Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for CryptoKey #88988

Closed

Conversation

atlas-wheatear
Copy link

Further to #43440, this Pull Request adds three unit tests for CryptoKey.

CryptoKey Load and save a .key file.

These concern a CryptoKey instance that has loaded in the attached private key, namely tests/data/crypto/in.key:

  • load() a private key implies not is_public_only()
  • default save() leads to identical file contents as tests/data/crypto/in.key, since they are the same private key
  • save() with public_only set to true leads to identical contents as the separately prepared public key, namely tests/data/crypto/in.pub

@atlas-wheatear atlas-wheatear requested review from a team as code owners February 28, 2024 22:27
@atlas-wheatear
Copy link
Author

My apologies, there was a careless error in 78193af , involving a file being compared to itself.

@Calinou Calinou added this to the 4.x milestone Feb 28, 2024
@wheatear-dev
Copy link
Contributor

wheatear-dev commented Feb 29, 2024

Sorry - I have managed to lock myself out of the original account 😓

This is it's successor, on the same email address as before.

If that's too complex, please close this PR, and I will gladly open another in the new account's name.

EDIT - this will likely be necessary, I can't push to this branch anymore.

@Faless
Copy link
Collaborator

Faless commented Feb 29, 2024

Since CryptoKey is implemented by the mbedTLS module (core come with the interface, but no implementation), we might want to move the tests there, since they would all fail when module_mbedtls_enabled=no

crypto_key->save(priv_out_path);
const String priv_path = TestUtils::get_data_path("crypto/in.key");
Ref<FileAccess> f_priv_out = FileAccess::open(priv_out_path, FileAccess::READ);
REQUIRE(!f_priv_out.is_null());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
REQUIRE(!f_priv_out.is_null());
REQUIRE(f_priv_out.is_valid());

crypto_key->save(pub_out_path, true);
const String pub_path = TestUtils::get_data_path("crypto/in.pub");
Ref<FileAccess> f_pub_out = FileAccess::open(pub_out_path, FileAccess::READ);
REQUIRE(!f_pub_out.is_null());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
REQUIRE(!f_pub_out.is_null());
REQUIRE(f_pub_out.is_valid());

REQUIRE(!f_pub_out.is_null());
String s_pub_out = f_pub_out->get_as_utf8_string();
Ref<FileAccess> f_pub_in = FileAccess::open(pub_path, FileAccess::READ);
String s_pub_in = f_pub_in->get_as_utf8_string();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
String s_pub_in = f_pub_in->get_as_utf8_string();
REQUIRE(f_pub_in.is_valid());
String s_pub_in = f_pub_in->get_as_utf8_string();

REQUIRE(!f_priv_out.is_null());
String s_priv_out = f_priv_out->get_as_utf8_string();
Ref<FileAccess> f_priv_in = FileAccess::open(priv_path, FileAccess::READ);
String s_priv_in = f_priv_in->get_as_utf8_string();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
String s_priv_in = f_priv_in->get_as_utf8_string();
REQUIRE(f_priv_in.is_valid());
String s_priv_in = f_priv_in->get_as_utf8_string();

@wheatear-dev
Copy link
Contributor

@Calinou please could you close this PR?

I can't do it myself, because it was created by my irrecoverable account, nor can I implement the suggestions.

I will open a duplicated one at the weekend, in this new accounts name, and link it to this one.

@AThousandShips @Faless - sorry, you both gave really helpful comments - they won't be in vain!

@akien-mga akien-mga closed this Feb 29, 2024
@AThousandShips AThousandShips removed this from the 4.x milestone Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants