@@ -2,107 +2,107 @@ package g8
2
2
3
3
import "testing"
4
4
5
- func TestAuthorizationService_IsAuthorized (t * testing.T ) {
5
+ func TestAuthorizationService_Authorize (t * testing.T ) {
6
6
authorizationService := NewAuthorizationService ().WithToken ("token" )
7
- if ! authorizationService .IsAuthorized ("token" , nil ) {
7
+ if _ , authorized := authorizationService .Authorize ("token" , nil ); ! authorized {
8
8
t .Error ("should've returned true" )
9
9
}
10
- if authorizationService .IsAuthorized ("bad-token" , nil ) {
10
+ if _ , authorized := authorizationService .Authorize ("bad-token" , nil ); authorized {
11
11
t .Error ("should've returned false" )
12
12
}
13
- if authorizationService .IsAuthorized ("token" , []string {"admin" }) {
13
+ if _ , authorized := authorizationService .Authorize ("token" , []string {"admin" }); authorized {
14
14
t .Error ("should've returned false" )
15
15
}
16
- if authorizationService .IsAuthorized ("" , nil ) {
16
+ if _ , authorized := authorizationService .Authorize ("" , nil ); authorized {
17
17
t .Error ("should've returned false" )
18
18
}
19
19
}
20
20
21
- func TestAuthorizationService_IsAuthorizedWithPermissions (t * testing.T ) {
21
+ func TestAuthorizationService_AuthorizeWithPermissions (t * testing.T ) {
22
22
authorizationService := NewAuthorizationService ().WithClient (NewClient ("token" ).WithPermissions ([]string {"a" , "b" }))
23
- if ! authorizationService .IsAuthorized ("token" , nil ) {
23
+ if _ , authorized := authorizationService .Authorize ("token" , nil ); ! authorized {
24
24
t .Error ("should've returned true" )
25
25
}
26
- if ! authorizationService .IsAuthorized ("token" , []string {"a" }) {
26
+ if _ , authorized := authorizationService .Authorize ("token" , []string {"a" }); ! authorized {
27
27
t .Error ("should've returned true" )
28
28
}
29
- if ! authorizationService .IsAuthorized ("token" , []string {"b" }) {
29
+ if _ , authorized := authorizationService .Authorize ("token" , []string {"b" }); ! authorized {
30
30
t .Error ("should've returned true" )
31
31
}
32
- if ! authorizationService .IsAuthorized ("token" , []string {"a" , "b" }) {
32
+ if _ , authorized := authorizationService .Authorize ("token" , []string {"a" , "b" }); ! authorized {
33
33
t .Error ("should've returned true" )
34
34
}
35
- if authorizationService .IsAuthorized ("token" , []string {"c" }) {
35
+ if _ , authorized := authorizationService .Authorize ("token" , []string {"c" }); authorized {
36
36
t .Error ("should've returned false" )
37
37
}
38
- if authorizationService .IsAuthorized ("token" , []string {"a" , "c" }) {
38
+ if _ , authorized := authorizationService .Authorize ("token" , []string {"a" , "c" }); authorized {
39
39
t .Error ("should've returned false" )
40
40
}
41
- if authorizationService .IsAuthorized ("bad-token" , nil ) {
41
+ if _ , authorized := authorizationService .Authorize ("bad-token" , nil ); authorized {
42
42
t .Error ("should've returned false" )
43
43
}
44
- if authorizationService .IsAuthorized ("bad-token" , []string {"a" }) {
44
+ if _ , authorized := authorizationService .Authorize ("bad-token" , []string {"a" }); authorized {
45
45
t .Error ("should've returned false" )
46
46
}
47
- if authorizationService .IsAuthorized ("" , []string {"a" }) {
47
+ if _ , authorized := authorizationService .Authorize ("" , []string {"a" }); authorized {
48
48
t .Error ("should've returned false" )
49
49
}
50
50
}
51
51
52
52
func TestAuthorizationService_WithToken (t * testing.T ) {
53
53
authorizationService := NewAuthorizationService ().WithToken ("token" )
54
- if ! authorizationService .IsAuthorized ("token" , nil ) {
54
+ if _ , authorized := authorizationService .Authorize ("token" , nil ); ! authorized {
55
55
t .Error ("should've returned true" )
56
56
}
57
- if authorizationService .IsAuthorized ("bad-token" , nil ) {
57
+ if _ , authorized := authorizationService .Authorize ("bad-token" , nil ); authorized {
58
58
t .Error ("should've returned false" )
59
59
}
60
- if authorizationService .IsAuthorized ("token" , []string {"admin" }) {
60
+ if _ , authorized := authorizationService .Authorize ("token" , []string {"admin" }); authorized {
61
61
t .Error ("should've returned false" )
62
62
}
63
63
}
64
64
65
65
func TestAuthorizationService_WithTokens (t * testing.T ) {
66
66
authorizationService := NewAuthorizationService ().WithTokens ([]string {"1" , "2" })
67
- if ! authorizationService .IsAuthorized ("1" , nil ) {
67
+ if _ , authorized := authorizationService .Authorize ("1" , nil ); ! authorized {
68
68
t .Error ("should've returned true" )
69
69
}
70
- if ! authorizationService .IsAuthorized ("2" , nil ) {
70
+ if _ , authorized := authorizationService .Authorize ("2" , nil ); ! authorized {
71
71
t .Error ("should've returned true" )
72
72
}
73
- if authorizationService .IsAuthorized ("3" , nil ) {
73
+ if _ , authorized := authorizationService .Authorize ("3" , nil ); authorized {
74
74
t .Error ("should've returned false" )
75
75
}
76
76
}
77
77
78
78
func TestAuthorizationService_WithClient (t * testing.T ) {
79
79
authorizationService := NewAuthorizationService ().WithClient (NewClient ("token" ).WithPermissions ([]string {"a" , "b" }))
80
- if ! authorizationService .IsAuthorized ("token" , []string {"a" , "b" }) {
80
+ if _ , authorized := authorizationService .Authorize ("token" , []string {"a" , "b" }); ! authorized {
81
81
t .Error ("should've returned true" )
82
82
}
83
- if ! authorizationService .IsAuthorized ("token" , []string {"a" }) {
83
+ if _ , authorized := authorizationService .Authorize ("token" , []string {"a" }); ! authorized {
84
84
t .Error ("should've returned true" )
85
85
}
86
- if ! authorizationService .IsAuthorized ("token" , []string {"b" }) {
86
+ if _ , authorized := authorizationService .Authorize ("token" , []string {"b" }); ! authorized {
87
87
t .Error ("should've returned true" )
88
88
}
89
- if authorizationService .IsAuthorized ("token" , []string {"c" }) {
89
+ if _ , authorized := authorizationService .Authorize ("token" , []string {"c" }); authorized {
90
90
t .Error ("should've returned false" )
91
91
}
92
92
}
93
93
94
94
func TestAuthorizationService_WithClients (t * testing.T ) {
95
95
authorizationService := NewAuthorizationService ().WithClients ([]* Client {NewClient ("1" ).WithPermission ("a" ), NewClient ("2" ).WithPermission ("b" )})
96
- if ! authorizationService .IsAuthorized ("1" , []string {"a" }) {
96
+ if _ , authorized := authorizationService .Authorize ("1" , []string {"a" }); ! authorized {
97
97
t .Error ("should've returned true" )
98
98
}
99
- if ! authorizationService .IsAuthorized ("2" , []string {"b" }) {
99
+ if _ , authorized := authorizationService .Authorize ("2" , []string {"b" }); ! authorized {
100
100
t .Error ("should've returned true" )
101
101
}
102
- if authorizationService .IsAuthorized ("1" , []string {"b" }) {
102
+ if _ , authorized := authorizationService .Authorize ("1" , []string {"b" }); authorized {
103
103
t .Error ("should've returned false" )
104
104
}
105
- if authorizationService .IsAuthorized ("2" , []string {"a" }) {
105
+ if _ , authorized := authorizationService .Authorize ("2" , []string {"a" }); authorized {
106
106
t .Error ("should've returned false" )
107
107
}
108
108
}
0 commit comments