1
1
// Copyright 2020 Contributors to the Parsec project.
2
2
// SPDX-License-Identifier: Apache-2.0
3
+ use super :: { TestCoreClient , DEFAULT_APP_NAME } ;
3
4
use crate :: error:: { ClientErrorKind , Error } ;
4
- use crate :: { auth:: AuthenticationData , CoreClient } ;
5
5
use mockstream:: MockStream ;
6
6
use parsec_interface:: operations;
7
7
use parsec_interface:: operations:: list_providers:: ProviderInfo ;
@@ -27,7 +27,6 @@ const REQ_HEADER: RequestHeader = RequestHeader {
27
27
auth_type : AuthType :: NoAuth ,
28
28
opcode : Opcode :: Ping ,
29
29
} ;
30
- const APP_NAME : & str = "test-app" ;
31
30
32
31
fn get_response_bytes_from_result ( result : NativeResult ) -> Vec < u8 > {
33
32
let mut stream = MockStream :: new ( ) ;
@@ -52,13 +51,9 @@ fn get_operation_from_req_bytes(bytes: Vec<u8>) -> NativeOperation {
52
51
. unwrap ( )
53
52
}
54
53
55
- fn get_client ( ) -> CoreClient {
56
- CoreClient :: new ( AuthenticationData :: AppIdentity ( String :: from ( APP_NAME ) ) )
57
- }
58
-
59
54
#[ test]
60
55
fn ping_test ( ) {
61
- let mut client = get_client ( ) ;
56
+ let mut client: TestCoreClient = Default :: default ( ) ;
62
57
client. set_mock_read ( & get_response_bytes_from_result ( NativeResult :: Ping (
63
58
operations:: ping:: Result {
64
59
wire_protocol_version_maj : 1 ,
@@ -74,7 +69,7 @@ fn ping_test() {
74
69
75
70
#[ test]
76
71
fn list_provider_test ( ) {
77
- let mut client = get_client ( ) ;
72
+ let mut client: TestCoreClient = Default :: default ( ) ;
78
73
let mut provider_info = Vec :: new ( ) ;
79
74
provider_info. push ( ProviderInfo {
80
75
uuid : uuid:: Uuid :: nil ( ) ,
@@ -101,7 +96,7 @@ fn list_provider_test() {
101
96
102
97
#[ test]
103
98
fn list_provider_operations_test ( ) {
104
- let mut client = get_client ( ) ;
99
+ let mut client: TestCoreClient = Default :: default ( ) ;
105
100
let mut opcodes = HashSet :: new ( ) ;
106
101
let _ = opcodes. insert ( Opcode :: PsaDestroyKey ) ;
107
102
let _ = opcodes. insert ( Opcode :: PsaGenerateKey ) ;
@@ -121,7 +116,7 @@ fn list_provider_operations_test() {
121
116
122
117
#[ test]
123
118
fn generate_key_test ( ) {
124
- let mut client = get_client ( ) ;
119
+ let mut client: TestCoreClient = Default :: default ( ) ;
125
120
client. set_mock_read ( & get_response_bytes_from_result (
126
121
NativeResult :: PsaGenerateKey ( operations:: psa_generate_key:: Result { } ) ,
127
122
) ) ;
@@ -165,7 +160,7 @@ fn generate_key_test() {
165
160
166
161
#[ test]
167
162
fn destroy_key_test ( ) {
168
- let mut client = get_client ( ) ;
163
+ let mut client: TestCoreClient = Default :: default ( ) ;
169
164
client. set_mock_read ( & get_response_bytes_from_result (
170
165
NativeResult :: PsaDestroyKey ( operations:: psa_destroy_key:: Result { } ) ,
171
166
) ) ;
@@ -188,7 +183,7 @@ fn destroy_key_test() {
188
183
189
184
#[ test]
190
185
fn import_key_test ( ) {
191
- let mut client = get_client ( ) ;
186
+ let mut client: TestCoreClient = Default :: default ( ) ;
192
187
client. set_mock_read ( & get_response_bytes_from_result ( NativeResult :: PsaImportKey (
193
188
operations:: psa_import_key:: Result { } ,
194
189
) ) ) ;
@@ -238,7 +233,7 @@ fn import_key_test() {
238
233
239
234
#[ test]
240
235
fn export_public_key_test ( ) {
241
- let mut client = get_client ( ) ;
236
+ let mut client: TestCoreClient = Default :: default ( ) ;
242
237
let key_data = vec ! [ 0xa5 ; 128 ] ;
243
238
client. set_mock_read ( & get_response_bytes_from_result (
244
239
NativeResult :: PsaExportPublicKey ( operations:: psa_export_public_key:: Result {
@@ -266,7 +261,7 @@ fn export_public_key_test() {
266
261
267
262
#[ test]
268
263
fn sign_hash_test ( ) {
269
- let mut client = get_client ( ) ;
264
+ let mut client: TestCoreClient = Default :: default ( ) ;
270
265
let hash = vec ! [ 0x77_u8 ; 32 ] ;
271
266
let key_name = String :: from ( "key_name" ) ;
272
267
let sign_algorithm = AsymmetricSignature :: Ecdsa {
@@ -305,7 +300,7 @@ fn sign_hash_test() {
305
300
306
301
#[ test]
307
302
fn verify_hash_test ( ) {
308
- let mut client = get_client ( ) ;
303
+ let mut client: TestCoreClient = Default :: default ( ) ;
309
304
let hash = vec ! [ 0x77_u8 ; 32 ] ;
310
305
let key_name = String :: from ( "key_name" ) ;
311
306
let sign_algorithm = AsymmetricSignature :: Ecdsa {
@@ -343,7 +338,7 @@ fn verify_hash_test() {
343
338
344
339
#[ test]
345
340
fn different_response_type_test ( ) {
346
- let mut client = get_client ( ) ;
341
+ let mut client: TestCoreClient = Default :: default ( ) ;
347
342
client. set_mock_read ( & get_response_bytes_from_result (
348
343
NativeResult :: PsaVerifyHash ( operations:: psa_verify_hash:: Result { } ) ,
349
344
) ) ;
@@ -360,7 +355,7 @@ fn different_response_type_test() {
360
355
361
356
#[ test]
362
357
fn response_status_test ( ) {
363
- let mut client = get_client ( ) ;
358
+ let mut client: TestCoreClient = Default :: default ( ) ;
364
359
let mut stream = MockStream :: new ( ) ;
365
360
let status = ResponseStatus :: PsaErrorDataCorrupt ;
366
361
let mut resp = Response :: from_request_header ( REQ_HEADER , ResponseStatus :: Success ) ;
@@ -374,7 +369,7 @@ fn response_status_test() {
374
369
375
370
#[ test]
376
371
fn malformed_response_test ( ) {
377
- let mut client = get_client ( ) ;
372
+ let mut client: TestCoreClient = Default :: default ( ) ;
378
373
client. set_mock_read ( & [ 0xcb_u8 ; 130 ] ) ;
379
374
let err = client. ping ( ) . expect_err ( "Error was expected" ) ;
380
375
@@ -386,7 +381,7 @@ fn malformed_response_test() {
386
381
387
382
#[ test]
388
383
fn request_fields_test ( ) {
389
- let mut client = get_client ( ) ;
384
+ let mut client: TestCoreClient = Default :: default ( ) ;
390
385
client. set_mock_read ( & get_response_bytes_from_result ( NativeResult :: Ping (
391
386
operations:: ping:: Result {
392
387
wire_protocol_version_maj : 1 ,
@@ -401,7 +396,7 @@ fn request_fields_test() {
401
396
402
397
#[ test]
403
398
fn auth_value_test ( ) {
404
- let mut client = get_client ( ) ;
399
+ let mut client: TestCoreClient = Default :: default ( ) ;
405
400
client. set_mock_read ( & get_response_bytes_from_result (
406
401
NativeResult :: PsaDestroyKey ( operations:: psa_destroy_key:: Result { } ) ,
407
402
) ) ;
@@ -413,6 +408,6 @@ fn auth_value_test() {
413
408
let req = get_req_from_bytes ( client. get_mock_write ( ) ) ;
414
409
assert_eq ! (
415
410
String :: from_utf8( req. auth. bytes( ) . to_owned( ) ) . unwrap( ) ,
416
- String :: from( APP_NAME )
411
+ String :: from( DEFAULT_APP_NAME )
417
412
) ;
418
413
}
0 commit comments