Repository: Nerzal/gocloak
Pull request #148 (2020-02-20 23:04:14)

Testing keycloak:latest
#147 


Patch:
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 1d29668..6af7df1 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -36,8 +36,8 @@ jobs:
         run: nancy go.sum
       - name: Run Keycloak
         run: |
-          docker pull quay.io/keycloak/keycloak:8.0.1
-          docker run -d -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=secret -e KEYCLOAK_IMPORT=/tmp/gocloak-realm.json -v "`pwd`/testdata/gocloak-realm.json:/tmp/gocloak-realm.json" -p 8080:8080 --name keycloak quay.io/keycloak/keycloak:8.0.1 -Dkeycloak.profile.feature.upload_scripts=enabled
+          docker pull quay.io/keycloak/keycloak:latest
+          docker run -d -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=secret -e KEYCLOAK_IMPORT=/tmp/gocloak-realm.json -v "`pwd`/testdata/gocloak-realm.json:/tmp/gocloak-realm.json" -p 8080:8080 --name keycloak quay.io/keycloak/keycloak:latest -Dkeycloak.profile.feature.upload_scripts=enabled
           sleep 10
       - name: Unit Tests
         run: |
diff --git a/models.go b/models.go
index fb05173..946fa75 100644
--- a/models.go
+++ b/models.go
@@ -12,6 +12,10 @@ import (
 // "string" tag allows to convert the non-string fields of a structure to map[string]string.
 // "omitempty" allows to skip the fields with default values.
 func GetQueryParams(s interface{}) (map[string]string, error) {
+	// if obj, ok := s.(GetGroupsParams); ok {
+	// 	obj.OnMarshal()
+	// 	s = obj
+	// }
 	b, err := json.Marshal(s)
 	if err != nil {
 		return nil, err
@@ -239,10 +243,22 @@ type Group struct {
 
 // GetGroupsParams represents the optional parameters for getting groups
 type GetGroupsParams struct {
-	First  *int    `json:"first,string,omitempty"`
-	Max    *int    `json:"max,string,omitempty"`
-	Search *string `json:"search,omitempty"`
-	Full   *bool   `json:"full,string,omitempty"`
+	First               *int    `json:"first,string,omitempty"`
+	Max                 *int    `json:"max,string,omitempty"`
+	Search              *string `json:"search,omitempty"`
+	Full                *bool   `json:"full,string,omitempty"`
+	BriefRepresentation *bool   `json:"briefRepresentation,string,omitempty"`
+}
+
+func (obj GetGroupsParams) MarshalJSON() ([]byte, error) {
+	type Alias GetGroupsParams
+	a := (Alias)(obj)
+	if a.BriefRepresentation != nil {
+		a.Full = BoolP(!*a.BriefRepresentation)
+	} else if a.Full != nil {
+		a.BriefRepresentation = BoolP(!*a.Full)
+	}
+	return json.Marshal(a)
 }
 
 // Role is a role


Test patch:
diff --git a/client_test.go b/client_test.go
index 5c64b15..cb67f5b 100644
--- a/client_test.go
+++ b/client_test.go
@@ -114,7 +114,7 @@ func GetAdminToken(t testing.TB, client GoCloak) *JWT {
 		cfg.Admin.UserName,
 		cfg.Admin.Password,
 		cfg.Admin.Realm)
-	assert.NoError(t, err, "Login failed")
+	assert.NoError(t, err, "Login Admin failed")
 	return token
 }
 
@@ -373,7 +373,7 @@ func NewClientWithDebug(t testing.TB) GoCloak {
 				} else if len(e.Error) > 0 {
 					msg = e.Error
 				}
-				return strings.HasPrefix(msg, "Cached clientScope not found")
+				return strings.HasPrefix(msg, "Cached clientScope not found") || strings.Contains(msg, "unknown_error")
 			}
 		}
 		return false
@@ -1254,6 +1254,37 @@ func TestGocloak_GetGroupsFull(t *testing.T) {
 	assert.Fail(t, "GetGroupsFull failed")
 }
 
+func TestGocloak_GetGroupsBriefRepresentation(t *testing.T) {
+	t.Parallel()
+	cfg := GetConfig(t)
+	client := NewClientWithDebug(t)
+	token := GetAdminToken(t, client)
+
+	tearDown, groupID := CreateGroup(t, client)
+	defer tearDown()
+
+	groups, err := client.GetGroups(
+		token.AccessToken,
+		cfg.GoCloak.Realm,
+		GetGroupsParams{
+			BriefRepresentation: BoolP(false),
+		})
+	assert.NoError(t, err, "GetGroups failed")
+
+	for _, group := range groups {
+		if NilOrEmpty(group.ID) {
+			continue
+		}
+		if *(group.ID) == groupID {
+			ok := client.UserAttributeContains(group.Attributes, "foo", "alice")
+			assert.True(t, ok, "UserAttributeContains")
+			return
+		}
+	}
+
+	assert.Fail(t, "GetGroupsBriefRepresentation failed")
+}
+
 func TestGocloak_GetGroupFull(t *testing.T) {
 	t.Parallel()
 	cfg := GetConfig(t)
@@ -1483,6 +1514,7 @@ func CreateRealm(t *testing.T, client GoCloak) (func(), string) {
 	assert.NoError(t, err, "CreateRealm failed")
 	assert.Equal(t, realmID, realmName)
 	tearDown := func() {
+		token := GetAdminToken(t, client)
 		err := client.DeleteRealm(
 			token.AccessToken,
 			realmName)