-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from LRZ-BADW/flavor-group-modify-tests
Flavor Group Modify Tests
- Loading branch information
Showing
8 changed files
with
210 additions
and
42 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
.sqlx/query-36a8b0c1f2a7c2a6a9a49f1ce65fc48bb67eba6087d1506de4ec8a967e8f4d1d.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
.sqlx/query-5c957d441d9c8e1a835f3e9dcbb6a69a11cba3c7e0adf1eba18165c85b6bd863.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod delete; | ||
mod modify; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
use lrzcc::{Api, Token}; | ||
use lrzcc_test::{random_alphanumeric_string, spawn_app}; | ||
use std::str::FromStr; | ||
use tokio::task::spawn_blocking; | ||
|
||
#[tokio::test] | ||
async fn e2e_lib_flavor_group_modify_denies_access_to_normal_user() { | ||
// arrange | ||
let server = spawn_app().await; | ||
let test_project = server | ||
.setup_test_project(0, 0, 1) | ||
.await | ||
.expect("Failed to setup test project"); | ||
let user = test_project.normals[0].user.clone(); | ||
let token = test_project.normals[0].token.clone(); | ||
let project = test_project.project.clone(); | ||
server | ||
.mock_keystone_auth(&token, &user.openstack_id, &user.name) | ||
.mount(&server.keystone_server) | ||
.await; | ||
let flavor_group = server | ||
.setup_test_flavor_group(project.id) | ||
.await | ||
.expect("Failed to setup test server state"); | ||
|
||
spawn_blocking(move || { | ||
// arrange | ||
let client = Api::new( | ||
format!("{}/api", &server.address), | ||
Token::from_str(&token).unwrap(), | ||
None, | ||
None, | ||
) | ||
.unwrap(); | ||
|
||
// act | ||
let modify = client.flavor_group.modify(flavor_group.id).send(); | ||
|
||
// assert | ||
assert!(modify.is_err()); | ||
assert_eq!( | ||
modify.unwrap_err().to_string(), | ||
format!("Admin privileges required") | ||
); | ||
}) | ||
.await | ||
.unwrap(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn e2e_lib_flavor_group_modify_denies_access_to_master_user() { | ||
// arrange | ||
let server = spawn_app().await; | ||
let test_project = server | ||
.setup_test_project(0, 1, 0) | ||
.await | ||
.expect("Failed to setup test project"); | ||
let user = test_project.masters[0].user.clone(); | ||
let token = test_project.masters[0].token.clone(); | ||
let project = test_project.project.clone(); | ||
server | ||
.mock_keystone_auth(&token, &user.openstack_id, &user.name) | ||
.mount(&server.keystone_server) | ||
.await; | ||
let flavor_group = server | ||
.setup_test_flavor_group(project.id) | ||
.await | ||
.expect("Failed to setup test server state"); | ||
|
||
spawn_blocking(move || { | ||
// arrange | ||
let client = Api::new( | ||
format!("{}/api", &server.address), | ||
Token::from_str(&token).unwrap(), | ||
None, | ||
None, | ||
) | ||
.unwrap(); | ||
|
||
// act | ||
let modify = client.flavor_group.modify(flavor_group.id).send(); | ||
|
||
// assert | ||
assert!(modify.is_err()); | ||
assert_eq!( | ||
modify.unwrap_err().to_string(), | ||
format!("Admin privileges required") | ||
); | ||
}) | ||
.await | ||
.unwrap(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn e2e_lib_flavor_group_modify_and_get_works() { | ||
// arrange | ||
let server = spawn_app().await; | ||
let (user, project, token) = server | ||
.setup_test_user_and_project(true) | ||
.await | ||
.expect("Failed to setup test user and project."); | ||
server | ||
.mock_keystone_auth(&token, &user.openstack_id, &user.name) | ||
.mount(&server.keystone_server) | ||
.await; | ||
let flavor_group = server | ||
.setup_test_flavor_group(project.id) | ||
.await | ||
.expect("Failed to setup test server state"); | ||
|
||
spawn_blocking(move || { | ||
// arrange | ||
let client = Api::new( | ||
format!("{}/api", &server.address), | ||
Token::from_str(&token).unwrap(), | ||
None, | ||
None, | ||
) | ||
.unwrap(); | ||
|
||
// act and assert 1 - modify | ||
let name = random_alphanumeric_string(10); | ||
let modified = client | ||
.flavor_group | ||
.modify(flavor_group.id) | ||
.name(name.clone()) | ||
// TODO: test changing the project | ||
.send() | ||
.unwrap(); | ||
assert_eq!(&name, &modified.name); | ||
|
||
// act and assert 2 - get | ||
let retrieved = client.flavor_group.get(modified.id).unwrap(); | ||
assert_eq!(modified.id, retrieved.id); | ||
assert_eq!(modified.name, retrieved.name); | ||
assert_eq!(modified.project, retrieved.project.id); | ||
assert_eq!( | ||
modified.flavors, | ||
retrieved | ||
.flavors | ||
.into_iter() | ||
.map(|f| f.id) | ||
.collect::<Vec<u32>>() | ||
); | ||
}) | ||
.await | ||
.unwrap(); | ||
} |