-
Notifications
You must be signed in to change notification settings - Fork 7
test: Add identity provider integration tests #831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| mod create; | ||
| mod delete; | ||
| mod get; | ||
| mod list; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| //! Test create group functionality. | ||
|
|
||
| use eyre::Result; | ||
| use tracing_test::traced_test; | ||
| use uuid::Uuid; | ||
|
|
||
| use openstack_keystone::identity::IdentityApi; | ||
| use openstack_keystone_core_types::identity::GroupCreate; | ||
|
|
||
| use crate::common::get_state; | ||
| use crate::create_domain; | ||
|
|
||
| #[tokio::test] | ||
| #[traced_test] | ||
| async fn test_create() -> Result<()> { | ||
| let (state, _tmp) = get_state().await?; | ||
| let domain = create_domain!(state)?; | ||
| let name = Uuid::new_v4().to_string(); | ||
|
|
||
| let group = state | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's please use "create_user!", "create_group!" like the tests/integration/src/identity/user_group/add.rs - we should be using this pattern more since it includes automatic cleanup of the resources created by the test what helps to fix test reliability. It is actually already present in some of the added tests. |
||
| .provider | ||
| .get_identity_provider() | ||
| .create_group( | ||
| &state, | ||
| GroupCreate { | ||
| name: name.clone(), | ||
| domain_id: domain.id.clone(), | ||
| description: Some("a group".into()), | ||
| ..Default::default() | ||
| }, | ||
| ) | ||
| .await?; | ||
|
|
||
| assert!(!group.id.is_empty(), "an id was generated"); | ||
| assert_eq!(group.name, name); | ||
| assert_eq!(group.domain_id, domain.id); | ||
| assert_eq!(group.description.as_deref(), Some("a group")); | ||
| Ok(()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| //! Test delete group functionality. | ||
|
|
||
| use eyre::Result; | ||
| use tracing_test::traced_test; | ||
| use uuid::Uuid; | ||
|
|
||
| use openstack_keystone::identity::IdentityApi; | ||
| use openstack_keystone_core_types::identity::GroupCreate; | ||
|
|
||
| use crate::common::get_state; | ||
| use crate::create_domain; | ||
|
|
||
| #[tokio::test] | ||
| #[traced_test] | ||
| async fn test_delete() -> Result<()> { | ||
| let (state, _tmp) = get_state().await?; | ||
| let domain = create_domain!(state)?; | ||
| let group = state | ||
| .provider | ||
| .get_identity_provider() | ||
| .create_group( | ||
| &state, | ||
| GroupCreate { | ||
| name: Uuid::new_v4().to_string(), | ||
| domain_id: domain.id.clone(), | ||
| ..Default::default() | ||
| }, | ||
| ) | ||
| .await?; | ||
|
|
||
| state | ||
| .provider | ||
| .get_identity_provider() | ||
| .delete_group(&state, &group.id) | ||
| .await?; | ||
|
|
||
| let fetched = state | ||
| .provider | ||
| .get_identity_provider() | ||
| .get_group(&state, &group.id) | ||
| .await?; | ||
| assert!(fetched.is_none(), "group is gone after delete"); | ||
| Ok(()) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| //! Test get group functionality. | ||
|
|
||
| use eyre::Result; | ||
| use tracing_test::traced_test; | ||
|
|
||
| use openstack_keystone::identity::IdentityApi; | ||
|
|
||
| use crate::common::get_state; | ||
| use crate::{create_domain, create_group}; | ||
|
|
||
| #[tokio::test] | ||
| #[traced_test] | ||
| async fn test_get() -> Result<()> { | ||
| let (state, _tmp) = get_state().await?; | ||
| let domain = create_domain!(state)?; | ||
| let group = create_group!(state, domain.id.clone())?; | ||
|
|
||
| let fetched = state | ||
| .provider | ||
| .get_identity_provider() | ||
| .get_group(&state, &group.id) | ||
| .await? | ||
| .expect("group found"); | ||
| assert_eq!(fetched.id, group.id); | ||
| assert_eq!(fetched.name, group.name); | ||
| assert_eq!(fetched.domain_id, group.domain_id); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| #[traced_test] | ||
| async fn test_get_not_found() -> Result<()> { | ||
| let (state, _tmp) = get_state().await?; | ||
| let result = state | ||
| .provider | ||
| .get_identity_provider() | ||
| .get_group(&state, "missing") | ||
| .await?; | ||
| assert!(result.is_none(), "a missing group returns None"); | ||
| Ok(()) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| //! Test list groups functionality. | ||
|
|
||
| use eyre::Result; | ||
| use tracing_test::traced_test; | ||
|
|
||
| use openstack_keystone::identity::IdentityApi; | ||
| use openstack_keystone_core_types::identity::GroupListParameters; | ||
|
|
||
| use crate::common::get_state; | ||
| use crate::{create_domain, create_group}; | ||
|
|
||
| #[tokio::test] | ||
| #[traced_test] | ||
| async fn test_list() -> Result<()> { | ||
| let (state, _tmp) = get_state().await?; | ||
| let domain = create_domain!(state)?; | ||
| let group_a = create_group!(state, domain.id.clone())?; | ||
| let group_b = create_group!(state, domain.id.clone())?; | ||
|
|
||
| let groups = state | ||
| .provider | ||
| .get_identity_provider() | ||
| .list_groups(&state, &GroupListParameters::default()) | ||
| .await?; | ||
|
|
||
| assert!( | ||
| groups.iter().any(|g| g.id == group_a.id), | ||
| "first group is listed" | ||
| ); | ||
| assert!( | ||
| groups.iter().any(|g| g.id == group_b.id), | ||
| "second group is listed" | ||
| ); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| #[traced_test] | ||
| async fn test_list_by_domain() -> Result<()> { | ||
| let (state, _tmp) = get_state().await?; | ||
| let domain = create_domain!(state)?; | ||
| let group = create_group!(state, domain.id.clone())?; | ||
|
|
||
| let groups = state | ||
| .provider | ||
| .get_identity_provider() | ||
| .list_groups( | ||
| &state, | ||
| &GroupListParameters { | ||
| domain_id: Some(domain.id.clone()), | ||
| name: None, | ||
| }, | ||
| ) | ||
| .await?; | ||
|
|
||
| assert!( | ||
| groups.iter().any(|g| g.id == group.id), | ||
| "group is listed for its domain" | ||
| ); | ||
| assert!( | ||
| groups.iter().all(|g| g.domain_id == domain.id), | ||
| "only groups from the requested domain are returned" | ||
| ); | ||
| Ok(()) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| //! Test delete user functionality. | ||
|
|
||
| use eyre::Result; | ||
| use tracing_test::traced_test; | ||
| use uuid::Uuid; | ||
|
|
||
| use openstack_keystone::identity::IdentityApi; | ||
| use openstack_keystone_core_types::identity::UserCreateBuilder; | ||
|
|
||
| use crate::common::get_state; | ||
| use crate::create_domain; | ||
|
|
||
| #[tokio::test] | ||
| #[traced_test] | ||
| async fn test_delete() -> Result<()> { | ||
| let (state, _tmp) = get_state().await?; | ||
| let domain = create_domain!(state)?; | ||
|
|
||
| let user = state | ||
| .provider | ||
| .get_identity_provider() | ||
| .create_user( | ||
| &state, | ||
| UserCreateBuilder::default() | ||
| .name(Uuid::new_v4().to_string()) | ||
| .domain_id(domain.id.clone()) | ||
| .enabled(true) | ||
| .build()?, | ||
| ) | ||
| .await?; | ||
|
|
||
| state | ||
| .provider | ||
| .get_identity_provider() | ||
| .delete_user(&state, &user.id) | ||
| .await?; | ||
|
|
||
| let fetched = state | ||
| .provider | ||
| .get_identity_provider() | ||
| .get_user(&state, &user.id) | ||
| .await?; | ||
| assert!(fetched.is_none(), "user is gone after delete"); | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From now on this import is not necessary. Please remove it, but you actually should just run
cargo check -p test_integration --teststo see warnings. Focus only in the files you add