Skip to content

Commit

Permalink
Add a unit test to ensure KeyID compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
justinas committed Apr 30, 2024
1 parent 91000ea commit c44c7c2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/jwt/jwk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"crypto/rsa"
"crypto/sha256"
"encoding/base64"
"math/big"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -69,3 +70,16 @@ func TestKeyIDHasDistinctOutputForDifferingInputs(t *testing.T) {
require.NotEmpty(t, id2)
require.NotEqual(t, id1, id2)
}

// TestKeyIDCompatibility ensures we do not introduce a change in the KeyID algorithm for existing keys.
// It does so by ensuring that a pre-generated public key results in the expected value.
func TestKeyIDCompatibility(t *testing.T) {
n, ok := new(big.Int).
SetString("10804584566601725083798733714540307814537881454603593919227265169397611763416631197061041949793088023127406259586903197568870611092333639226643589004457719", 10)
require.True(t, ok, "failed to create a bigint")
publicKey := &rsa.PublicKey{
E: 65537,
N: n,
}
require.Equal(t, "GDLHLDvPUYmNLVU3WgshDX7bAw8xEmML8ypeE9KRAEQ", KeyID(publicKey))
}

0 comments on commit c44c7c2

Please sign in to comment.