Skip to content

Commit e91c9cb

Browse files
committed
test: fix flaky RSA key comparison in TestGetPrivateKeyPEM
Signed-off-by: Abhinav Singh <abhinavsingh717073@gmail.com>
1 parent 114820a commit e91c9cb

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

pkg/router/jwt_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,16 @@ func TestGetPrivateKeyPEM(t *testing.T) {
183183
privateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
184184
assert.NoError(t, err)
185185
assert.NotNil(t, privateKey)
186-
assert.Equal(t, manager.privateKey, privateKey)
186+
// Compare keys mathematically instead of by object equality
187+
assert.Equal(t, manager.privateKey.PublicKey.N, privateKey.PublicKey.N, "Public key N should match")
188+
assert.Equal(t, manager.privateKey.PublicKey.E, privateKey.PublicKey.E, "Public key E should match")
189+
assert.Equal(t, 0, manager.privateKey.D.Cmp(privateKey.D), "Private exponent D should match")
190+
191+
// Compare primes
192+
assert.Equal(t, len(manager.privateKey.Primes), len(privateKey.Primes), "Number of primes should match")
193+
for i := range manager.privateKey.Primes {
194+
assert.Equal(t, 0, manager.privateKey.Primes[i].Cmp(privateKey.Primes[i]), "Prime %d should match", i)
195+
}
187196
}
188197

189198
func TestLoadPrivateKeyPEM(t *testing.T) {

0 commit comments

Comments
 (0)