-
Notifications
You must be signed in to change notification settings - Fork 14
/
clientScopes_test.go
111 lines (84 loc) · 2.68 KB
/
clientScopes_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package keycloak
import (
"context"
"net/http"
"strings"
"testing"
)
// create a new client scope.
func createClientScope(t *testing.T, k *Keycloak, realm string, clientScopeName string) string {
t.Helper()
clientScope := &ClientScope{
Name: String(clientScopeName),
Description: String(clientScopeName + " description"),
}
res, err := k.ClientScopes.Create(context.Background(), realm, clientScope)
if err != nil {
t.Errorf("ClientScopes.Create returned error: %v", err)
}
parts := strings.Split(res.Header.Get("Location"), "/")
clientScopeID := parts[len(parts)-1]
return clientScopeID
}
func TestClientScopesService_List(t *testing.T) {
k := client(t)
realm := "first"
createRealm(t, k, realm)
clientScopes, res, err := k.ClientScopes.List(context.Background(), realm)
if err != nil {
t.Errorf("ClientScopes.List returned error: %v", err)
}
if res.StatusCode != http.StatusOK {
t.Errorf("got: %d, want: %d", res.StatusCode, http.StatusOK)
}
// ...-dedicated, acr, address, email, microprofile-jwt, offline_access, phone, profile, roles, web-origins
if len(clientScopes) != 10 {
t.Errorf("got: %d, want: %d", len(clientScopes), 10)
}
}
func TestClientScopesService_Create(t *testing.T) {
k := client(t)
realm := "first"
createRealm(t, k, realm)
ctx := context.Background()
clientScope := &ClientScope{
Name: String("my-client-scope"),
Description: String("some description"),
}
res, err := k.ClientScopes.Create(ctx, realm, clientScope)
if err != nil {
t.Errorf("ClientScopes.Create returned error: %v", err)
}
if res.StatusCode != http.StatusCreated {
t.Errorf("got: %d, want: %d", res.StatusCode, http.StatusCreated)
}
}
func TestClientScopesService_Get(t *testing.T) {
k := client(t)
realm := "first"
createRealm(t, k, realm)
clientScopeID := createClientScope(t, k, realm, "my-client-scope")
clientScopes, res, err := k.ClientScopes.Get(context.Background(), realm, clientScopeID)
if err != nil {
t.Errorf("ClientScopes.Get returned error: %v", err)
}
if res.StatusCode != http.StatusOK {
t.Errorf("got: %d, want: %d", res.StatusCode, http.StatusOK)
}
if *clientScopes.Name != "my-client-scope" {
t.Errorf("got: %s, want: %s", *clientScopes.Name, "my-client-scope")
}
}
func TestClientScopesService_Delete(t *testing.T) {
k := client(t)
realm := "first"
createRealm(t, k, realm)
clientScopeID := createClientScope(t, k, realm, "my-client-scope")
res, err := k.ClientScopes.Delete(context.Background(), realm, clientScopeID)
if err != nil {
t.Errorf("ClientScopes.Delete returned error: %v", err)
}
if res.StatusCode != http.StatusNoContent {
t.Errorf("got: %d, want: %d", res.StatusCode, http.StatusNoContent)
}
}