Skip to content

Commit b0af408

Browse files
author
Joe Ellis
committed
Add test for ListKeys
Signed-off-by: Joe Ellis <[email protected]>
1 parent 002aa05 commit b0af408

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/core/testing/core_tests.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::error::{ClientErrorKind, Error};
66
use crate::BasicClient;
77
use mockstream::{FailingMockStream, MockStream};
88
use parsec_interface::operations;
9+
use parsec_interface::operations::list_keys::KeyInfo;
910
use parsec_interface::operations::list_providers::{ProviderInfo, Uuid};
1011
use parsec_interface::operations::psa_algorithm::*;
1112
use parsec_interface::operations::psa_key_attributes::*;
@@ -118,6 +119,57 @@ fn list_opcodes_test() {
118119
assert!(opcodes.contains(&Opcode::PsaGenerateKey) && opcodes.contains(&Opcode::PsaDestroyKey));
119120
}
120121

122+
#[test]
123+
fn list_keys_test() {
124+
use parsec_interface::operations::psa_key_attributes::{
125+
Attributes, Lifetime, Policy, Type, UsageFlags,
126+
};
127+
128+
let mut client: TestBasicClient = Default::default();
129+
let mut key_info = Vec::new();
130+
key_info.push(KeyInfo {
131+
provider_id: ProviderID::MbedCrypto,
132+
name: String::from("Foo"),
133+
attributes: Attributes {
134+
lifetime: Lifetime::Persistent,
135+
key_type: Type::RsaKeyPair,
136+
bits: 1024,
137+
policy: Policy {
138+
usage_flags: UsageFlags {
139+
export: true,
140+
copy: true,
141+
cache: true,
142+
encrypt: true,
143+
decrypt: true,
144+
sign_message: true,
145+
verify_message: true,
146+
sign_hash: true,
147+
verify_hash: true,
148+
derive: true,
149+
},
150+
permitted_algorithms: Algorithm::AsymmetricSignature(
151+
AsymmetricSignature::RsaPkcs1v15Sign {
152+
hash_alg: Hash::Sha256.into(),
153+
},
154+
),
155+
},
156+
},
157+
});
158+
159+
client.set_mock_read(&get_response_bytes_from_result(NativeResult::ListKeys(
160+
operations::list_keys::Result { keys: key_info },
161+
)));
162+
163+
let keys = client.list_keys().expect("Failed to list keys");
164+
// Check request:
165+
// ListKeys request is empty so no checking to be done
166+
167+
// Check response:
168+
assert_eq!(keys.len(), 1);
169+
assert_eq!(keys[0].name, "Foo");
170+
assert_eq!(keys[0].provider_id, ProviderID::MbedCrypto);
171+
}
172+
121173
#[test]
122174
fn no_crypto_provider_test() {
123175
let client = BasicClient::new(AuthenticationData::AppIdentity(Secret::new(String::from(

0 commit comments

Comments
 (0)