Skip to content

Commit

Permalink
APIGOV-24312 - Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekschauhan committed Aug 8, 2023
1 parent c64a423 commit 12f823a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 70 deletions.
68 changes: 0 additions & 68 deletions pkg/apic/auth/apicauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,74 +45,6 @@ func TestChannelTokenGetterCloses(t *testing.T) {
}
}

func TestGetKey(t *testing.T) {
cases := []struct {
description string
kr *keyReader
}{
{
"no password",
&keyReader{
privKey: "testdata/private_key.pem",
},
},
{
"with empty password file",
&keyReader{
privKey: "testdata/private_key.pem",
password: "testdata/password_empty",
},
},
{
"with password",
&keyReader{
privKey: "testdata/private_key_with_pwd.pem",
password: "testdata/password",
},
},
}

for _, testCase := range cases {
if _, err := testCase.kr.getPrivateKey(); err != nil {
t.Errorf("testcase: %s: failed to read rsa key %s", testCase.description, err)
}
}
}

func TestGetPublicKey(t *testing.T) {
cases := []struct {
description string
kr *keyReader
}{
{
"with public key",
&keyReader{
publicKey: "testdata/public_key",
},
},
{
"with private and public key",
&keyReader{
privKey: "testdata/private_key.pem",
publicKey: "testdata/public_key",
},
},
{
"with private, public key, and password",
&keyReader{
privKey: "testdata/private_key_with_pwd.pem",
password: "testdata/password",
publicKey: "testdata/public_key",
},
},
}
for _, testCase := range cases {
if _, err := testCase.kr.getPublicKey(); err != nil {
t.Errorf("testcase: %s: failed to read public key %s", testCase.description, err)
}
}
}

func TestNetAuthenticate(t *testing.T) {
aa := NewWithStatic("12345", "abcde")
if aa.tenantID != "12345" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/authz/oauth/authclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestGetPlatformTokensHttpError(t *testing.T) {
s.SetTokenResponse("", 0, http.StatusBadRequest)
ac, err := NewAuthClient(s.GetTokenURL(), apiClient,
WithServerName("testServer"),
WithClientSecretAuth("invalid_client", "invalid-secrt", ""))
WithClientSecretPostAuth("invalid_client", "invalid-secrt", ""))
assert.Nil(t, err)
assert.NotNil(t, ac)

Expand Down Expand Up @@ -106,7 +106,7 @@ func TestGetPlatformTokensTimeout(t *testing.T) {
apiClient := api.NewClientWithTimeout(config.NewTLSConfig(), "", time.Second)
ac, err := NewAuthClient(s.URL, apiClient,
WithServerName("testServer"),
WithClientSecretAuth("invalid_client", "invalid-secrt", ""))
WithClientSecretPostAuth("invalid_client", "invalid-secrt", ""))

assert.Nil(t, err)
assert.NotNil(t, ac)
Expand Down
71 changes: 71 additions & 0 deletions pkg/authz/oauth/keyreader_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package oauth

import "testing"

func TestGetKey(t *testing.T) {
cases := []struct {
description string
kr *keyReader
}{
{
"no password",
&keyReader{
privKey: "../../apic/auth/testdata/private_key.pem",
},
},
{
"with empty password file",
&keyReader{
privKey: "../../apic/auth/testdata/private_key.pem",
password: "../../apic/auth/testdata/password_empty",
},
},
{
"with password",
&keyReader{
privKey: "../../apic/auth/testdata/private_key_with_pwd.pem",
password: "../../apic/auth/testdata/password",
},
},
}

for _, testCase := range cases {
if _, err := testCase.kr.GetPrivateKey(); err != nil {
t.Errorf("testcase: %s: failed to read rsa key %s", testCase.description, err)
}
}
}

func TestGetPublicKey(t *testing.T) {
cases := []struct {
description string
kr *keyReader
}{
{
"with public key",
&keyReader{
publicKey: "../../apic/auth/testdata/public_key",
},
},
{
"with private and public key",
&keyReader{
privKey: "../../apic/auth/testdata/private_key.pem",
publicKey: "../../apic/auth/testdata/public_key",
},
},
{
"with private, public key, and password",
&keyReader{
privKey: "../../apic/auth/testdata/private_key_with_pwd.pem",
password: "../../apic/auth/testdata/password",
publicKey: "../../apic/auth/testdata/public_key",
},
},
}
for _, testCase := range cases {
if _, err := testCase.kr.GetPublicKey(); err != nil {
t.Errorf("testcase: %s: failed to read public key %s", testCase.description, err)
}
}
}
3 changes: 3 additions & 0 deletions pkg/authz/oauth/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ func (p *provider) GetIssuer() string {
}

func (p *provider) useTLSAuth() bool {
if p.cfg.GetAuthConfig() == nil {
return false
}
return p.cfg.GetAuthConfig().GetType() == IDPAuthTypeTLSClientAuth || p.cfg.GetAuthConfig().GetType() == IDPAuthTypeSelfSignedTLSClientAuth
}

Expand Down

0 comments on commit 12f823a

Please sign in to comment.