use cosmian_kms_cli_actions::reexport::cosmian_kmip::kmip_2_1::{
extra::{
VENDOR_ID_COSMIAN,
tagging::{SYSTEM_TAG_SYMMETRIC_KEY, VENDOR_ATTR_TAG},
},
kmip_operations::GetAttributes,
kmip_types::{AttributeReference, CryptographicAlgorithm, Tag, UniqueIdentifier},
requests::symmetric_key_create_request,
};
use test_kms_server::{TestClientOptions, start_test_server_with_patch, test_config_path};
use crate::error::result::CosmianResult;
const TEST_VENDOR_ID: &str = "test_vendor_id";
#[tokio::test]
pub(crate) async fn test_vendor_id_in_vendor_attributes() -> CosmianResult<()> {
let mut ctx = start_test_server_with_patch(
&test_config_path("auth_plain.toml"),
|config| {
config.vendor_identification = TEST_VENDOR_ID.to_owned();
},
TestClientOptions::default(),
)
.await?;
ctx.owner_client_config.vendor_id = TEST_VENDOR_ID.to_owned();
let client = ctx.get_owner_client();
let create_request = symmetric_key_create_request(
TEST_VENDOR_ID,
None,
256,
CryptographicAlgorithm::AES,
Vec::<String>::new(),
false,
None,
)?;
let create_response = client.create(create_request).await?;
let uid = create_response.unique_identifier.to_string();
let get_attrs_response = client
.get_attributes(GetAttributes {
unique_identifier: Some(UniqueIdentifier::TextString(uid)),
attribute_reference: Some(vec![AttributeReference::Standard(Tag::Tag)]),
})
.await?;
let attributes = &get_attrs_response.attributes;
let vendor_attrs = attributes
.vendor_attributes
.as_ref()
.expect("a newly created symmetric key must have VendorAttributes");
let has_test_vendor = vendor_attrs.iter().any(|va| {
va.vendor_identification == TEST_VENDOR_ID && va.attribute_name == VENDOR_ATTR_TAG
});
assert!(
has_test_vendor,
"Expected a VendorAttribute with vendor_identification={TEST_VENDOR_ID} \
and attribute_name={VENDOR_ATTR_TAG}; got: {vendor_attrs:?}"
);
let tags = attributes.get_tags(TEST_VENDOR_ID);
assert!(
tags.contains(SYSTEM_TAG_SYMMETRIC_KEY),
"System tag {SYSTEM_TAG_SYMMETRIC_KEY} must appear under vendor_id \
{TEST_VENDOR_ID}; got tags: {tags:?}"
);
let cosmian_tags = attributes.get_tags(VENDOR_ID_COSMIAN);
assert!(
cosmian_tags.is_empty(),
"Tags must NOT be stored under the default vendor ID {VENDOR_ID_COSMIAN} \
when the server uses {TEST_VENDOR_ID}; got: {cosmian_tags:?}"
);
ctx.stop_server().await?;
Ok(())
}