-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARO-4373 additional unit tests and comments resolution
- Loading branch information
1 parent
9149938
commit cea889a
Showing
6 changed files
with
111 additions
and
34 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
This file was deleted.
Oops, something went wrong.
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,60 @@ | ||
package oidcbuilder | ||
|
||
import ( | ||
"crypto/rand" | ||
"crypto/rsa" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
|
||
mock_azblob "github.com/Azure/ARO-RP/pkg/util/mocks/azblob" | ||
utilerror "github.com/Azure/ARO-RP/test/util/error" | ||
) | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
func TestKeyIDFromPublicKey(t *testing.T) { | ||
privateKey, err := rsa.GenerateKey(rand.Reader, 4096) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
keyID, err := keyIDFromPublicKey(&privateKey.PublicKey) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
invalidPublicKey := rsa.PublicKey{} | ||
|
||
for _, tt := range []struct { | ||
name string | ||
mocks func(*mock_azblob.MockAZBlobClient) | ||
publicKey interface{} | ||
wantkid string | ||
wantErr string | ||
}{ | ||
{ | ||
name: "Success", | ||
publicKey: &privateKey.PublicKey, | ||
wantkid: keyID, | ||
}, | ||
{ | ||
name: "Failed to serialize public key", | ||
publicKey: &invalidPublicKey, | ||
wantErr: "Failed to serialize public key to DER format: asn1: structure error: empty integer", | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
controller := gomock.NewController(t) | ||
defer controller.Finish() | ||
|
||
kid, err := keyIDFromPublicKey(tt.publicKey) | ||
utilerror.AssertErrorMessage(t, err, tt.wantErr) | ||
|
||
if tt.wantkid != kid { | ||
t.Fatalf("Expected KeyID and returned KeyID doesn't match") | ||
} | ||
}) | ||
} | ||
} |
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