-
Notifications
You must be signed in to change notification settings - Fork 1
/
authui_test.go
115 lines (95 loc) · 3.41 KB
/
authui_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
112
113
114
115
package main
import (
"fmt"
"testing"
"context"
"github.com/Microkubes/authorization-server/app/test"
"github.com/Microkubes/authorization-server/security"
"github.com/Microkubes/microservice-security/auth"
"github.com/Microkubes/microservice-security/oauth2"
"github.com/keitaroinc/goa"
"github.com/gorilla/sessions"
)
func TestConfirmAuthorizationAuthUIBadRequest(t *testing.T) {
service := goa.New("")
sessionStore := &security.SecureSessionStore{
SessionName: "TEST-SESSION",
Store: sessions.NewCookieStore([]byte("something-very-secret")),
}
clientService := &test.DummyClientService{
Auths: map[string]*oauth2.ClientAuth{},
Clients: map[string]*oauth2.Client{},
}
authUIController := NewAuthUIController(service, sessionStore, clientService)
confirmed := true
_, err := test.ConfirmAuthorizationAuthUIBadRequest(t, context.Background(), service, authUIController, &confirmed)
if err != nil {
t.Fatal(err)
}
}
type ErrDummyClientService struct {
*test.DummyClientService
}
func (e *ErrDummyClientService) ConfirmClientAuth(a, b string) (*oauth2.ClientAuth, error) {
return nil, fmt.Errorf("server-error ConfirmClientAuth")
}
func (e *ErrDummyClientService) GetClient(string) (*oauth2.Client, error) {
return nil, fmt.Errorf("server-error GetClient")
}
func TestConfirmAuthorizationAuthUIInternalServerError(t *testing.T) {
service := goa.New("")
sessionStore := test.NewMockSessionStore()
acd := security.AuthorizeClientData{
AuthorizeRequest: "/oauth2/authorize?params=params",
ClientID: "client-001",
Confirmed: true,
}
authObj := auth.Auth{
UserID: "user-001",
Username: "testuser",
Roles: []string{"user"},
}
sessionStore.SetValue("confirmation", acd, nil, nil)
clientService := &ErrDummyClientService{
DummyClientService: &test.DummyClientService{
Auths: map[string]*oauth2.ClientAuth{},
Clients: map[string]*oauth2.Client{},
},
}
authUIController := NewAuthUIController(service, sessionStore, clientService)
confirmed := false
test.ConfirmAuthorizationAuthUIInternalServerError(t, auth.SetAuth(context.Background(), &authObj), service, authUIController, &confirmed)
}
func TestPromptAuthorizationAuthUIBadRequest(t *testing.T) {
service := goa.New("")
sessionStore := test.NewMockSessionStore()
authUIController := NewAuthUIController(service, sessionStore, &test.DummyClientService{
Auths: map[string]*oauth2.ClientAuth{},
Clients: map[string]*oauth2.Client{},
})
test.PromptAuthorizationAuthUIBadRequest(t, context.Background(), service, authUIController)
}
func TestPromptAuthorizationAuthUIInternalServerError(t *testing.T) {
service := goa.New("")
sessionStore := test.NewMockSessionStore()
acd := security.AuthorizeClientData{
AuthorizeRequest: "/oauth2/authorize?params=params",
ClientID: "client-001",
Confirmed: true,
}
authObj := auth.Auth{
UserID: "user-001",
Username: "testuser",
Roles: []string{"user"},
}
sessionStore.SetValue("confirmation", acd, nil, nil)
sessionStore.Set("clientId", "client-001", nil, nil)
clientService := &ErrDummyClientService{
DummyClientService: &test.DummyClientService{
Auths: map[string]*oauth2.ClientAuth{},
Clients: map[string]*oauth2.Client{},
},
}
authUIController := NewAuthUIController(service, sessionStore, clientService)
test.PromptAuthorizationAuthUIInternalServerError(t, auth.SetAuth(context.Background(), &authObj), service, authUIController)
}