-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathroleUri_integration_test.go
146 lines (125 loc) · 2.99 KB
/
roleUri_integration_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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// +build integration move to top
package mysqldb
import (
"fmt"
"testing"
odb "github.com/Ulbora/GoAuth2/oauth2database"
lg "github.com/Ulbora/Level_Logger"
db "github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/dbinterface_mysql"
)
var dbroui db.Database
var odbroui odb.Oauth2DB
var cidroui int64
//uil id
var idrouiUidi int64
//role id
var idrouiRoidi int64
var idroui int64
func TestMySQLOauthDBRoleUrii_ConnectAllowURI(t *testing.T) {
var mydb mdb.MyDB
mydb.Host = "localhost:3306"
mydb.User = "admin"
mydb.Password = "admin"
mydb.Database = "ulbora_oauth2_server"
dbroui = &mydb
var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbroui
odbroui = &moadb
dbroui.Connect()
}
func TestMySQLOauthDBRoleUrii_AddClient(t *testing.T) {
var c odb.Client
c.Secret = "12345"
c.Name = "tester"
c.Email = "[email protected]"
c.WebSite = "www.bob.com"
c.Enabled = true
c.Paid = false
fmt.Println("before db add")
res, id := odbroui.AddClient(&c, nil)
fmt.Println("res: ", res)
fmt.Println("id: ", id)
if !res || id == 0 {
t.Fail()
} else {
cidroui = id
}
}
func TestMySQLOauthDBRoleUrii_AddClientAllowedURI(t *testing.T) {
var ur odb.ClientAllowedURI
ur.ClientID = cidroui
ur.URI = "someuri"
res, id := odbroui.AddClientAllowedURI(&ur)
if !res || id <= 0 {
t.Fail()
} else {
idrouiUidi = id
}
}
func TestMySQLOauthDBRoleUrii_AddClientRole(t *testing.T) {
var r odb.ClientRole
r.ClientID = cidroui
r.Role = "someRole"
res, id := odbroui.AddClientRole(&r)
if !res || id <= 0 {
t.Fail()
} else {
idrouiRoidi = id
}
}
func TestMySQLOauthDBRoleUrii_AddClientRoleURI(t *testing.T) {
var r odb.ClientRoleURI
r.ClientAllowedURIID = idrouiUidi
r.ClientRoleID = idrouiRoidi
res := odbroui.AddClientRoleURI(&r)
// fmt.Println("role uri id: ", id)
if !res {
t.Fail()
}
}
func TestMySQLOauthDBRoleUrii_GetClientRoleURIList(t *testing.T) {
res := odbroui.GetClientRoleAllowedURIList(idrouiRoidi)
fmt.Println("Role URI list res: ", res)
if res == nil || (*res)[0].ClientRoleID != idrouiRoidi {
t.Fail()
}
}
func TestMySQLOauthDBRoleUrii_GetClientRoleURIListByClient(t *testing.T) {
res := odbroui.GetClientRoleAllowedURIListByClientID(cidroui)
fmt.Println("Role URI list by client res: ", res)
if res == nil || (*res)[0].ClientRoleID != idrouiRoidi {
t.Fail()
}
}
func TestMySQLOauthDBRoleUrii_DeleteClientRoleURI(t *testing.T) {
var r odb.ClientRoleURI
r.ClientAllowedURIID = idrouiUidi
r.ClientRoleID = idrouiRoidi
res := odbroui.DeleteClientRoleURI(&r)
if !res {
t.Fail()
}
}
func TestMySQLOauthDBRoleUrii_DeleteClientAllowedURI(t *testing.T) {
res := odbroui.DeleteClientAllowedURI(idrouiUidi)
fmt.Println("allowed uri delete: ", res)
if !res {
t.Fail()
}
}
func TestMySQLOauthDBRoleUrii_DeleteClientRole(t *testing.T) {
res := odbroui.DeleteClientRole(idrouiRoidi)
fmt.Println("role delete: ", res)
if !res {
t.Fail()
}
}
func TestMySQLOauthDBRoleUrii_DeleteClient(t *testing.T) {
suc := odbroui.DeleteClient(cidroui)
if !suc {
t.Fail()
}
}