-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
manager_test.go
93 lines (75 loc) · 1.87 KB
/
manager_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
package group_test
import (
"log"
"net/http/httptest"
"net/url"
"os"
"testing"
"fmt"
"github.com/julienschmidt/httprouter"
_ "github.com/lib/pq"
"github.com/ory/fosite"
"github.com/ory/herodot"
"github.com/ory/hydra/compose"
"github.com/ory/hydra/integration"
. "github.com/ory/hydra/warden/group"
"github.com/ory/ladon"
)
var clientManagers = map[string]Manager{}
var ts *httptest.Server
func init() {
clientManagers["memory"] = &MemoryManager{
Groups: map[string]Group{},
}
localWarden, httpClient := compose.NewMockFirewall("foo", "alice", fosite.Arguments{Scope}, &ladon.DefaultPolicy{
ID: "1",
Subjects: []string{"alice"},
Resources: []string{"rn:hydra:warden<.*>"},
Actions: []string{"create", "get", "delete", "update", "members.add", "members.remove"},
Effect: ladon.AllowAccess,
})
s := &Handler{
Manager: &MemoryManager{
Groups: map[string]Group{},
},
H: herodot.NewJSONWriter(nil),
W: localWarden,
}
routing := httprouter.New()
s.SetRoutes(routing)
ts = httptest.NewServer(routing)
u, _ := url.Parse(ts.URL + GroupsHandlerPath)
clientManagers["http"] = &HTTPManager{
Client: httpClient,
Endpoint: u,
}
}
func TestMain(m *testing.M) {
connectToPG()
connectToMySQL()
s := m.Run()
integration.KillAll()
os.Exit(s)
}
func connectToMySQL() {
var db = integration.ConnectToMySQL()
s := &SQLManager{DB: db}
if _, err := s.CreateSchemas(); err != nil {
log.Fatalf("Could not create postgres schema: %v", err)
}
clientManagers["mysql"] = s
}
func connectToPG() {
var db = integration.ConnectToPostgres()
s := &SQLManager{DB: db}
if _, err := s.CreateSchemas(); err != nil {
log.Fatalf("Could not create postgres schema: %v", err)
}
clientManagers["postgres"] = s
}
func TestManagers(t *testing.T) {
t.Parallel()
for k, m := range clientManagers {
t.Run(fmt.Sprintf("case=%s", k), TestHelperManagers(m))
}
}