diff --git a/Makefile b/Makefile index 0409e81..5c5a80e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -test: +test: generate-gocloak-interface ./run-tests.sh start-keycloak: stop-keycloak @@ -6,3 +6,6 @@ start-keycloak: stop-keycloak stop-keycloak: docker-compose down + +generate-gocloak-interface: + @$(shell go env GOPATH)/bin/ifacemaker -f client.go -s GoCloak -i GoCloakIface -p gocloak -o gocloak_iface.go \ No newline at end of file diff --git a/README.md b/README.md index 6f4d7c0..6eb6b68 100644 --- a/README.md +++ b/README.md @@ -116,258 +116,7 @@ To get the `clientId` from `id`, use `GetClients` method with `GetClientsParams{ ## Features -```go -// GoCloak holds all methods a client should fulfill -type GoCloak interface { - - RestyClient() *resty.Client - SetRestyClient(restyClient *resty.Client) - - GetToken(ctx context.Context, realm string, options TokenOptions) (*JWT, error) - GetRequestingPartyToken(ctx context.Context, token, realm string, options RequestingPartyTokenOptions) (*JWT, error) - GetRequestingPartyPermissions(ctx context.Context, token, realm string, options RequestingPartyTokenOptions) (*[]RequestingPartyPermission, error) - GetRequestingPartyPermissionDecision(ctx context.Context, token, realm string, options RequestingPartyTokenOptions) (*RequestingPartyPermissionDecision, error) - - Login(ctx context.Context, clientID, clientSecret, realm, username, password string) (*JWT, error) - LoginOtp(ctx context.Context, clientID, clientSecret, realm, username, password, totp string) (*JWT, error) - Logout(ctx context.Context, clientID, clientSecret, realm, refreshToken string) error - LogoutPublicClient(ctx context.Context, clientID, realm, accessToken, refreshToken string) error - LogoutAllSessions(ctx context.Context, accessToken, realm, userID string) error - RevokeUserConsents(ctx context.Context, accessToken, realm, userID, clientID string) error - LogoutUserSession(ctx context.Context, accessToken, realm, session string) error - LoginClient(ctx context.Context, clientID, clientSecret, realm string) (*JWT, error) - LoginClientSignedJWT(ctx context.Context, clientID, realm string, key interface{}, signedMethod jwt.SigningMethod, expiresAt *jwt.Time) (*JWT, error) - LoginAdmin(ctx context.Context, username, password, realm string) (*JWT, error) - RefreshToken(ctx context.Context, refreshToken, clientID, clientSecret, realm string) (*JWT, error) - DecodeAccessToken(ctx context.Context, accessToken, realm, expectedAudience string) (*jwt.Token, *jwt.MapClaims, error) - DecodeAccessTokenCustomClaims(ctx context.Context, accessToken, realm, expectedAudience string, claims jwt.Claims) (*jwt.Token, error) - RetrospectToken(ctx context.Context, accessToken, clientID, clientSecret, realm string) (*RetrospecTokenResult, error) - GetIssuer(ctx context.Context, realm string) (*IssuerResponse, error) - GetCerts(ctx context.Context, realm string) (*CertResponse, error) - GetServerInfo(ctx context.Context, accessToken string) (*ServerInfoRepesentation, error) - GetUserInfo(ctx context.Context, accessToken, realm string) (*UserInfo, error) - GetRawUserInfo(ctx context.Context, accessToken, realm string) (map[string]interface{}, error) - SetPassword(ctx context.Context, token, userID, realm, password string, temporary bool) error - ExecuteActionsEmail(ctx context.Context, token, realm string, params ExecuteActionsEmail) error - - CreateUser(ctx context.Context, token, realm string, user User) (string, error) - CreateGroup(ctx context.Context, accessToken, realm string, group Group) (string, error) - CreateChildGroup(ctx context.Context, token, realm, groupID string, group Group) (string, error) - CreateClientRole(ctx context.Context, accessToken, realm, idOfClient string, role Role) (string, error) - CreateClient(ctx context.Context, accessToken, realm string, newClient Client) (string, error) - CreateClientScope(ctx context.Context, accessToken, realm string, scope ClientScope) (string, error) - CreateComponent(ctx context.Context, accessToken, realm string, component Component) (string, error) - CreateClientScopeMappingsRealmRoles(ctx context.Context, token, realm, idOfClient string, roles []Role) error - CreateClientScopeMappingsClientRoles(ctx context.Context, token, realm, idOfClient, idOfSelectedClient string, roles []Role) error - CreateClientScopesScopeMappingsRealmRoles(ctx context.Context, token, realm, idOfCLientScope string, roles []Role) error - CreateClientScopesScopeMappingsClientRoles(ctx context.Context, token, realm, idOfClientScope, idOfClient string, roles []Role) error - - UpdateUser(ctx context.Context, accessToken, realm string, user User) error - UpdateGroup(ctx context.Context, accessToken, realm string, updatedGroup Group) error - UpdateRole(ctx context.Context, accessToken, realm, idOfClient string, role Role) error - UpdateClient(ctx context.Context, accessToken, realm string, updatedClient Client) error - UpdateClientScope(ctx context.Context, accessToken, realm string, scope ClientScope) error - - DeleteUser(ctx context.Context, accessToken, realm, userID string) error - DeleteComponent(ctx context.Context, accessToken, realm, componentID string) error - DeleteGroup(ctx context.Context, accessToken, realm, groupID string) error - DeleteClientRole(ctx context.Context, accessToken, realm, idOfClient, roleName string) error - DeleteClientRoleFromUser(ctx context.Context, token, realm, idOfClient, userID string, roles []Role) error - DeleteClient(ctx context.Context, accessToken, realm, idOfClient string) error - DeleteClientScope(ctx context.Context, accessToken, realm, scopeID string) error - DeleteClientScopeMappingsRealmRoles(ctx context.Context, token, realm, idOfClient string, roles []Role) error - DeleteClientScopeMappingsClientRoles(ctx context.Context, token, realm, idOfClient, idOfSelectedClient string, roles []Role) error - DeleteClientScopesScopeMappingsRealmRoles(ctx context.Context, token, realm, idOfCLientScope string, roles []Role) error - DeleteClientScopesScopeMappingsClientRoles(ctx context.Context, token, realm, idOfClientScope, ifOfClient string, roles []Role) error - - GetClient(ctx context.Context, accessToken, realm, idOfClient string) (*Client, error) - GetClientsDefaultScopes(ctx context.Context, token, realm, idOfClient string) ([]*ClientScope, error) - AddDefaultScopeToClient(ctx context.Context, token, realm, idOfClient, scopeID string) error - RemoveDefaultScopeFromClient(ctx context.Context, token, realm, idOfClient, scopeID string) error - GetClientsOptionalScopes(ctx context.Context, token, realm, idOfClient string) ([]*ClientScope, error) - AddOptionalScopeToClient(ctx context.Context, token, realm, idOfClient, scopeID string) error - RemoveOptionalScopeFromClient(ctx context.Context, token, realm, idOfClient, scopeID string) error - GetDefaultOptionalClientScopes(ctx context.Context, token, realm string) ([]*ClientScope, error) - GetDefaultDefaultClientScopes(ctx context.Context, token, realm string) ([]*ClientScope, error) - GetClientScope(ctx context.Context, token, realm, scopeID string) (*ClientScope, error) - GetClientScopes(ctx context.Context, token, realm string) ([]*ClientScope, error) - GetClientScopeMappings(ctx context.Context, token, realm, idOfClient string) (*MappingsRepresentation, error) - GetClientScopeMappingsRealmRoles(ctx context.Context, token, realm, idOfClient string) ([]*Role, error) - GetClientScopeMappingsRealmRolesAvailable(ctx context.Context, token, realm, idOfClient string) ([]*Role, error) - GetClientScopesScopeMappingsRealmRolesAvailable(ctx context.Context, token, realm, idOfClientScope string) ([]*Role, error) - GetClientScopesScopeMappingsClientRolesAvailable(ctx context.Context, token, realm, idOfClientScope, idOfClient string) ([]*Role, error) - GetClientScopeMappingsClientRoles(ctx context.Context, token, realm, idOfClient, idOfSelectedClient string) ([]*Role, error) - GetClientScopesScopeMappingsRealmRoles(ctx context.Context, token, realm, idOfClientScope string) ([]*Role, error) - GetClientScopesScopeMappingsClientRoles(ctx context.Context, token, realm, idOfClientScope, idOfClient string) ([]*Role, error) - GetClientScopeMappingsClientRolesAvailable(ctx context.Context, token, realm, idOfClient, idOfSelectedClient string) ([]*Role, error) - GetClientSecret(ctx context.Context, token, realm, idOfClient string) (*CredentialRepresentation, error) - GetClientServiceAccount(ctx context.Context, token, realm, idOfClient string) (*User, error) - RegenerateClientSecret(ctx context.Context, token, realm, idOfClient string) (*CredentialRepresentation, error) - GetKeyStoreConfig(ctx context.Context, accessToken, realm string) (*KeyStoreConfig, error) - GetUserByID(ctx context.Context, accessToken, realm, userID string) (*User, error) - GetUserCount(ctx context.Context, accessToken, realm string, params GetUsersParams) (int, error) - GetUsers(ctx context.Context, accessToken, realm string, params GetUsersParams) ([]*User, error) - GetUserGroups(ctx context.Context, accessToken, realm, userID string, params GetGroupsParams) ([]*UserGroup, error) - AddUserToGroup(ctx context.Context, token, realm, userID, groupID string) error - DeleteUserFromGroup(ctx context.Context, token, realm, userID, groupID string) error - GetComponents(ctx context.Context, accessToken, realm string) ([]*Component, error) - GetGroups(ctx context.Context, accessToken, realm string, params GetGroupsParams) ([]*Group, error) - GetGroupsCount(ctx context.Context, token, realm string, params GetGroupsParams) (int, error) - GetGroup(ctx context.Context, accessToken, realm, groupID string) (*Group, error) - GetDefaultGroups(ctx context.Context, accessToken, realm string) ([]*Group, error) - AddDefaultGroup(ctx context.Context, accessToken, realm, groupID string) error - RemoveDefaultGroup(ctx context.Context, accessToken, realm, groupID string) error - GetGroupMembers(ctx context.Context, accessToken, realm, groupID string, params GetGroupsParams) ([]*User, error) - GetRoleMappingByGroupID(ctx context.Context, accessToken, realm, groupID string) (*MappingsRepresentation, error) - GetRoleMappingByUserID(ctx context.Context, accessToken, realm, userID string) (*MappingsRepresentation, error) - GetClientRoles(ctx context.Context, accessToken, realm, idOfClient string, params GetRoleParams) ([]*Role, error) - GetClientRole(ctx context.Context, token, realm, idOfClient, roleName string) (*Role, error) - GetClientRoleByID(ctx context.Context, accessToken, realm, roleID string) (*Role, error) - GetClients(ctx context.Context, accessToken, realm string, params GetClientsParams) ([]*Client, error) - AddClientRoleComposite(ctx context.Context, token, realm, roleID string, roles []Role) error - DeleteClientRoleComposite(ctx context.Context, token, realm, roleID string, roles []Role) error - GetUsersByRoleName(ctx context.Context, token, realm, roleName string) ([]*User, error) - GetUsersByClientRoleName(ctx context.Context, token, realm, idOfClient, roleName string, params GetUsersByRoleParams) ([]*User, error) - CreateClientProtocolMapper(ctx context.Context, token, realm, idOfClient string, mapper ProtocolMapperRepresentation) (string, error) - UpdateClientProtocolMapper(ctx context.Context, token, realm, idOfClient, mapperID string, mapper ProtocolMapperRepresentation) error - DeleteClientProtocolMapper(ctx context.Context, token, realm, idOfClient, mapperID string) error - - // *** Realm Roles *** - - CreateRealmRole(ctx context.Context, token, realm string, role Role) (string, error) - GetRealmRole(ctx context.Context, token, realm, roleName string) (*Role, error) - GetRealmRoles(ctx context.Context, accessToken, realm string, params GetRoleParams) ([]*Role, error) - GetRealmRoleByID(ctx context.Context, token, realm, roleID string) (*Role, error) - GetRealmRolesByUserID(ctx context.Context, accessToken, realm, userID string) ([]*Role, error) - GetRealmRolesByGroupID(ctx context.Context, accessToken, realm, groupID string) ([]*Role, error) - UpdateRealmRole(ctx context.Context, token, realm, roleName string, role Role) error - UpdateRealmRoleByID(ctx context.Context, token, realm, roleID string, role Role) error - DeleteRealmRole(ctx context.Context, token, realm, roleName string) error - AddRealmRoleToUser(ctx context.Context, token, realm, userID string, roles []Role) error - DeleteRealmRoleFromUser(ctx context.Context, token, realm, userID string, roles []Role) error - AddRealmRoleToGroup(ctx context.Context, token, realm, groupID string, roles []Role) error - DeleteRealmRoleFromGroup(ctx context.Context, token, realm, groupID string, roles []Role) error - AddRealmRoleComposite(ctx context.Context, token, realm, roleName string, roles []Role) error - DeleteRealmRoleComposite(ctx context.Context, token, realm, roleName string, roles []Role) error - GetCompositeRealmRoles(ctx context.Context, token, realm, roleName string) ([]*Role, error) - GetCompositeRealmRolesByRoleID(ctx context.Context, token, realm, roleID string) ([]*Role, error) - GetCompositeRealmRolesByUserID(ctx context.Context, token, realm, userID string) ([]*Role, error) - GetCompositeRealmRolesByGroupID(ctx context.Context, token, realm, groupID string) ([]*Role, error) - GetAvailableRealmRolesByUserID(ctx context.Context, token, realm, userID string) ([]*Role, error) - GetAvailableRealmRolesByGroupID(ctx context.Context, token, realm, groupID string) ([]*Role, error) - - // *** Client Roles *** - - AddClientRoleToUser(ctx context.Context, token, realm, idOfClient, userID string, roles []Role) error - AddClientRoleToGroup(ctx context.Context, token, realm, idOfClient, groupID string, roles []Role) error - DeleteClientRoleFromGroup(ctx context.Context, token, realm, idOfClient, groupID string, roles []Role) error - GetCompositeClientRolesByRoleID(ctx context.Context, token, realm, idOfClient, roleID string) ([]*Role, error) - GetClientRolesByUserID(ctx context.Context, token, realm, idOfClient, userID string) ([]*Role, error) - GetClientRolesByGroupID(ctx context.Context, token, realm, idOfClient, groupID string) ([]*Role, error) - GetCompositeClientRolesByUserID(ctx context.Context, token, realm, idOfClient, userID string) ([]*Role, error) - GetCompositeClientRolesByGroupID(ctx context.Context, token, realm, idOfClient, groupID string) ([]*Role, error) - GetAvailableClientRolesByUserID(ctx context.Context, token, realm, idOfClient, userID string) ([]*Role, error) - GetAvailableClientRolesByGroupID(ctx context.Context, token, realm, idOfClient, groupID string) ([]*Role, error) - - // *** Realm *** - - GetRealm(ctx context.Context, token, realm string) (*RealmRepresentation, error) - GetRealms(ctx context.Context, token string) ([]*RealmRepresentation, error) - CreateRealm(ctx context.Context, token string, realm RealmRepresentation) (string, error) - UpdateRealm(ctx context.Context, token string, realm RealmRepresentation) error - DeleteRealm(ctx context.Context, token, realm string) error - ClearRealmCache(ctx context.Context, token, realm string) error - ClearUserCache(ctx context.Context, token, realm string) error - ClearKeysCache(ctx context.Context, token, realm string) error - -GetClientUserSessions(ctx context.Context, token, realm, idOfClient string, params ...GetClientUserSessionsParams) ([]*UserSessionRepresentation, error) -GetClientOfflineSessions(ctx context.Context, token, realm, idOfClient string, params ...GetClientUserSessionsParams) ([]*UserSessionRepresentation, error) - GetUserSessions(ctx context.Context, token, realm, userID string) ([]*UserSessionRepresentation, error) - GetUserOfflineSessionsForClient(ctx context.Context, token, realm, userID, idOfClient string) ([]*UserSessionRepresentation, error) - - // *** Protection API *** - GetResource(ctx context.Context, token, realm, idOfClient, resourceID string) (*ResourceRepresentation, error) - GetResources(ctx context.Context, token, realm, idOfClient string, params GetResourceParams) ([]*ResourceRepresentation, error) - CreateResource(ctx context.Context, token, realm, idOfClient string, resource ResourceRepresentation) (*ResourceRepresentation, error) - UpdateResource(ctx context.Context, token, realm, idOfClient string, resource ResourceRepresentation) error - DeleteResource(ctx context.Context, token, realm, idOfClient, resourceID string) error - - GetResourceClient(ctx context.Context, token, realm, resourceID string) (*ResourceRepresentation, error) - GetResourcesClient(ctx context.Context, token, realm string, params GetResourceParams) ([]*ResourceRepresentation, error) - CreateResourceClient(ctx context.Context, token, realm string, resource ResourceRepresentation) (*ResourceRepresentation, error) - UpdateResourceClient(ctx context.Context, token, realm string, resource ResourceRepresentation) error - DeleteResourceClient(ctx context.Context, token, realm, resourceID string) error - - GetScope(ctx context.Context, token, realm, idOfClient, scopeID string) (*ScopeRepresentation, error) - GetScopes(ctx context.Context, token, realm, idOfClient string, params GetScopeParams) ([]*ScopeRepresentation, error) - CreateScope(ctx context.Context, token, realm, idOfClient string, scope ScopeRepresentation) (*ScopeRepresentation, error) - UpdateScope(ctx context.Context, token, realm, idOfClient string, resource ScopeRepresentation) error - DeleteScope(ctx context.Context, token, realm, idOfClient, scopeID string) error - - GetPolicy(ctx context.Context, token, realm, idOfClient, policyID string) (*PolicyRepresentation, error) - GetPolicies(ctx context.Context, token, realm, idOfClient string, params GetPolicyParams) ([]*PolicyRepresentation, error) - CreatePolicy(ctx context.Context, token, realm, idOfClient string, policy PolicyRepresentation) (*PolicyRepresentation, error) - UpdatePolicy(ctx context.Context, token, realm, idOfClient string, policy PolicyRepresentation) error - DeletePolicy(ctx context.Context, token, realm, idOfClient, policyID string) error - - GetResourcePolicy(ctx context.Context, token, realm, permissionID string) (*ResourcePolicyRepresentation, error) - GetResourcePolicies(ctx context.Context, token, realm string, params GetResourcePoliciesParams) ([]*ResourcePolicyRepresentation, error) - CreateResourcePolicy(ctx context.Context, token, realm, resourceID string, policy ResourcePolicyRepresentation) (*ResourcePolicyRepresentation, error) - UpdateResourcePolicy(ctx context.Context, token, realm, permissionID string, policy ResourcePolicyRepresentation) error - DeleteResourcePolicy(ctx context.Context, token, realm, permissionID string) error - - GetPermission(ctx context.Context, token, realm, idOfClient, permissionID string) (*PermissionRepresentation, error) - GetPermissions(ctx context.Context, token, realm, idOfClient string, params GetPermissionParams) ([]*PermissionRepresentation, error) - GetPermissionResources(ctx context.Context, token, realm, idOfClient, permissionID string) ([]*PermissionResource, error) - GetPermissionScopes(ctx context.Context, token, realm, idOfClient, permissionID string) ([]*PermissionScope, error) - GetDependentPermissions(ctx context.Context, token, realm, idOfClient, policyID string) ([]*PermissionRepresentation, error) - CreatePermission(ctx context.Context, token, realm, idOfClient string, permission PermissionRepresentation) (*PermissionRepresentation, error) - UpdatePermission(ctx context.Context, token, realm, idOfClient string, permission PermissionRepresentation) error - DeletePermission(ctx context.Context, token, realm, idOfClient, permissionID string) error - - CreatePermissionTicket(ctx context.Context, token, realm string, permissions []CreatePermissionTicketParams) (*PermissionTicketResponseRepresentation, error) - GrantUserPermission(ctx context.Context, token, realm string, permission PermissionGrantParams) (*PermissionGrantResponseRepresentation, error) - UpdateUserPermission(ctx context.Context, token, realm string, permission PermissionGrantParams) (*PermissionGrantResponseRepresentation, error) - GetUserPermissions(ctx context.Context, token, realm string, params GetUserPermissionParams) ([]*PermissionGrantResponseRepresentation, error) - DeleteUserPermission(ctx context.Context, token, realm, ticketID string) error - - // *** Credentials API *** - - GetCredentialRegistrators(ctx context.Context, token, realm string) ([]string, error) - GetConfiguredUserStorageCredentialTypes(ctx context.Context, token, realm, userID string) ([]string, error) - GetCredentials(ctx context.Context, token, realm, UserID string) ([]*CredentialRepresentation, error) - DeleteCredentials(ctx context.Context, token, realm, UserID, CredentialID string) error - UpdateCredentialUserLabel(ctx context.Context, token, realm, userID, credentialID, userLabel string) error - DisableAllCredentialsByType(ctx context.Context, token, realm, userID string, types []string) error - MoveCredentialBehind(ctx context.Context, token, realm, userID, credentialID, newPreviousCredentialID string) error - MoveCredentialToFirst(ctx context.Context, token, realm, userID, credentialID string) error - -// *** Authentication Flows *** -GetAuthenticationFlows(ctx context.Context, token, realm string) ([]*AuthenticationFlowRepresentation, error) -GetAuthenticationFlow(ctx context.Context, token, realm string, authenticationFlowID string) (*AuthenticationFlowRepresentation, error) -CreateAuthenticationFlow(ctx context.Context, token, realm string, flow AuthenticationFlowRepresentation) error -UpdateAuthenticationFlow(ctx context.Context, token, realm string, flow AuthenticationFlowRepresentation, authenticationFlowID string) (*AuthenticationFlowRepresentation, error) -DeleteAuthenticationFlow(ctx context.Context, token, realm, flowID string) error - -// *** Identity Providers *** - - CreateIdentityProvider(ctx context.Context, token, realm string, providerRep IdentityProviderRepresentation) (string, error) - GetIdentityProvider(ctx context.Context, token, realm, alias string) (*IdentityProviderRepresentation, error) - GetIdentityProviders(ctx context.Context, token, realm string) ([]*IdentityProviderRepresentation, error) - UpdateIdentityProvider(ctx context.Context, token, realm, alias string, providerRep IdentityProviderRepresentation) error - DeleteIdentityProvider(ctx context.Context, token, realm, alias string) error - - CreateIdentityProviderMapper(ctx context.Context, token, realm, alias string, mapper IdentityProviderMapper) (string, error) - GetIdentityProviderMapper(ctx context.Context, token string, realm string, alias string, mapperID string) (*IdentityProviderMapper, error) - CreateUserFederatedIdentity(ctx context.Context, token, realm, userID, providerID string, federatedIdentityRep FederatedIdentityRepresentation) error - GetUserFederatedIdentities(ctx context.Context, token, realm, userID string) ([]*FederatedIdentityRepresentation, error) - DeleteUserFederatedIdentity(ctx context.Context, token, realm, userID, providerID string) error - - // *** Events API *** - GetEvents(ctx context.Context, token string, realm string, params GetEventsParams) ([]*EventRepresentation, error) - -} -``` +[GoCloakIface](gocloak_iface.go) holds all methods a client should fulfil. ## Configure gocloak to skip TLS Insecure Verification diff --git a/client.go b/client.go index ccff45f..e2f2dfe 100644 --- a/client.go +++ b/client.go @@ -39,6 +39,9 @@ type GoCloak struct { } } +// Verify struct implements interface +var _ GoCloakIface = &GoCloak{} + const ( adminClientID string = "admin-cli" urlSeparator string = "/" diff --git a/client_test.go b/client_test.go index 0cda97c..b4c8699 100644 --- a/client_test.go +++ b/client_test.go @@ -92,7 +92,7 @@ func GetConfig(t testing.TB) *Config { return config } -func GetClientToken(t *testing.T, client *gocloak.GoCloak) *gocloak.JWT { +func GetClientToken(t *testing.T, client gocloak.GoCloakIface) *gocloak.JWT { cfg := GetConfig(t) token, err := client.LoginClient( context.Background(), @@ -103,7 +103,7 @@ func GetClientToken(t *testing.T, client *gocloak.GoCloak) *gocloak.JWT { return token } -func GetUserToken(t *testing.T, client *gocloak.GoCloak) *gocloak.JWT { +func GetUserToken(t *testing.T, client gocloak.GoCloakIface) *gocloak.JWT { SetUpTestUser(t, client) cfg := GetConfig(t) token, err := client.Login( @@ -117,7 +117,7 @@ func GetUserToken(t *testing.T, client *gocloak.GoCloak) *gocloak.JWT { return token } -func GetAdminToken(t testing.TB, client *gocloak.GoCloak) *gocloak.JWT { +func GetAdminToken(t testing.TB, client gocloak.GoCloakIface) *gocloak.JWT { cfg := GetConfig(t) token, err := client.LoginAdmin( context.Background(), @@ -140,7 +140,7 @@ func GetRandomNameP(name string) *string { return &r } -func GetClientByClientID(t *testing.T, client *gocloak.GoCloak, clientID string) *gocloak.Client { +func GetClientByClientID(t *testing.T, client gocloak.GoCloakIface, clientID string) *gocloak.Client { cfg := GetConfig(t) token := GetAdminToken(t, client) clients, err := client.GetClients( @@ -163,7 +163,7 @@ func GetClientByClientID(t *testing.T, client *gocloak.GoCloak, clientID string) return nil } -func CreateGroup(t testing.TB, client *gocloak.GoCloak) (func(), string) { +func CreateGroup(t testing.TB, client gocloak.GoCloakIface) (func(), string) { cfg := GetConfig(t) token := GetAdminToken(t, client) group := gocloak.Group{ @@ -194,7 +194,7 @@ func CreateGroup(t testing.TB, client *gocloak.GoCloak) (func(), string) { return tearDown, groupID } -func CreateResource(t *testing.T, client *gocloak.GoCloak, idOfClient string) (func(), string) { +func CreateResource(t *testing.T, client gocloak.GoCloakIface, idOfClient string) (func(), string) { cfg := GetConfig(t) token := GetAdminToken(t, client) resource := gocloak.ResourceRepresentation{ @@ -233,7 +233,7 @@ func CreateResource(t *testing.T, client *gocloak.GoCloak, idOfClient string) (f return tearDown, *createdResource.ID } -func CreateResourceClientWithScopes(t *testing.T, client *gocloak.GoCloak) (func(), string) { +func CreateResourceClientWithScopes(t *testing.T, client gocloak.GoCloakIface) (func(), string) { cfg := GetConfig(t) token := GetClientToken(t, client) resource := gocloak.ResourceRepresentation{ @@ -277,7 +277,7 @@ func CreateResourceClientWithScopes(t *testing.T, client *gocloak.GoCloak) (func return tearDown, *createdResource.ID } -func CreateResourceClient(t *testing.T, client *gocloak.GoCloak) (func(), string) { +func CreateResourceClient(t *testing.T, client gocloak.GoCloakIface) (func(), string) { cfg := GetConfig(t) token := GetClientToken(t, client) resource := gocloak.ResourceRepresentation{ @@ -314,7 +314,7 @@ func CreateResourceClient(t *testing.T, client *gocloak.GoCloak) (func(), string return tearDown, *createdResource.ID } -func CreateScope(t *testing.T, client *gocloak.GoCloak, idOfClient string) (func(), string) { +func CreateScope(t *testing.T, client gocloak.GoCloakIface, idOfClient string) (func(), string) { cfg := GetConfig(t) token := GetAdminToken(t, client) scope := gocloak.ScopeRepresentation{ @@ -343,7 +343,7 @@ func CreateScope(t *testing.T, client *gocloak.GoCloak, idOfClient string) (func return tearDown, *createdScope.ID } -func CreatePolicy(t *testing.T, client *gocloak.GoCloak, idOfClient string, policy gocloak.PolicyRepresentation) (func(), string) { +func CreatePolicy(t *testing.T, client gocloak.GoCloakIface, idOfClient string, policy gocloak.PolicyRepresentation) (func(), string) { cfg := GetConfig(t) token := GetAdminToken(t, client) createdPolicy, err := client.CreatePolicy( @@ -368,7 +368,7 @@ func CreatePolicy(t *testing.T, client *gocloak.GoCloak, idOfClient string, poli return tearDown, *createdPolicy.ID } -func CreatePermission(t *testing.T, client *gocloak.GoCloak, idOfClient string, permission gocloak.PermissionRepresentation) (func(), string) { +func CreatePermission(t *testing.T, client gocloak.GoCloakIface, idOfClient string, permission gocloak.PermissionRepresentation) (func(), string) { cfg := GetConfig(t) token := GetAdminToken(t, client) createdPermission, err := client.CreatePermission( @@ -392,7 +392,7 @@ func CreatePermission(t *testing.T, client *gocloak.GoCloak, idOfClient string, return tearDown, *createdPermission.ID } -func CreateClient(t *testing.T, client *gocloak.GoCloak, newClient *gocloak.Client) (func(), string) { +func CreateClient(t *testing.T, client gocloak.GoCloakIface, newClient *gocloak.Client) (func(), string) { if newClient == nil { newClient = &gocloak.Client{ ClientID: GetRandomNameP("ClientID"), @@ -420,7 +420,7 @@ func CreateClient(t *testing.T, client *gocloak.GoCloak, newClient *gocloak.Clie return tearDown, createdID } -func SetUpTestUser(t testing.TB, client *gocloak.GoCloak) { +func SetUpTestUser(t testing.TB, client gocloak.GoCloakIface) { setupOnce.Do(func() { cfg := GetConfig(t) token := GetAdminToken(t, client) @@ -554,7 +554,7 @@ func FailRequest(client *gocloak.GoCloak, err error, failN, skipN int) *gocloak. return client } -func ClearRealmCache(t testing.TB, client *gocloak.GoCloak, realm ...string) { +func ClearRealmCache(t testing.TB, client gocloak.GoCloakIface, realm ...string) { cfg := GetConfig(t) token := GetAdminToken(t, client) if len(realm) == 0 { @@ -1293,7 +1293,7 @@ func Test_GroupPermissions(t *testing.T) { } } -func CreateClientRole(t *testing.T, client *gocloak.GoCloak) (func(), string) { +func CreateClientRole(t *testing.T, client gocloak.GoCloakIface) (func(), string) { cfg := GetConfig(t) token := GetAdminToken(t, client) @@ -1404,7 +1404,7 @@ func Test_GetClientRole(t *testing.T) { require.Nil(t, role) } -func CreateClientScope(t *testing.T, client *gocloak.GoCloak, scope *gocloak.ClientScope) (func(), string) { +func CreateClientScope(t *testing.T, client gocloak.GoCloakIface, scope *gocloak.ClientScope) (func(), string) { cfg := GetConfig(t) token := GetAdminToken(t, client) @@ -1445,7 +1445,7 @@ func Test_CreateClientScope_DeleteClientScope(t *testing.T) { tearDown() } -func CreateUpdateClientScopeProtocolMapper(t *testing.T, client *gocloak.GoCloak, scopeID string, protocolMapper *gocloak.ProtocolMappers) (func(), string) { +func CreateUpdateClientScopeProtocolMapper(t *testing.T, client gocloak.GoCloakIface, scopeID string, protocolMapper *gocloak.ProtocolMappers) (func(), string) { cfg := GetConfig(t) token := GetAdminToken(t, client) @@ -1738,7 +1738,7 @@ func Test_GetClientScopeProtocolMappers(t *testing.T) { require.NotNil(t, protocolMappers) } -func CreateClientScopeMappingsRealmRoles(t *testing.T, client *gocloak.GoCloak, idOfClient string, roles []gocloak.Role) func() { +func CreateClientScopeMappingsRealmRoles(t *testing.T, client gocloak.GoCloakIface, idOfClient string, roles []gocloak.Role) func() { token := GetAdminToken(t, client) cfg := GetConfig(t) @@ -1765,7 +1765,7 @@ func CreateClientScopeMappingsRealmRoles(t *testing.T, client *gocloak.GoCloak, return tearDown } -func CreateClientScopeMappingsClientRoles(t *testing.T, client *gocloak.GoCloak, idOfClient, clients string, roles []gocloak.Role) func() { +func CreateClientScopeMappingsClientRoles(t *testing.T, client gocloak.GoCloakIface, idOfClient, clients string, roles []gocloak.Role) func() { token := GetAdminToken(t, client) cfg := GetConfig(t) @@ -1948,7 +1948,7 @@ func Test_ClientScopeMappingsRealmRoles(t *testing.T) { } func CreateClientScopesMappingsClientRoles( - t *testing.T, client *gocloak.GoCloak, scopeID, idOfClient string, roles []gocloak.Role, + t *testing.T, client gocloak.GoCloakIface, scopeID, idOfClient string, roles []gocloak.Role, ) func() { token := GetAdminToken(t, client) cfg := GetConfig(t) @@ -2723,7 +2723,7 @@ func Test_GetRealms(t *testing.T) { // Realm // ----------- -func CreateRealm(t *testing.T, client *gocloak.GoCloak) (func(), string) { +func CreateRealm(t *testing.T, client gocloak.GoCloakIface) (func(), string) { token := GetAdminToken(t, client) realmName := GetRandomName("Realm") @@ -2800,7 +2800,7 @@ func Test_ClearRealmCache(t *testing.T) { // Realm Roles // ----------- -func CreateRealmRole(t *testing.T, client *gocloak.GoCloak) (func(), string) { +func CreateRealmRole(t *testing.T, client gocloak.GoCloakIface) (func(), string) { cfg := GetConfig(t) token := GetAdminToken(t, client) @@ -3146,7 +3146,7 @@ func Test_AddRealmRoleComposite_DeleteRealmRoleComposite(t *testing.T) { // Users // ----- -func CreateUser(t *testing.T, client *gocloak.GoCloak) (func(), string) { +func CreateUser(t *testing.T, client gocloak.GoCloakIface) (func(), string) { cfg := GetConfig(t) token := GetAdminToken(t, client) @@ -6945,7 +6945,7 @@ func TestGocloak_UpdateRequiredAction(t *testing.T) { require.NoError(t, err, "Failed to update required action") } -func CreateComponent(t *testing.T, client *gocloak.GoCloak) (func(), *gocloak.Component) { +func CreateComponent(t *testing.T, client gocloak.GoCloakIface) (func(), *gocloak.Component) { newComponent := &gocloak.Component{ Name: GetRandomNameP("CreateComponent"), ProviderID: gocloak.StringP("rsa-generated"), diff --git a/go.mod b/go.mod index cde0112..479fe1e 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,13 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/jessevdk/go-flags v1.4.1-0.20181029123624-5de817a9aa20 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/vburenin/ifacemaker v1.2.1 // indirect + golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/tools v0.1.10 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 86853e2..65eec96 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPr github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/jessevdk/go-flags v1.4.1-0.20181029123624-5de817a9aa20 h1:dAOsPLhnBzIyxu0VvmnKjlNcIlgMK+erD6VRHDtweMI= +github.com/jessevdk/go-flags v1.4.1-0.20181029123624-5de817a9aa20/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -21,16 +23,26 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/vburenin/ifacemaker v1.2.1 h1:3Vq8B/bfBgjWTkv+jDg4dVL1KHt3k1K4lO7XRxYA2sk= +github.com/vburenin/ifacemaker v1.2.1/go.mod h1:5WqrzX2aD7/hi+okBjcaEQJMg4lDGrpuEX3B8L4Wgrs= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= +golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=