-
-
Notifications
You must be signed in to change notification settings - Fork 936
/
server.go
64 lines (49 loc) · 2.24 KB
/
server.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
package testhelpers
import (
"context"
"testing"
"github.com/gobuffalo/httptest"
"github.com/ory/kratos/driver"
"github.com/ory/kratos/driver/config"
"github.com/ory/kratos/x"
)
func NewKratosServer(t *testing.T, reg driver.Registry) (public, admin *httptest.Server) {
return NewKratosServerWithRouters(t, reg, x.NewRouterPublic(), x.NewRouterAdmin())
}
func NewKratosServerWithCSRF(t *testing.T, reg driver.Registry) (public, admin *httptest.Server) {
rp, ra := x.NewRouterPublic(), x.NewRouterAdmin()
public = httptest.NewServer(x.NewTestCSRFHandler(rp, reg))
admin = httptest.NewServer(ra)
if len(reg.Config(context.Background()).Source().String(config.ViperKeySelfServiceLoginUI)) == 0 {
reg.Config(context.Background()).MustSet(config.ViperKeySelfServiceLoginUI, "http://NewKratosServerWithCSRF/you-forgot-to-set-me/login")
}
reg.Config(context.Background()).MustSet(config.ViperKeyPublicBaseURL, public.URL)
reg.Config(context.Background()).MustSet(config.ViperKeyAdminBaseURL, admin.URL)
reg.RegisterRoutes(context.Background(), rp, ra)
t.Cleanup(public.Close)
t.Cleanup(admin.Close)
return
}
func NewKratosServerWithRouters(t *testing.T, reg driver.Registry, rp *x.RouterPublic, ra *x.RouterAdmin) (public, admin *httptest.Server) {
public = httptest.NewServer(rp)
admin = httptest.NewServer(ra)
InitKratosServers(t, reg, public, admin)
t.Cleanup(public.Close)
t.Cleanup(admin.Close)
return
}
func InitKratosServers(t *testing.T, reg driver.Registry, public, admin *httptest.Server) {
if len(reg.Config(context.Background()).Source().String(config.ViperKeySelfServiceLoginUI)) == 0 {
reg.Config(context.Background()).MustSet(config.ViperKeySelfServiceLoginUI, "http://NewKratosServerWithRouters/you-forgot-to-set-me/login")
}
reg.Config(context.Background()).MustSet(config.ViperKeyPublicBaseURL, public.URL)
reg.Config(context.Background()).MustSet(config.ViperKeyAdminBaseURL, admin.URL)
reg.RegisterRoutes(context.Background(), public.Config.Handler.(*x.RouterPublic), admin.Config.Handler.(*x.RouterAdmin))
}
func NewKratosServers(t *testing.T) (public, admin *httptest.Server) {
public = httptest.NewServer(x.NewRouterPublic())
admin = httptest.NewServer(x.NewRouterAdmin())
t.Cleanup(public.Close)
t.Cleanup(admin.Close)
return
}