Skip to content
Merged
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
4 changes: 4 additions & 0 deletions tests/integration/src/identity/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
//
// SPDX-License-Identifier: Apache-2.0

mod create;
mod delete;
mod get;
mod list;
mod update;
34 changes: 34 additions & 0 deletions tests/integration/src/identity/group/create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 crate::common::get_state;
use crate::{create_domain, create_group};

#[tokio::test]
#[traced_test]
async fn test_create() -> Result<()> {
let (state, _tmp) = get_state().await?;
let domain = create_domain!(state)?;

let group = create_group!(state, domain.id.clone())?;

assert!(!group.id.is_empty(), "an id was generated");
assert!(!group.name.is_empty());
assert_eq!(group.domain_id, domain.id);
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 openstack_keystone_core::auth::ExecutionContext;

use crate::common::get_state;
use crate::{create_domain, create_group};

#[tokio::test]
#[traced_test]
async fn test_delete() -> Result<()> {
let (state, _tmp) = get_state().await?;
let domain = create_domain!(state)?;
let group = create_group!(state, domain.id.clone())?;

state
.provider
.get_identity_provider()
.delete_group(&ExecutionContext::internal(&state), &group.id)
.await?;

let fetched = state
.provider
.get_identity_provider()
.get_group(&ExecutionContext::internal(&state), &group.id)
.await?;
assert!(fetched.is_none(), "group is gone after delete");
Ok(())
}

#[tokio::test]
#[traced_test]
async fn test_delete_not_found() -> Result<()> {
let (state, _tmp) = get_state().await?;
let result = state
.provider
.get_identity_provider()
.delete_group(&ExecutionContext::internal(&state), "does-not-exist")
.await;
assert!(result.is_err(), "deleting a missing group errors");
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_core::auth::ExecutionContext;

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(&ExecutionContext::internal(&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(&ExecutionContext::internal(&state), "missing")
.await?;
assert!(result.is_none(), "a missing group returns None");
Ok(())
}
81 changes: 81 additions & 0 deletions tests/integration/src/identity/group/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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_core::auth::ExecutionContext;
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(
&ExecutionContext::internal(&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(
&ExecutionContext::internal(&state),
&GroupListParameters {
domain_id: Some(domain.id.clone()),
..Default::default()
},
)
.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;
35 changes: 30 additions & 5 deletions tests/integration/src/identity/user/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async fn test_create_with_password_and_expiry_days() -> eyre::Result<()> {
let (state, _tmp) = get_state().await?;
let domain = create_domain!(state)?;
let uid = Uuid::new_v4().simple().to_string();
setup_test_config(&state, Some(90), None).await;
setup_test_config(&ExecutionContext::internal(&state), Some(90), None).await;

let prov = state.provider.get_identity_provider();
let user = prov
Expand Down Expand Up @@ -169,7 +169,7 @@ async fn test_create_with_password_and_unique_count() -> Result<()> {
let (state, _tmp) = get_state().await?;
let domain = create_domain!(state)?;
let uid = Uuid::new_v4().simple().to_string();
setup_test_config(&state, None, Some(5)).await;
setup_test_config(&ExecutionContext::internal(&state), None, Some(5)).await;

let prov = state.provider.get_identity_provider();
prov.create_user(
Expand Down Expand Up @@ -285,7 +285,7 @@ async fn test_create_with_password_and_get_user() -> Result<()> {
let (state, _tmp) = get_state().await?;
let domain = create_domain!(state)?;
let uid = Uuid::new_v4().simple().to_string();
setup_test_config(&state, Some(30), None).await;
setup_test_config(&ExecutionContext::internal(&state), Some(30), None).await;

let prov = state.provider.get_identity_provider();
prov.create_user(
Expand Down Expand Up @@ -320,7 +320,7 @@ async fn test_create_with_expiry_and_authenticate() -> Result<()> {
let (state, _tmp) = get_state().await?;
let domain = create_domain!(state)?;
let uid = Uuid::new_v4().simple().to_string();
setup_test_config(&state, Some(90), None).await;
setup_test_config(&ExecutionContext::internal(&state), Some(90), None).await;

let prov = state.provider.get_identity_provider();
prov.create_user(
Expand Down Expand Up @@ -366,7 +366,7 @@ async fn test_create_with_expiry_and_unique_count() -> Result<()> {
let (state, _tmp) = get_state().await?;
let domain = create_domain!(state)?;
let uid = Uuid::new_v4().simple().to_string();
setup_test_config(&state, Some(90), Some(1)).await;
setup_test_config(&ExecutionContext::internal(&state), Some(90), Some(1)).await;

let prov = state.provider.get_identity_provider();
let user = prov
Expand Down Expand Up @@ -404,3 +404,28 @@ async fn test_create_with_expiry_and_unique_count() -> Result<()> {

Ok(())
}

#[tokio::test]
#[traced_test]
async fn test_create_invalid_name_too_long() -> Result<()> {
let (state, _tmp) = get_state().await?;
let domain = create_domain!(state)?;

let result = state
.provider
.get_identity_provider()
.create_user(
&ExecutionContext::internal(&state),
UserCreateBuilder::default()
.name("x".repeat(256))
.domain_id(domain.id.clone())
.enabled(true)
.build()?,
)
.await;
assert!(
result.is_err(),
"creating a user with an over-length name is rejected"
);
Ok(())
}
57 changes: 57 additions & 0 deletions tests/integration/src/identity/user/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 user functionality.

use eyre::Result;
use tracing_test::traced_test;

use openstack_keystone_core::auth::ExecutionContext;

use crate::common::get_state;
use crate::{create_domain, create_user};

#[tokio::test]
#[traced_test]
async fn test_delete() -> Result<()> {
let (state, _tmp) = get_state().await?;
let domain = create_domain!(state)?;
let user = create_user!(state, domain.id.clone())?;

state
.provider
.get_identity_provider()
.delete_user(&ExecutionContext::internal(&state), &user.id)
.await?;

let fetched = state
.provider
.get_identity_provider()
.get_user(&ExecutionContext::internal(&state), &user.id)
.await?;
assert!(fetched.is_none(), "user is gone after delete");
Ok(())
}

#[tokio::test]
#[traced_test]
async fn test_delete_not_found() -> Result<()> {
let (state, _tmp) = get_state().await?;
let result = state
.provider
.get_identity_provider()
.delete_user(&ExecutionContext::internal(&state), "does-not-exist")
.await;
assert!(result.is_err(), "deleting a missing user errors");
Ok(())
}
Loading
Loading