This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the pointer overwrite issue in oauthServer metadata (#183)
Signed-off-by: Prafulla Mahindrakar <prafulla.mahindrakar@gmail.com> Co-authored-by: Prafulla Mahindrakar <prafulla.mahindrakar@gmail.com> Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
- Loading branch information
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package oauthserver | ||
|
||
import ( | ||
"crypto/rand" | ||
"crypto/rsa" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGetJSONWebKeys(t *testing.T) { | ||
newpriv, err := rsa.GenerateMultiPrimeKey(rand.Reader, 4, 128) | ||
if err != nil { | ||
t.Errorf("failed to generate key") | ||
} | ||
oldpriv, err := rsa.GenerateMultiPrimeKey(rand.Reader, 4, 128) | ||
if err != nil { | ||
t.Errorf("failed to generate key") | ||
} | ||
newKey := newpriv.PublicKey | ||
oldKey := oldpriv.PublicKey | ||
publicKeys := []rsa.PublicKey{newKey, oldKey} | ||
keyset, err := getJSONWebKeys(publicKeys) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, keyset) | ||
oldJwkKey, exists := keyset.Get(1) | ||
assert.True(t, exists) | ||
oldpublicKey, exists := oldJwkKey.Get(KeyMetadataPublicCert) | ||
op, ok := oldpublicKey.(*rsa.PublicKey) | ||
assert.True(t, ok) | ||
assert.Equal(t, &oldKey, op) | ||
newJwkKey, exists := keyset.Get(0) | ||
assert.True(t, exists) | ||
newpublicKey, exists := newJwkKey.Get(KeyMetadataPublicCert) | ||
np, ok := newpublicKey.(*rsa.PublicKey) | ||
assert.True(t, ok) | ||
assert.NotEqual(t, np, op) | ||
assert.Equal(t, &newKey, np) | ||
} |