Skip to content

Commit 3be9133

Browse files
committed
Fix: tests
1 parent 06b0c45 commit 3be9133

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

auth/auth_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ func TestNewKeycloakAuthorizer(t *testing.T) {
2020
assert.ErrorContains(t, err, "invalid realm info")
2121
assert.ErrorContains(t, err, "realm id cannot be empty")
2222
assert.ErrorContains(t, err, "couldn't parse auth server internal url")
23-
assert.ErrorContains(t, err, "couldn't parse auth server public url")
2423
assert.Nil(t, authorizer)
2524
})
2625

@@ -36,7 +35,6 @@ func TestNewKeycloakAuthorizer(t *testing.T) {
3635
t.Run(test, func(t *testing.T) {
3736
authorizer, err := NewKeycloakAuthorizer(KeycloakRealmInfo{
3837
AuthServerInternalUrl: test,
39-
AuthServerPublicUrl: validPublicUrl,
4038
RealmId: validRealm,
4139
})
4240

@@ -46,28 +44,12 @@ func TestNewKeycloakAuthorizer(t *testing.T) {
4644
})
4745
}
4846
})
49-
t.Run("public", func(t *testing.T) {
50-
for _, test := range tests {
51-
t.Run(test, func(t *testing.T) {
52-
authorizer, err := NewKeycloakAuthorizer(KeycloakRealmInfo{
53-
AuthServerInternalUrl: validInternalUrl,
54-
AuthServerPublicUrl: test,
55-
RealmId: validRealm,
56-
})
57-
58-
assert.ErrorContains(t, err, "invalid realm info")
59-
assert.ErrorContains(t, err, "couldn't parse auth server public url")
60-
assert.Nil(t, authorizer)
61-
})
62-
}
63-
})
6447
})
6548

6649
t.Run("OK", func(t *testing.T) {
6750
authorizer, err := NewKeycloakAuthorizer(KeycloakRealmInfo{
6851
RealmId: validRealm,
6952
AuthServerInternalUrl: validInternalUrl,
70-
AuthServerPublicUrl: validPublicUrl,
7153
})
7254

7355
assert.NoError(t, err)
@@ -79,7 +61,6 @@ func TestParseJWT(t *testing.T) {
7961
authorizer, err := NewKeycloakAuthorizer(KeycloakRealmInfo{
8062
RealmId: validRealm,
8163
AuthServerInternalUrl: validInternalUrl,
82-
AuthServerPublicUrl: validPublicUrl,
8364
})
8465
require.NoError(t, err)
8566
require.NotNil(t, authorizer)
@@ -137,7 +118,6 @@ func TestParseAuthorizationHeader(t *testing.T) {
137118
authorizer, err := NewKeycloakAuthorizer(KeycloakRealmInfo{
138119
RealmId: validRealm,
139120
AuthServerInternalUrl: validInternalUrl,
140-
AuthServerPublicUrl: validPublicUrl,
141121
})
142122
require.NoError(t, err)
143123
require.NotNil(t, authorizer)
@@ -192,7 +172,6 @@ func TestParseRequest(t *testing.T) {
192172
authorizer, err := NewKeycloakAuthorizer(KeycloakRealmInfo{
193173
RealmId: validRealm,
194174
AuthServerInternalUrl: validInternalUrl,
195-
AuthServerPublicUrl: validPublicUrl,
196175
})
197176
require.NoError(t, err)
198177
require.NotNil(t, authorizer)

auth/example_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,14 @@ func ExampleNewKeycloakAuthorizer() {
4949
defer clean()
5050

5151
var (
52-
realmId = "user-management" // keycloak realm name
53-
authUrl = "http://keycloak:8080/auth" // keycloak server internal url
54-
publicUrl = "http://localhost:28080/auth" // keycloak server public url (jwt issuer)
55-
origin = "http://localhost:3000" // request origin, note: it is optional, if request doesn't have Origin header it is not validated
52+
realmId = "user-management" // keycloak realm name
53+
authUrl = "http://keycloak:8080/auth" // keycloak server internal url
54+
origin = "http://localhost:3000" // request origin, note: it is optional, if request doesn't have Origin header it is not validated
5655
)
5756

5857
realmInfo := auth.KeycloakRealmInfo{
5958
RealmId: realmId,
6059
AuthServerInternalUrl: authUrl,
61-
AuthServerPublicUrl: publicUrl,
6260
}
6361

6462
authorizer, err := auth.NewKeycloakAuthorizer(realmInfo, authorizerKeycloakMock) // NOTE: authorizerKeycloakMock only used for mocking keycloak cert response in this example, do not use outside tests!
@@ -101,16 +99,14 @@ func ExampleNewGinAuthMiddleware() {
10199
defer clean()
102100

103101
var (
104-
realmId = "user-management" // keycloak realm name
105-
authUrl = "http://keycloak:8080/auth" // keycloak server internal url
106-
publicUrl = "http://localhost:28080/auth" // keycloak server public url (jwt issuer)
107-
origin = "http://localhost:3000" // request origin, note: it is optional, if request doesn't have Origin header it is not validated
102+
realmId = "user-management" // keycloak realm name
103+
authUrl = "http://keycloak:8080/auth" // keycloak server internal url
104+
origin = "http://localhost:3000" // request origin, note: it is optional, if request doesn't have Origin header it is not validated
108105
)
109106

110107
realmInfo := auth.KeycloakRealmInfo{
111108
RealmId: realmId,
112109
AuthServerInternalUrl: authUrl,
113-
AuthServerPublicUrl: publicUrl,
114110
}
115111

116112
authorizer, err := auth.NewKeycloakAuthorizer(realmInfo, authorizerKeycloakMock) // NOTE: authorizerKeycloakMock only used for mocking keycloak cert response in this example, do not use outside tests!

0 commit comments

Comments
 (0)