-
Notifications
You must be signed in to change notification settings - Fork 14
/
clientRoles_test.go
72 lines (54 loc) · 1.58 KB
/
clientRoles_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package keycloak
import (
"context"
"net/http"
"testing"
)
// create a new client role
func createClientRole(t *testing.T, k *Keycloak, realm, clientID, roleName string) {
t.Helper()
role := &Role{
Name: String(roleName),
Description: String(roleName + " description"),
}
if _, err := k.ClientRoles.Create(context.Background(), realm, clientID, role); err != nil {
t.Errorf("ClientRoles.Create returned error: %v", err)
}
}
func TestClientRolesService_Create(t *testing.T) {
k := client(t)
realm := "first"
createRealm(t, k, realm)
clientID := createClient(t, k, realm, "client")
ctx := context.Background()
role := &Role{
Name: String("role"),
Description: String("description"),
}
res, err := k.ClientRoles.Create(ctx, realm, clientID, role)
if err != nil {
t.Errorf("ClientRoles.Create returned error: %v", err)
}
if res.StatusCode != http.StatusCreated {
t.Errorf("got: %d, want: %d", res.StatusCode, http.StatusCreated)
}
}
func TestClientRolesService_List(t *testing.T) {
k := client(t)
realm := "first"
createRealm(t, k, realm)
clientID := createClient(t, k, realm, "client")
createClientRole(t, k, realm, clientID, "first")
createClientRole(t, k, realm, clientID, "second")
roles, res, err := k.ClientRoles.List(context.Background(), realm, clientID)
if err != nil {
t.Errorf("ClientRoles.List returned error: %v", err)
}
if res.StatusCode != http.StatusOK {
t.Errorf("got: %d, want: %d", res.StatusCode, http.StatusOK)
}
// includes "uma_protection"
if len(roles) != 3 {
t.Errorf("got: %d, want: %d", len(roles), 3)
}
}