* Introduce Superadmin field in OAuthClient configuration * Implement IsSuperadmin method in OAuthRegistry * Update identityAdmin to check superadmin status via OAuthRegistry * Add tests for OAuthRegistry superadmin functionality
This commit is contained in:
@@ -31,3 +31,18 @@ func (o *OAuthRegistry) Lookup(clientID string, clientSecret string) (string, bo
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// IsSuperadmin reports whether keyID (as returned by Lookup) belongs to an
|
||||
// OAuth client configured with superadmin: true.
|
||||
func (o *OAuthRegistry) IsSuperadmin(keyID string) bool {
|
||||
for _, client := range o.clients {
|
||||
id := client.ID
|
||||
if id == "" {
|
||||
id = client.ClientID
|
||||
}
|
||||
if id == keyID {
|
||||
return client.Superadmin
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -32,6 +32,26 @@ func TestNewOAuthRegistryAndLookup(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOAuthRegistryIsSuperadmin(t *testing.T) {
|
||||
registry, err := NewOAuthRegistry([]config.OAuthClient{
|
||||
{ID: "oauth-admin", ClientID: "admin-id", ClientSecret: "admin-secret", Superadmin: true},
|
||||
{ID: "oauth-client", ClientID: "client-id", ClientSecret: "client-secret"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("NewOAuthRegistry() error = %v", err)
|
||||
}
|
||||
|
||||
if !registry.IsSuperadmin("oauth-admin") {
|
||||
t.Fatal("IsSuperadmin(oauth-admin) = false, want true")
|
||||
}
|
||||
if registry.IsSuperadmin("oauth-client") {
|
||||
t.Fatal("IsSuperadmin(oauth-client) = true, want false")
|
||||
}
|
||||
if registry.IsSuperadmin("unknown") {
|
||||
t.Fatal("IsSuperadmin(unknown) = true, want false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMiddlewareAllowsOAuthBasicAuthAndSetsContext(t *testing.T) {
|
||||
oauthRegistry, err := NewOAuthRegistry([]config.OAuthClient{{
|
||||
ID: "oauth-client",
|
||||
|
||||
Reference in New Issue
Block a user