Skip to content

Commit

Permalink
use constant to reduce SonarCloud smelliness metric
Browse files Browse the repository at this point in the history
  • Loading branch information
chlowell committed Feb 15, 2023
1 parent f238572 commit b5532eb
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions apps/confidential/confidential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ import (
"github.com/kylelemons/godebug/pretty"
)

const (
authorityFmt = "https://%s/%s"
localhost = "http://localhost"
)

// errorClient is an HTTP client for tests that should fail when confidential.Client sends a request
type errorClient struct{}

Expand Down Expand Up @@ -69,10 +64,12 @@ func TestCertFromPEM(t *testing.T) {
}

const (
authorityFmt = "https://%s/%s"
fakeClientID = "fake_client_id"
fakeTokenEndpoint = "https://fake_authority/fake/token"
token = "fake_token"
localhost = "http://localhost"
refresh = "fake_refresh"
token = "fake_token"
)

var tokenScope = []string{"the_scope"}
Expand Down Expand Up @@ -617,7 +614,7 @@ func TestTokenProviderOptions(t *testing.T) {
}
return TokenProviderResult{AccessToken: accessToken, ExpiresInSeconds: 3600}, nil
})
client, err := New("id", cred, WithHTTPClient(&errorClient{}))
client, err := New(fakeClientID, cred, WithHTTPClient(&errorClient{}))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -659,7 +656,7 @@ func TestWithCache(t *testing.T) {
if err != nil {
t.Fatal(err)
}
client, err := New("client-id", cred, WithAuthority(authorityA), WithCache(&cache), WithHTTPClient(&mockClient))
client, err := New(fakeClientID, cred, WithAuthority(authorityA), WithCache(&cache), WithHTTPClient(&mockClient))
if err != nil {
t.Fatal(err)
}
Expand All @@ -677,7 +674,7 @@ func TestWithCache(t *testing.T) {
}

// a client configured for a different tenant should be able to authenticate silently with the shared cache's data
client, err = New("client-id", cred, WithAuthority(authorityB), WithCache(&cache), WithHTTPClient(&mockClient))
client, err = New(fakeClientID, cred, WithAuthority(authorityB), WithCache(&cache), WithHTTPClient(&mockClient))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -786,7 +783,7 @@ func TestWithClaims(t *testing.T) {
ar, err = client.AcquireTokenByAuthCode(ctx, "code", localhost, tokenScope, WithClaims(test.claims))
case "authcodeURL":
u := ""
if u, err = client.AuthCodeURL(ctx, "client-id", localhost, tokenScope, WithClaims(test.claims)); err == nil {
if u, err = client.AuthCodeURL(ctx, fakeClientID, localhost, tokenScope, WithClaims(test.claims)); err == nil {
var parsed *url.URL
if parsed, err = url.Parse(u); err == nil {
validate(t, parsed.Query())
Expand Down Expand Up @@ -902,7 +899,7 @@ func TestWithTenantID(t *testing.T) {
case "authcode":
ar, err = client.AcquireTokenByAuthCode(ctx, "auth code", localhost, tokenScope, WithTenantID(test.tenant))
case "authcodeURL":
URL, err = client.AuthCodeURL(ctx, "client-id", localhost, tokenScope, WithTenantID(test.tenant))
URL, err = client.AuthCodeURL(ctx, fakeClientID, localhost, tokenScope, WithTenantID(test.tenant))
case "credential":
ar, err = client.AcquireTokenByCredential(ctx, tokenScope, WithTenantID(test.tenant))
case "obo":
Expand Down

0 comments on commit b5532eb

Please sign in to comment.