Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

PKCS #11 Unit Tests #1992

Merged
merged 3 commits into from
May 12, 2020
Merged

PKCS #11 Unit Tests #1992

merged 3 commits into from
May 12, 2020

Conversation

lundinc2
Copy link
Contributor

@lundinc2 lundinc2 commented May 11, 2020

Description

  • Now at 85% line coverage
  • 100% function coverage
  • Added unit tests for:
    • C_GetAttributeValue
    • PKCS11_PAL_DESTROY_OBJECT
    • C_Verify
    • C_GenerateKeyPair
    • C_GenerateRandom

Checklist:

  • I have tested my changes. No regression in existing tests.
  • My code is Linted.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

* Now at 85% line coverage
* 100% function coverage
* Added unit tests for:
	* C_GetAttributeValue
	* PKCS11_PAL_DESTROY_OBJECT
	* C_Verify
	* C_GenerateKeyPair
	* C_GenerateRandom
@lundinc2 lundinc2 requested a review from alfred2g May 11, 2020 15:46
Comment on lines 316 to 326
pvPortMalloc_Stub( pvPkcs11MallocCb );
PKCS11_PAL_FindObject_IgnoreAndReturn( 2 );
PKCS11_PAL_GetObjectValue_IgnoreAndReturn( CKR_OK );
mbedtls_pk_parse_key_IgnoreAndReturn( 0 );
PKCS11_PAL_GetObjectValueCleanup_CMockIgnore();
pvPortMalloc_Stub( pvPkcs11MallocCb );
mbedtls_ecp_keypair_init_CMockIgnore();
mbedtls_ecp_group_init_CMockIgnore();
mbedtls_ecp_group_load_IgnoreAndReturn( 0 );
mbedtls_mpi_read_binary_IgnoreAndReturn( 0 );
pvPortMalloc_Stub( pvPkcs11MallocCb );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the stubs are the same
pvPortMalloc_Stub( pvPkcs11MallocCb );

mbedtls_ecp_keypair_init_CMockIgnore();
mbedtls_ecp_group_init_CMockIgnore();
mbedtls_ecp_group_load_IgnoreAndReturn( 0 );
mbedtls_mpi_read_binary_IgnoreAndReturn( 0 );
pvPortMalloc_Stub( pvPkcs11MallocCb );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too,
stubs can only be set at the beginning of the function , no need to redefine them before every function call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should stay the same as I have different behavior in the malloc stub before this one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pvPortMalloc_IgnoreAndReturn( &xKeyContext ); Above this one injects a struct

TEST_ASSERT_EQUAL( CKR_OK, xResult );

xResult = prvOpenSession( &xSession );
TEST_ASSERT_EQUAL( CKR_OK, xResult );

mbedtls_pk_init_CMockIgnore();
pvPortMalloc_Stub( pvPkcs11MallocCb );
PKCS11_PAL_FindObject_IgnoreAndReturn( 1 );
PKCS11_PAL_GetObjectValue_IgnoreAndReturn( CKR_OK );
PKCS11_PAL_FindObject_IgnoreAndReturn( CK_INVALID_HANDLE );
mbedtls_pk_parse_public_key_IgnoreAndReturn( 0 );
PKCS11_PAL_GetObjectValueCleanup_CMockIgnore();
pvPortMalloc_Stub( pvPkcs11MallocCb );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor

@alfred2g alfred2g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just the multiple stubs within the same function

@lundinc2
Copy link
Contributor Author

/bot run checks

1 similar comment
@lundinc2
Copy link
Contributor Author

/bot run checks

@lundinc2 lundinc2 merged commit c530795 into aws:master May 12, 2020
alfred2g pushed a commit to alfred2g/amazon-freertos that referenced this pull request May 21, 2020
* PKCS aws#11 Unit Tests

* Now at 85% line coverage
* 100% function coverage
* Added unit tests for:
	* C_GetAttributeValue
	* PKCS11_PAL_DESTROY_OBJECT
	* C_Verify
	* C_GenerateKeyPair
	* C_GenerateRandom
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants