Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/integration/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use openstack_keystone_core_types::identity::*;
use crate::common::*;
use crate::impl_deleter;

mod group;
mod service_account;
mod user;
mod user_group;
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/src/identity/group.rs
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;
52 changes: 52 additions & 0 deletions tests/integration/src/identity/group/create.rs
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;

Copy link
Copy Markdown
Collaborator

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 --tests to see warnings. Focus only in the files you add

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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(())
}
57 changes: 57 additions & 0 deletions tests/integration/src/identity/group/delete.rs
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(())
}
54 changes: 54 additions & 0 deletions tests/integration/src/identity/group/get.rs
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(())
}
78 changes: 78 additions & 0 deletions tests/integration/src/identity/group/list.rs
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(())
}
3 changes: 3 additions & 0 deletions tests/integration/src/identity/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
pub(crate) mod helpers;

mod create;
mod delete;
mod federated;
mod get;
mod get_domain_id;
mod list;
mod update;
58 changes: 58 additions & 0 deletions tests/integration/src/identity/user/delete.rs
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(())
}
Loading
Loading