Skip to content

Commit

Permalink
Testing keycloak:latest
Browse files Browse the repository at this point in the history
Fix GetGroup with Full/BriefRepresentation tags
Fix GetGroupsParams
Using a new token in Realm teardown function
  • Loading branch information
Sergey Vilgelm committed Feb 21, 2020
1 parent 2f4c873 commit 51ee226
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
36 changes: 34 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 20 additions & 4 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 51ee226

Please sign in to comment.