From 86ab7200ec7081c826837def315f7f249a1eb0f4 Mon Sep 17 00:00:00 2001 From: Jameel Briones Date: Tue, 24 Mar 2020 11:46:09 +0000 Subject: [PATCH 1/2] KEYCLOAK-13018: ensure state contains the correct user The following changes backports upstream changes to the Keycloak client from this PR: https://github.com/keycloak/keycloak-operator/pull/150 --- pkg/common/client.go | 84 ++++++++++++++--------------- pkg/common/client_test.go | 91 +++++++++++++++++++++++++++----- pkg/common/keycloakClient_moq.go | 60 ++++++++++----------- 3 files changed, 146 insertions(+), 89 deletions(-) diff --git a/pkg/common/client.go b/pkg/common/client.go index 44abf54..ae9a335 100644 --- a/pkg/common/client.go +++ b/pkg/common/client.go @@ -38,11 +38,11 @@ type Client struct { type T interface{} // Generic create function for creating new Keycloak resources -func (c *Client) create(obj T, resourcePath, resourceName string) error { +func (c *Client) create(obj T, resourcePath, resourceName string) (string, error) { jsonValue, err := json.Marshal(obj) if err != nil { logrus.Errorf("error %+v marshalling object", err) - return nil + return "", nil } req, err := http.NewRequest( @@ -52,7 +52,7 @@ func (c *Client) create(obj T, resourcePath, resourceName string) error { ) if err != nil { logrus.Errorf("error creating POST %s request %+v", resourceName, err) - return errors.Wrapf(err, "error creating POST %s request", resourceName) + return "", errors.Wrapf(err, "error creating POST %s request", resourceName) } req.Header.Set("Content-Type", "application/json") @@ -61,12 +61,12 @@ func (c *Client) create(obj T, resourcePath, resourceName string) error { if err != nil { logrus.Errorf("error on request %+v", err) - return errors.Wrapf(err, "error performing POST %s request", resourceName) + return "", errors.Wrapf(err, "error performing POST %s request", resourceName) } defer res.Body.Close() if res.StatusCode != 201 && res.StatusCode != 204 { - return fmt.Errorf("failed to create %s: (%d) %s", resourceName, res.StatusCode, res.Status) + return "", fmt.Errorf("failed to create %s: (%d) %s", resourceName, res.StatusCode, res.Status) } if resourceName == "client" { @@ -74,22 +74,24 @@ func (c *Client) create(obj T, resourcePath, resourceName string) error { fmt.Println("user response ", string(d)) } - return nil + location := strings.Split(res.Header.Get("Location"), "/") + uid := location[len(location)-1] + return uid, nil } -func (c *Client) CreateRealm(realm *v1alpha1.KeycloakRealm) error { +func (c *Client) CreateRealm(realm *v1alpha1.KeycloakRealm) (string, error) { return c.create(realm.Spec.Realm, "realms", "realm") } -func (c *Client) CreateClient(client *v1alpha1.KeycloakAPIClient, realmName string) error { +func (c *Client) CreateClient(client *v1alpha1.KeycloakAPIClient, realmName string) (string, error) { return c.create(client, fmt.Sprintf("realms/%s/clients", realmName), "client") } -func (c *Client) CreateUser(user *v1alpha1.KeycloakAPIUser, realmName string) error { +func (c *Client) CreateUser(user *v1alpha1.KeycloakAPIUser, realmName string) (string, error) { return c.create(user, fmt.Sprintf("realms/%s/users", realmName), "user") } -func (c *Client) CreateFederatedIdentity(fid v1alpha1.FederatedIdentity, userID string, realmName string) error { +func (c *Client) CreateFederatedIdentity(fid v1alpha1.FederatedIdentity, userID string, realmName string) (string, error) { return c.create(fid, fmt.Sprintf("realms/%s/users/%s/federated-identity/%s", realmName, userID, fid.IdentityProvider), "federated-identity") } @@ -109,14 +111,14 @@ func (c *Client) GetUserFederatedIdentities(userID string, realmName string) ([] return result.([]v1alpha1.FederatedIdentity), err } -func (c *Client) CreateUserClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, userID string) error { +func (c *Client) CreateUserClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, userID string) (string, error) { return c.create( []*v1alpha1.KeycloakUserRole{role}, fmt.Sprintf("realms/%s/users/%s/role-mappings/clients/%s", realmName, userID, clientID), "user-client-role", ) } -func (c *Client) CreateUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName, userID string) error { +func (c *Client) CreateUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName, userID string) (string, error) { return c.create( []*v1alpha1.KeycloakUserRole{role}, fmt.Sprintf("realms/%s/users/%s/role-mappings/realm", realmName, userID), @@ -124,7 +126,7 @@ func (c *Client) CreateUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName, ) } -func (c *Client) CreateAuthenticatorConfig(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName, executionID string) error { +func (c *Client) CreateAuthenticatorConfig(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName, executionID string) (string, error) { return c.create(authenticatorConfig, fmt.Sprintf("realms/%s/authentication/executions/%s/config", realmName, executionID), "AuthenticatorConfig") } @@ -179,15 +181,18 @@ func (c *Client) FindUserByEmail(email, realm string) (*v1alpha1.KeycloakAPIUser } func (c *Client) FindUserByUsername(name, realm string) (*v1alpha1.KeycloakAPIUser, error) { - result, err := c.get(fmt.Sprintf("realms/%s/users?first=0&max=1&search=%s", realm, name), "user", func(body []byte) (T, error) { + result, err := c.get(fmt.Sprintf("realms/%s/users?username=%s&max=-1", realm, name), "user", func(body []byte) (T, error) { var users []*v1alpha1.KeycloakAPIUser if err := json.Unmarshal(body, &users); err != nil { return nil, err } - if len(users) == 0 { - return nil, errors.New("not found") + + for _, user := range users { + if user.UserName == name { + return user, nil + } } - return users[0], nil + return nil, errors.New("not found") }) if err != nil { return nil, err @@ -198,9 +203,8 @@ func (c *Client) FindUserByUsername(name, realm string) (*v1alpha1.KeycloakAPIUs return result.(*v1alpha1.KeycloakAPIUser), nil } -func (c *Client) CreateIdentityProvider(identityProvider *v1alpha1.KeycloakIdentityProvider, realmName string) error { - err := c.create(identityProvider, fmt.Sprintf("realms/%s/identity-provider/instances", realmName), "identity provider") - return err +func (c *Client) CreateIdentityProvider(identityProvider *v1alpha1.KeycloakIdentityProvider, realmName string) (string, error) { + return c.create(identityProvider, fmt.Sprintf("realms/%s/identity-provider/instances", realmName), "identity provider") } // Generic get function for returning a Keycloak resource @@ -738,18 +742,7 @@ func (c *Client) CreateGroup(groupName string, realmName string) (string, error) } // Create the new group - err := c.create(group, fmt.Sprintf("realms/%s/groups", realmName), "group") - if err != nil { - return "", err - } - - createdGroup, err := c.FindGroupByName(groupName, realmName) - - if err != nil { - return "", err - } - - return createdGroup.ID, nil + return c.create(group, fmt.Sprintf("realms/%s/groups", realmName), "group") } func (c *Client) MakeGroupDefault(groupID string, realmName string) error { @@ -811,14 +804,15 @@ func (c *Client) SetGroupChild(groupID, realmName string, childGroup *Group) err } // Otherwise, set the child group - return c.create( + _, err = c.create( childGroup, fmt.Sprintf("realms/%s/groups/%s/children", realmName, groupID), "group-child", ) + return err } -func (c *Client) CreateGroupClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, groupID string) error { +func (c *Client) CreateGroupClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, groupID string) (string, error) { return c.create( []*v1alpha1.KeycloakUserRole{role}, fmt.Sprintf("realms/%s/groups/%s/role-mappings/clients/%s", realmName, groupID, clientID), @@ -890,7 +884,7 @@ func (c *Client) FindGroupClientRole(realmName, clientID, groupID string, predic return nil, nil } -func (c *Client) CreateGroupRealmRole(role *v1alpha1.KeycloakUserRole, realmName, groupID string) error { +func (c *Client) CreateGroupRealmRole(role *v1alpha1.KeycloakUserRole, realmName, groupID string) (string, error) { return c.create( []*v1alpha1.KeycloakUserRole{role}, fmt.Sprintf("realms/%s/groups/%s/role-mappings/realm", realmName, groupID), @@ -1013,13 +1007,13 @@ func defaultRequester() Requester { type KeycloakInterface interface { Ping() error - CreateRealm(realm *v1alpha1.KeycloakRealm) error + CreateRealm(realm *v1alpha1.KeycloakRealm) (string, error) GetRealm(realmName string) (*v1alpha1.KeycloakRealm, error) UpdateRealm(specRealm *v1alpha1.KeycloakRealm) error DeleteRealm(realmName string) error ListRealms() ([]*v1alpha1.KeycloakAPIRealm, error) - CreateClient(client *v1alpha1.KeycloakAPIClient, realmName string) error + CreateClient(client *v1alpha1.KeycloakAPIClient, realmName string) (string, error) GetClient(clientID, realmName string) (*v1alpha1.KeycloakAPIClient, error) GetClientSecret(clientID, realmName string) (string, error) GetClientInstall(clientID, realmName string) ([]byte, error) @@ -1027,8 +1021,8 @@ type KeycloakInterface interface { DeleteClient(clientID, realmName string) error ListClients(realmName string) ([]*v1alpha1.KeycloakAPIClient, error) - CreateUser(user *v1alpha1.KeycloakAPIUser, realmName string) error - CreateFederatedIdentity(fid v1alpha1.FederatedIdentity, userID string, realmName string) error + CreateUser(user *v1alpha1.KeycloakAPIUser, realmName string) (string, error) + CreateFederatedIdentity(fid v1alpha1.FederatedIdentity, userID string, realmName string) (string, error) RemoveFederatedIdentity(fid v1alpha1.FederatedIdentity, userID string, realmName string) error GetUserFederatedIdentities(userName string, realmName string) ([]v1alpha1.FederatedIdentity, error) UpdatePassword(user *v1alpha1.KeycloakAPIUser, realmName, newPass string) error @@ -1048,28 +1042,28 @@ type KeycloakInterface interface { ListDefaultGroups(realmName string) ([]*Group, error) SetGroupChild(groupID, realmName string, childGroup *Group) error - CreateGroupClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, groupID string) error + CreateGroupClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, groupID string) (string, error) ListGroupClientRoles(realmName, clientID, groupID string) ([]*v1alpha1.KeycloakUserRole, error) FindGroupClientRole(realmName, clientID, groupID string, predicate func(*v1alpha1.KeycloakUserRole) bool) (*v1alpha1.KeycloakUserRole, error) ListAvailableGroupClientRoles(realmName, clientID, groupID string) ([]*v1alpha1.KeycloakUserRole, error) FindAvailableGroupClientRole(realmName, clientID, groupID string, predicate func(*v1alpha1.KeycloakUserRole) bool) (*v1alpha1.KeycloakUserRole, error) - CreateGroupRealmRole(role *v1alpha1.KeycloakUserRole, realmName, groupID string) error + CreateGroupRealmRole(role *v1alpha1.KeycloakUserRole, realmName, groupID string) (string, error) ListGroupRealmRoles(realmName, groupID string) ([]*v1alpha1.KeycloakUserRole, error) ListAvailableGroupRealmRoles(realmName, groupID string) ([]*v1alpha1.KeycloakUserRole, error) - CreateIdentityProvider(identityProvider *v1alpha1.KeycloakIdentityProvider, realmName string) error + CreateIdentityProvider(identityProvider *v1alpha1.KeycloakIdentityProvider, realmName string) (string, error) GetIdentityProvider(alias, realmName string) (*v1alpha1.KeycloakIdentityProvider, error) UpdateIdentityProvider(specIdentityProvider *v1alpha1.KeycloakIdentityProvider, realmName string) error DeleteIdentityProvider(alias, realmName string) error ListIdentityProviders(realmName string) ([]*v1alpha1.KeycloakIdentityProvider, error) - CreateUserClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, userID string) error + CreateUserClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, userID string) (string, error) ListUserClientRoles(realmName, clientID, userID string) ([]*v1alpha1.KeycloakUserRole, error) ListAvailableUserClientRoles(realmName, clientID, userID string) ([]*v1alpha1.KeycloakUserRole, error) DeleteUserClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, userID string) error - CreateUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName, userID string) error + CreateUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName, userID string) (string, error) ListUserRealmRoles(realmName, userID string) ([]*v1alpha1.KeycloakUserRole, error) ListAvailableUserRealmRoles(realmName, userID string) ([]*v1alpha1.KeycloakUserRole, error) DeleteUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName, userID string) error @@ -1078,7 +1072,7 @@ type KeycloakInterface interface { FindAuthenticationExecutionForFlow(flowAlias, realmName string, predicate func(*v1alpha1.AuthenticationExecutionInfo) bool) (*v1alpha1.AuthenticationExecutionInfo, error) UpdateAuthenticationExecutionForFlow(flowAlias, realmName string, execution *v1alpha1.AuthenticationExecutionInfo) error - CreateAuthenticatorConfig(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName, executionID string) error + CreateAuthenticatorConfig(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName, executionID string) (string, error) GetAuthenticatorConfig(configID, realmName string) (*v1alpha1.AuthenticatorConfig, error) UpdateAuthenticatorConfig(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName string) error DeleteAuthenticatorConfig(configID, realmName string) error diff --git a/pkg/common/client_test.go b/pkg/common/client_test.go index e163c6c..13aeb6c 100644 --- a/pkg/common/client_test.go +++ b/pkg/common/client_test.go @@ -19,6 +19,8 @@ const ( RealmsDeletePath = "/auth/admin/realms/%s" UserCreatePath = "/auth/admin/realms/%s/users" UserDeletePath = "/auth/admin/realms/%s/users/%s" + UserGetPath = "/auth/admin/realms/%s/users/%s" + UserFindByUsernamePath = "/auth/admin/realms/%s/users?username=%s&max=-1" UserAddToGroupPath = "/auth/admin/realms/%s/users/%s/groups/%s" UserDeleteFromGroupPath = "/auth/admin/realms/%s/users/%s/groups/%s" GroupGetUsersPath = "/auth/admin/realms/%s/groups/%s/members" @@ -46,6 +48,27 @@ func getDummyRealm() *v1alpha1.KeycloakRealm { Realm: "dummy", Enabled: false, DisplayName: "dummy", + Users: []*v1alpha1.KeycloakAPIUser{ + getExistingDummyUser(), + }, + }, + }, + } +} + +func getExistingDummyUser() *v1alpha1.KeycloakAPIUser { + return &v1alpha1.KeycloakAPIUser{ + ID: "existing-dummy-user", + UserName: "existing-dummy-user", + FirstName: "existing-dummy-user", + LastName: "existing-dummy-user", + Enabled: true, + EmailVerified: true, + Credentials: []v1alpha1.KeycloakCredential{ + { + Type: "password", + Value: "password", + Temporary: false, }, }, } @@ -80,7 +103,7 @@ func TestClient_CreateRealm(t *testing.T) { realm := getDummyRealm() // when - err := client.CreateRealm(realm) + _, err := client.CreateRealm(realm) // then // no error expected @@ -117,9 +140,12 @@ func TestClient_CreateUser(t *testing.T) { // given user := getDummyUser() realm := getDummyRealm() + dummyUserID := "dummy-user-id" handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { assert.Equal(t, fmt.Sprintf(UserCreatePath, realm.Spec.Realm.Realm), req.URL.Path) + locationURL := fmt.Sprintf("http://dummy-keycloak-host/%s", UserGetPath) + w.Header().Set("Location", fmt.Sprintf(locationURL, realm.Spec.Realm.Realm, dummyUserID)) w.WriteHeader(201) }) server := httptest.NewServer(handler) @@ -132,11 +158,12 @@ func TestClient_CreateUser(t *testing.T) { } // when - err := client.CreateUser(user, realm.Spec.Realm.Realm) + uid, err := client.CreateUser(user, realm.Spec.Realm.Realm) // then // correct path expected on httptest server assert.NoError(t, err) + assert.Equal(t, uid, dummyUserID) } func TestClient_DeleteUser(t *testing.T) { @@ -165,6 +192,43 @@ func TestClient_DeleteUser(t *testing.T) { assert.NoError(t, err) } +func TestClient_FindUserByUsername(t *testing.T) { + // given + realm := getDummyRealm() + user := getExistingDummyUser() + + handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + assert.Equal(t, fmt.Sprintf(UserFindByUsernamePath, realm.Spec.Realm.Realm, user.UserName), req.URL.String()) + assert.Equal(t, req.Method, http.MethodGet) + json, err := jsoniter.Marshal(realm.Spec.Realm.Users) + assert.NoError(t, err) + + size, err := w.Write(json) + assert.NoError(t, err) + assert.Equal(t, size, len(json)) + + w.WriteHeader(200) + }) + server := httptest.NewServer(handler) + defer server.Close() + + client := Client{ + requester: server.Client(), + URL: server.URL, + token: "dummy", + } + + // when + userFound, err := client.FindUserByUsername(user.UserName, realm.Spec.Realm.Realm) + + // then + // correct path expected on httptest server + assert.NoError(t, err) + + // returned realm must equal dummy realm + assert.Equal(t, user, userFound) +} + func TestClient_ListUsersInGroup(t *testing.T) { realm := getDummyRealm() groupID := "12345" @@ -341,17 +405,8 @@ func TestClient_CreateGroup(t *testing.T) { ) handle := withMethodSelection(t, map[string]http.HandlerFunc{ - // When the client requests the groups to find the newly - // created one - http.MethodGet: withJSON(t, []*Group{ - &Group{ - ID: createdGroupID, - Name: createdGroupName, - }, - }, 200), - // When the client requests to create the group - http.MethodPost: withPathAssertion(t, 201, fmt.Sprintf(GroupCreatePath, realm.Spec.Realm.Realm)), + http.MethodPost: withPathAssertionLocationHeader(t, 201, fmt.Sprintf(GroupCreatePath, realm.Spec.Realm.Realm), createdGroupID), }) request := func(c *Client) { @@ -412,7 +467,7 @@ func TestClient_CreateGroupClientRole(t *testing.T) { with := withPathAssertion(t, 201, fmt.Sprintf(GroupCreateClientRole, realm.Spec.Realm.Realm, groupID, clientID)) when := func(c *Client) { - err := c.CreateGroupClientRole(&v1alpha1.KeycloakUserRole{}, realm.Spec.Realm.Realm, clientID, groupID) + _, err := c.CreateGroupClientRole(&v1alpha1.KeycloakUserRole{}, realm.Spec.Realm.Realm, clientID, groupID) assert.NoError(t, err) } @@ -479,7 +534,7 @@ func TestClient_CreateGroupRealmRole(t *testing.T) { testClientHTTPRequest( withPathAssertion(t, 201, expectedPath), func(c *Client) { - err := c.CreateGroupRealmRole(&v1alpha1.KeycloakUserRole{}, realm.Spec.Realm.Realm, groupID) + _, err := c.CreateGroupRealmRole(&v1alpha1.KeycloakUserRole{}, realm.Spec.Realm.Realm, groupID) assert.NoError(t, err) }, ) @@ -560,6 +615,14 @@ func withPathAssertion(t *testing.T, status int, expectedPath string) func(http. } } +func withPathAssertionLocationHeader(t *testing.T, status int, expectedPath string, uid string) func(http.ResponseWriter, *http.Request) { + return func(w http.ResponseWriter, req *http.Request) { + assert.Equal(t, expectedPath, req.URL.Path) + w.Header().Set("Location", fmt.Sprintf("%s/%s", req.URL.Path, uid)) + w.WriteHeader(status) + } +} + func withMethodSelection(t *testing.T, byMethod map[string]http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { methodFunc, ok := byMethod[req.Method] diff --git a/pkg/common/keycloakClient_moq.go b/pkg/common/keycloakClient_moq.go index 92e5ce2..828d6e1 100644 --- a/pkg/common/keycloakClient_moq.go +++ b/pkg/common/keycloakClient_moq.go @@ -84,37 +84,37 @@ var _ KeycloakInterface = &KeycloakInterfaceMock{} // AddUserToGroupFunc: func(realmName string, userID string, groupID string) error { // panic("mock out the AddUserToGroup method") // }, -// CreateAuthenticatorConfigFunc: func(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName string, executionID string) error { +// CreateAuthenticatorConfigFunc: func(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName string, executionID string) (string, error) { // panic("mock out the CreateAuthenticatorConfig method") // }, -// CreateClientFunc: func(client *v1alpha1.KeycloakAPIClient, realmName string) error { +// CreateClientFunc: func(client *v1alpha1.KeycloakAPIClient, realmName string) (string, error) { // panic("mock out the CreateClient method") // }, -// CreateFederatedIdentityFunc: func(fid v1alpha1.FederatedIdentity, userID string, realmName string) error { +// CreateFederatedIdentityFunc: func(fid v1alpha1.FederatedIdentity, userID string, realmName string) (string, error) { // panic("mock out the CreateFederatedIdentity method") // }, // CreateGroupFunc: func(group string, realmName string) (string, error) { // panic("mock out the CreateGroup method") // }, -// CreateGroupClientRoleFunc: func(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, groupID string) error { +// CreateGroupClientRoleFunc: func(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, groupID string) (string, error) { // panic("mock out the CreateGroupClientRole method") // }, -// CreateGroupRealmRoleFunc: func(role *v1alpha1.KeycloakUserRole, realmName string, groupID string) error { +// CreateGroupRealmRoleFunc: func(role *v1alpha1.KeycloakUserRole, realmName string, groupID string) (string, error) { // panic("mock out the CreateGroupRealmRole method") // }, -// CreateIdentityProviderFunc: func(identityProvider *v1alpha1.KeycloakIdentityProvider, realmName string) error { +// CreateIdentityProviderFunc: func(identityProvider *v1alpha1.KeycloakIdentityProvider, realmName string) (string, error) { // panic("mock out the CreateIdentityProvider method") // }, -// CreateRealmFunc: func(realm *v1alpha1.KeycloakRealm) error { +// CreateRealmFunc: func(realm *v1alpha1.KeycloakRealm) (string, error) { // panic("mock out the CreateRealm method") // }, -// CreateUserFunc: func(user *v1alpha1.KeycloakAPIUser, realmName string) error { +// CreateUserFunc: func(user *v1alpha1.KeycloakAPIUser, realmName string) (string, error) { // panic("mock out the CreateUser method") // }, -// CreateUserClientRoleFunc: func(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, userID string) error { +// CreateUserClientRoleFunc: func(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, userID string) (string, error) { // panic("mock out the CreateUserClientRole method") // }, -// CreateUserRealmRoleFunc: func(role *v1alpha1.KeycloakUserRole, realmName string, userID string) error { +// CreateUserRealmRoleFunc: func(role *v1alpha1.KeycloakUserRole, realmName string, userID string) (string, error) { // panic("mock out the CreateUserRealmRole method") // }, // DeleteAuthenticatorConfigFunc: func(configID string, realmName string) error { @@ -272,37 +272,37 @@ type KeycloakInterfaceMock struct { AddUserToGroupFunc func(realmName string, userID string, groupID string) error // CreateAuthenticatorConfigFunc mocks the CreateAuthenticatorConfig method. - CreateAuthenticatorConfigFunc func(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName string, executionID string) error + CreateAuthenticatorConfigFunc func(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName string, executionID string) (string, error) // CreateClientFunc mocks the CreateClient method. - CreateClientFunc func(client *v1alpha1.KeycloakAPIClient, realmName string) error + CreateClientFunc func(client *v1alpha1.KeycloakAPIClient, realmName string) (string, error) // CreateFederatedIdentityFunc mocks the CreateFederatedIdentity method. - CreateFederatedIdentityFunc func(fid v1alpha1.FederatedIdentity, userID string, realmName string) error + CreateFederatedIdentityFunc func(fid v1alpha1.FederatedIdentity, userID string, realmName string) (string, error) // CreateGroupFunc mocks the CreateGroup method. CreateGroupFunc func(group string, realmName string) (string, error) // CreateGroupClientRoleFunc mocks the CreateGroupClientRole method. - CreateGroupClientRoleFunc func(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, groupID string) error + CreateGroupClientRoleFunc func(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, groupID string) (string, error) // CreateGroupRealmRoleFunc mocks the CreateGroupRealmRole method. - CreateGroupRealmRoleFunc func(role *v1alpha1.KeycloakUserRole, realmName string, groupID string) error + CreateGroupRealmRoleFunc func(role *v1alpha1.KeycloakUserRole, realmName string, groupID string) (string, error) // CreateIdentityProviderFunc mocks the CreateIdentityProvider method. - CreateIdentityProviderFunc func(identityProvider *v1alpha1.KeycloakIdentityProvider, realmName string) error + CreateIdentityProviderFunc func(identityProvider *v1alpha1.KeycloakIdentityProvider, realmName string) (string, error) // CreateRealmFunc mocks the CreateRealm method. - CreateRealmFunc func(realm *v1alpha1.KeycloakRealm) error + CreateRealmFunc func(realm *v1alpha1.KeycloakRealm) (string, error) // CreateUserFunc mocks the CreateUser method. - CreateUserFunc func(user *v1alpha1.KeycloakAPIUser, realmName string) error + CreateUserFunc func(user *v1alpha1.KeycloakAPIUser, realmName string) (string, error) // CreateUserClientRoleFunc mocks the CreateUserClientRole method. - CreateUserClientRoleFunc func(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, userID string) error + CreateUserClientRoleFunc func(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, userID string) (string, error) // CreateUserRealmRoleFunc mocks the CreateUserRealmRole method. - CreateUserRealmRoleFunc func(role *v1alpha1.KeycloakUserRole, realmName string, userID string) error + CreateUserRealmRoleFunc func(role *v1alpha1.KeycloakUserRole, realmName string, userID string) (string, error) // DeleteAuthenticatorConfigFunc mocks the DeleteAuthenticatorConfig method. DeleteAuthenticatorConfigFunc func(configID string, realmName string) error @@ -941,7 +941,7 @@ func (mock *KeycloakInterfaceMock) AddUserToGroupCalls() []struct { } // CreateAuthenticatorConfig calls CreateAuthenticatorConfigFunc. -func (mock *KeycloakInterfaceMock) CreateAuthenticatorConfig(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName string, executionID string) error { +func (mock *KeycloakInterfaceMock) CreateAuthenticatorConfig(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName string, executionID string) (string, error) { if mock.CreateAuthenticatorConfigFunc == nil { panic("KeycloakInterfaceMock.CreateAuthenticatorConfigFunc: method is nil but KeycloakInterface.CreateAuthenticatorConfig was just called") } @@ -980,7 +980,7 @@ func (mock *KeycloakInterfaceMock) CreateAuthenticatorConfigCalls() []struct { } // CreateClient calls CreateClientFunc. -func (mock *KeycloakInterfaceMock) CreateClient(client *v1alpha1.KeycloakAPIClient, realmName string) error { +func (mock *KeycloakInterfaceMock) CreateClient(client *v1alpha1.KeycloakAPIClient, realmName string) (string, error) { if mock.CreateClientFunc == nil { panic("KeycloakInterfaceMock.CreateClientFunc: method is nil but KeycloakInterface.CreateClient was just called") } @@ -1015,7 +1015,7 @@ func (mock *KeycloakInterfaceMock) CreateClientCalls() []struct { } // CreateFederatedIdentity calls CreateFederatedIdentityFunc. -func (mock *KeycloakInterfaceMock) CreateFederatedIdentity(fid v1alpha1.FederatedIdentity, userID string, realmName string) error { +func (mock *KeycloakInterfaceMock) CreateFederatedIdentity(fid v1alpha1.FederatedIdentity, userID string, realmName string) (string, error) { if mock.CreateFederatedIdentityFunc == nil { panic("KeycloakInterfaceMock.CreateFederatedIdentityFunc: method is nil but KeycloakInterface.CreateFederatedIdentity was just called") } @@ -1089,7 +1089,7 @@ func (mock *KeycloakInterfaceMock) CreateGroupCalls() []struct { } // CreateGroupClientRole calls CreateGroupClientRoleFunc. -func (mock *KeycloakInterfaceMock) CreateGroupClientRole(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, groupID string) error { +func (mock *KeycloakInterfaceMock) CreateGroupClientRole(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, groupID string) (string, error) { if mock.CreateGroupClientRoleFunc == nil { panic("KeycloakInterfaceMock.CreateGroupClientRoleFunc: method is nil but KeycloakInterface.CreateGroupClientRole was just called") } @@ -1132,7 +1132,7 @@ func (mock *KeycloakInterfaceMock) CreateGroupClientRoleCalls() []struct { } // CreateGroupRealmRole calls CreateGroupRealmRoleFunc. -func (mock *KeycloakInterfaceMock) CreateGroupRealmRole(role *v1alpha1.KeycloakUserRole, realmName string, groupID string) error { +func (mock *KeycloakInterfaceMock) CreateGroupRealmRole(role *v1alpha1.KeycloakUserRole, realmName string, groupID string) (string, error) { if mock.CreateGroupRealmRoleFunc == nil { panic("KeycloakInterfaceMock.CreateGroupRealmRoleFunc: method is nil but KeycloakInterface.CreateGroupRealmRole was just called") } @@ -1171,7 +1171,7 @@ func (mock *KeycloakInterfaceMock) CreateGroupRealmRoleCalls() []struct { } // CreateIdentityProvider calls CreateIdentityProviderFunc. -func (mock *KeycloakInterfaceMock) CreateIdentityProvider(identityProvider *v1alpha1.KeycloakIdentityProvider, realmName string) error { +func (mock *KeycloakInterfaceMock) CreateIdentityProvider(identityProvider *v1alpha1.KeycloakIdentityProvider, realmName string) (string, error) { if mock.CreateIdentityProviderFunc == nil { panic("KeycloakInterfaceMock.CreateIdentityProviderFunc: method is nil but KeycloakInterface.CreateIdentityProvider was just called") } @@ -1206,7 +1206,7 @@ func (mock *KeycloakInterfaceMock) CreateIdentityProviderCalls() []struct { } // CreateRealm calls CreateRealmFunc. -func (mock *KeycloakInterfaceMock) CreateRealm(realm *v1alpha1.KeycloakRealm) error { +func (mock *KeycloakInterfaceMock) CreateRealm(realm *v1alpha1.KeycloakRealm) (string, error) { if mock.CreateRealmFunc == nil { panic("KeycloakInterfaceMock.CreateRealmFunc: method is nil but KeycloakInterface.CreateRealm was just called") } @@ -1237,7 +1237,7 @@ func (mock *KeycloakInterfaceMock) CreateRealmCalls() []struct { } // CreateUser calls CreateUserFunc. -func (mock *KeycloakInterfaceMock) CreateUser(user *v1alpha1.KeycloakAPIUser, realmName string) error { +func (mock *KeycloakInterfaceMock) CreateUser(user *v1alpha1.KeycloakAPIUser, realmName string) (string, error) { if mock.CreateUserFunc == nil { panic("KeycloakInterfaceMock.CreateUserFunc: method is nil but KeycloakInterface.CreateUser was just called") } @@ -1272,7 +1272,7 @@ func (mock *KeycloakInterfaceMock) CreateUserCalls() []struct { } // CreateUserClientRole calls CreateUserClientRoleFunc. -func (mock *KeycloakInterfaceMock) CreateUserClientRole(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, userID string) error { +func (mock *KeycloakInterfaceMock) CreateUserClientRole(role *v1alpha1.KeycloakUserRole, realmName string, clientID string, userID string) (string, error) { if mock.CreateUserClientRoleFunc == nil { panic("KeycloakInterfaceMock.CreateUserClientRoleFunc: method is nil but KeycloakInterface.CreateUserClientRole was just called") } @@ -1315,7 +1315,7 @@ func (mock *KeycloakInterfaceMock) CreateUserClientRoleCalls() []struct { } // CreateUserRealmRole calls CreateUserRealmRoleFunc. -func (mock *KeycloakInterfaceMock) CreateUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName string, userID string) error { +func (mock *KeycloakInterfaceMock) CreateUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName string, userID string) (string, error) { if mock.CreateUserRealmRoleFunc == nil { panic("KeycloakInterfaceMock.CreateUserRealmRoleFunc: method is nil but KeycloakInterface.CreateUserRealmRole was just called") } From 7fe58dc0f3371755191fb92aa7c9bbde5d8a74b1 Mon Sep 17 00:00:00 2001 From: Jameel Briones Date: Tue, 24 Mar 2020 16:49:40 +0000 Subject: [PATCH 2/2] bump version to 0.1.1 --- version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/version.go b/version/version.go index 44ea6af..5e560ec 100644 --- a/version/version.go +++ b/version/version.go @@ -2,5 +2,5 @@ package version var ( //Version of the Keycloak Client - Version = "0.1.0" + Version = "0.1.1" )