Skip to content

keystore_test: fix flaky RSA key comparison by replacing DeepEqual#3994

Merged
kubevirt-bot merged 1 commit into
kubevirt:mainfrom
Acedus:fix-key-comparison
Dec 25, 2025
Merged

keystore_test: fix flaky RSA key comparison by replacing DeepEqual#3994
kubevirt-bot merged 1 commit into
kubevirt:mainfrom
Acedus:fix-key-comparison

Conversation

@Acedus
Copy link
Copy Markdown
Contributor

@Acedus Acedus commented Dec 24, 2025

What this PR does / why we need it:
The previous UT relied on reflect.DeepEqual to compare rsa.PrivateKey structs which can be flaky since it compares internal memory state rather than cryptographic equality which is what the test should be doing. This PR replaces DeepEqual with the PrivateKey Equal method which checks whether a key and another key have an equivalent private exponent and primes.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:
Related failure: https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_containerized-data-importer/3993/pull-cdi-unit-test/2003749757226323968#1:build-log.txt%3A1413

Release note:

NONE

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Dec 24, 2025
@Acedus
Copy link
Copy Markdown
Contributor Author

Acedus commented Dec 24, 2025

/cc @akalenyu

@coveralls
Copy link
Copy Markdown

coveralls commented Dec 24, 2025

Coverage Status

coverage: 58.743% (+0.04%) from 58.699%
when pulling ae0bd20 on Acedus:fix-key-comparison
into 0d192d1 on kubevirt:main.

Copy link
Copy Markdown
Collaborator

@akalenyu akalenyu left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm
I think you're right

Comment thread pkg/keys/keystore_test.go Outdated
if !reflect.DeepEqual(privateKey, returnedPrivateKey) {
Fail("Keys do not match")
}
Expect(privateKey.Equal(returnedPrivateKey)).To(BeTrue())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: you could keep the error description string

Suggested change
Expect(privateKey.Equal(returnedPrivateKey)).To(BeTrue())
Expect(privateKey.Equal(returnedPrivateKey)).To(BeTrue(), "Keys do not match")

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 24, 2025
@kubevirt-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: akalenyu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 24, 2025
The previous UT relied on reflect.DeepEqual to compare rsa.PrivateKey
structs which can be flaky since it compares internal memory state
rather than cryptographic equality which is what the test should be
doing. This commit replaces DeepEqual with the PrivateKey Equal method
which checks whether a key and another key have an equivalent private
exponent and primes.

Signed-off-by: Adi Aloni <[email protected]>
@Acedus Acedus force-pushed the fix-key-comparison branch from 2881ba2 to ae0bd20 Compare December 24, 2025 11:40
@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 24, 2025
@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 24, 2025
@akalenyu
Copy link
Copy Markdown
Collaborator

/test pull-containerized-data-importer-e2e-nfs

1 similar comment
@akalenyu
Copy link
Copy Markdown
Collaborator

/test pull-containerized-data-importer-e2e-nfs

@Acedus
Copy link
Copy Markdown
Contributor Author

Acedus commented Dec 25, 2025

/test pull-containerized-data-importer-e2e-destructive

@kubevirt-bot kubevirt-bot merged commit 9c87318 into kubevirt:main Dec 25, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants