-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathauthorizationCode_integration_test.go
209 lines (177 loc) · 4.73 KB
/
authorizationCode_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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// +build integration move to top
package mysqldb
import (
"fmt"
"testing"
"time"
odb "github.com/Ulbora/GoAuth2/oauth2database"
lg "github.com/Ulbora/Level_Logger"
db "github.com/Ulbora/dbinterface"
mdb "github.com/Ulbora/dbinterface_mysql"
)
var dbAci db.Database
var odbAci odb.Oauth2DB
var cidAci int64
var spIDAci int64
var spID2Aci int64
func TestMySQLOauthDBACi_Connect(t *testing.T) {
//var db db.Database
var mydb mdb.MyDB
mydb.Host = "localhost:3306"
mydb.User = "admin"
mydb.Password = "admin"
mydb.Database = "ulbora_oauth2_server"
dbAci = &mydb
var moadb MySQLOauthDB
var l lg.Logger
moadb.Log = &l
moadb.DB = dbAci
odbAci = &moadb
dbAci.Connect()
}
func TestMySQLOauthDBACi_AddClientNullUri(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 := odbAci.AddClient(&c, nil)
fmt.Println("client add res: ", res)
fmt.Println("client id: ", id)
if !res || id == 0 {
t.Fail()
} else {
cidAci = id
}
}
func TestMySQLOauthDBACi_AddAuthorizationCode(t *testing.T) {
var rt odb.RefreshToken
rt.Token = "somereftoken2"
var at odb.AccessToken
at.Token = "someacctoken"
at.Expires = time.Now()
var ac odb.AuthorizationCode
ac.ClientID = cidAci
ac.UserID = "1234"
ac.Expires = time.Now()
ac.RandonAuthCode = "13445a"
res, id := odbAci.AddAuthorizationCode(&ac, &at, &rt, nil)
if !res || id < 1 {
t.Fail()
}
}
// func TestMySQLOauthDBACi_DeleteAuthorizationCodeScope1(t *testing.T) {
// res := odbAci.DeleteAuthorizationCode(cidAci, "1234")
// if !res {
// t.Fail()
// }
// }
func TestMySQLOauthDBACi_AddAuthorizationCodeScope(t *testing.T) {
var rt odb.RefreshToken
rt.Token = "somereftoken2"
var at odb.AccessToken
at.Token = "someacctoken"
at.Expires = time.Now()
var ac odb.AuthorizationCode
ac.ClientID = cidAci
ac.UserID = "1234"
ac.Expires = time.Now()
ac.RandonAuthCode = "13445b"
var scope = []string{"test1", "test2"}
res, id := odbAci.AddAuthorizationCode(&ac, &at, &rt, &scope)
if !res || id < 1 {
t.Fail()
} else {
spID2Aci = id
}
}
func TestMySQLOauthDBACi_GetAuthCodeScopeList(t *testing.T) {
res := odbAci.GetAuthorizationCodeScopeList(spID2Aci)
fmt.Println("auth code scope in get: ", res)
if res == nil || (*res)[0].Scope != "test1" {
t.Fail()
}
}
func TestMySQLOauthDBACi_AddAuthCodeRevolk(t *testing.T) {
var rv odb.AuthCodeRevolk
rv.AuthorizationCode = spID2Aci
res, id := odbAci.AddAuthCodeRevolk(nil, &rv)
fmt.Println("revolk id: ", id)
if !res {
t.Fail()
}
}
func TestMySQLOauthDBACi_UpdateAuthCode(t *testing.T) {
var ac odb.AuthorizationCode
ac.RandonAuthCode = "13445bb"
ac.AlreadyUsed = true
ac.AuthorizationCode = spID2Aci
res := odbAci.UpdateAuthorizationCode(&ac)
if !res {
t.Fail()
}
}
func TestMySQLOauthDBACi_UpdateAuthCodeToken(t *testing.T) {
ac := odbAci.GetAuthorizationCodeByCode("13445bb")
fmt.Println("auth code in update token: ", ac)
var rt odb.RefreshToken
rt.Token = "somereftoken2upd"
rfs, rfid := odbAci.AddRefreshToken(nil, &rt)
fmt.Println("new refresh token: ", rfs)
if rfs {
at := odbAci.GetAccessToken(ac.AccessTokenID)
fmt.Println("at in update token: ", at)
at.Token = "someacctokenupd"
at.Expires = time.Now()
at.RefreshTokenID = rfid
tt := time.Now()
ac.Expires = tt
res := odbAci.UpdateAuthorizationCodeAndToken(ac, at)
fmt.Println("auth code update token suc: ", res)
ac2 := odbAci.GetAuthorizationCodeByCode("13445bb")
fmt.Println("auth2 code in update token: ", ac2)
fmt.Println("tt in update token: ", tt.UTC())
fmt.Println("expires in update token: ", ac2.Expires)
at2 := odbAci.GetAccessToken(ac.AccessTokenID)
fmt.Println("at2 in update token: ", at2)
if !res || at2.Token != "someacctokenupd" {
t.Fail()
}
}
}
func TestMySQLOauthDBACi_GetAuthCodeByCode(t *testing.T) {
res := odbAci.GetAuthorizationCodeByCode("13445bb")
fmt.Println("auth code in get: ", res)
if res == nil || res.RandonAuthCode != "13445bb" || res.AlreadyUsed != true {
t.Fail()
}
}
func TestMySQLOauthDBACi_GetAuthCodeByClient(t *testing.T) {
res := odbAci.GetAuthorizationCode(cidAci, "1234")
fmt.Println("auth code in get by client: ", res)
if len(*res) < 1 {
t.Fail()
}
}
func TestMySQLOauthDBACi_GetAuthCodeByScope(t *testing.T) {
res := odbAci.GetAuthorizationCodeByScope(cidAci, "1234", "test1")
fmt.Println("auth code in get by scope: ", res)
if len(*res) < 1 || (*res)[0].Scope != "test1" {
t.Fail()
}
}
func TestMySQLOauthDBACi_DeleteAuthorizationCode(t *testing.T) {
res := odbAci.DeleteAuthorizationCode(cidAci, "1234")
if !res {
t.Fail()
}
}
func TestMySQLOauthDBACi_DeleteClient(t *testing.T) {
suc := odbAci.DeleteClient(cidAci)
if !suc {
t.Fail()
}
}