@@ -2,107 +2,107 @@ package g8
22
33import "testing"
44
5- func TestAuthorizationService_IsAuthorized (t * testing.T ) {
5+ func TestAuthorizationService_Authorize (t * testing.T ) {
66 authorizationService := NewAuthorizationService ().WithToken ("token" )
7- if ! authorizationService .IsAuthorized ("token" , nil ) {
7+ if _ , authorized := authorizationService .Authorize ("token" , nil ); ! authorized {
88 t .Error ("should've returned true" )
99 }
10- if authorizationService .IsAuthorized ("bad-token" , nil ) {
10+ if _ , authorized := authorizationService .Authorize ("bad-token" , nil ); authorized {
1111 t .Error ("should've returned false" )
1212 }
13- if authorizationService .IsAuthorized ("token" , []string {"admin" }) {
13+ if _ , authorized := authorizationService .Authorize ("token" , []string {"admin" }); authorized {
1414 t .Error ("should've returned false" )
1515 }
16- if authorizationService .IsAuthorized ("" , nil ) {
16+ if _ , authorized := authorizationService .Authorize ("" , nil ); authorized {
1717 t .Error ("should've returned false" )
1818 }
1919}
2020
21- func TestAuthorizationService_IsAuthorizedWithPermissions (t * testing.T ) {
21+ func TestAuthorizationService_AuthorizeWithPermissions (t * testing.T ) {
2222 authorizationService := NewAuthorizationService ().WithClient (NewClient ("token" ).WithPermissions ([]string {"a" , "b" }))
23- if ! authorizationService .IsAuthorized ("token" , nil ) {
23+ if _ , authorized := authorizationService .Authorize ("token" , nil ); ! authorized {
2424 t .Error ("should've returned true" )
2525 }
26- if ! authorizationService .IsAuthorized ("token" , []string {"a" }) {
26+ if _ , authorized := authorizationService .Authorize ("token" , []string {"a" }); ! authorized {
2727 t .Error ("should've returned true" )
2828 }
29- if ! authorizationService .IsAuthorized ("token" , []string {"b" }) {
29+ if _ , authorized := authorizationService .Authorize ("token" , []string {"b" }); ! authorized {
3030 t .Error ("should've returned true" )
3131 }
32- if ! authorizationService .IsAuthorized ("token" , []string {"a" , "b" }) {
32+ if _ , authorized := authorizationService .Authorize ("token" , []string {"a" , "b" }); ! authorized {
3333 t .Error ("should've returned true" )
3434 }
35- if authorizationService .IsAuthorized ("token" , []string {"c" }) {
35+ if _ , authorized := authorizationService .Authorize ("token" , []string {"c" }); authorized {
3636 t .Error ("should've returned false" )
3737 }
38- if authorizationService .IsAuthorized ("token" , []string {"a" , "c" }) {
38+ if _ , authorized := authorizationService .Authorize ("token" , []string {"a" , "c" }); authorized {
3939 t .Error ("should've returned false" )
4040 }
41- if authorizationService .IsAuthorized ("bad-token" , nil ) {
41+ if _ , authorized := authorizationService .Authorize ("bad-token" , nil ); authorized {
4242 t .Error ("should've returned false" )
4343 }
44- if authorizationService .IsAuthorized ("bad-token" , []string {"a" }) {
44+ if _ , authorized := authorizationService .Authorize ("bad-token" , []string {"a" }); authorized {
4545 t .Error ("should've returned false" )
4646 }
47- if authorizationService .IsAuthorized ("" , []string {"a" }) {
47+ if _ , authorized := authorizationService .Authorize ("" , []string {"a" }); authorized {
4848 t .Error ("should've returned false" )
4949 }
5050}
5151
5252func TestAuthorizationService_WithToken (t * testing.T ) {
5353 authorizationService := NewAuthorizationService ().WithToken ("token" )
54- if ! authorizationService .IsAuthorized ("token" , nil ) {
54+ if _ , authorized := authorizationService .Authorize ("token" , nil ); ! authorized {
5555 t .Error ("should've returned true" )
5656 }
57- if authorizationService .IsAuthorized ("bad-token" , nil ) {
57+ if _ , authorized := authorizationService .Authorize ("bad-token" , nil ); authorized {
5858 t .Error ("should've returned false" )
5959 }
60- if authorizationService .IsAuthorized ("token" , []string {"admin" }) {
60+ if _ , authorized := authorizationService .Authorize ("token" , []string {"admin" }); authorized {
6161 t .Error ("should've returned false" )
6262 }
6363}
6464
6565func TestAuthorizationService_WithTokens (t * testing.T ) {
6666 authorizationService := NewAuthorizationService ().WithTokens ([]string {"1" , "2" })
67- if ! authorizationService .IsAuthorized ("1" , nil ) {
67+ if _ , authorized := authorizationService .Authorize ("1" , nil ); ! authorized {
6868 t .Error ("should've returned true" )
6969 }
70- if ! authorizationService .IsAuthorized ("2" , nil ) {
70+ if _ , authorized := authorizationService .Authorize ("2" , nil ); ! authorized {
7171 t .Error ("should've returned true" )
7272 }
73- if authorizationService .IsAuthorized ("3" , nil ) {
73+ if _ , authorized := authorizationService .Authorize ("3" , nil ); authorized {
7474 t .Error ("should've returned false" )
7575 }
7676}
7777
7878func TestAuthorizationService_WithClient (t * testing.T ) {
7979 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 {
8181 t .Error ("should've returned true" )
8282 }
83- if ! authorizationService .IsAuthorized ("token" , []string {"a" }) {
83+ if _ , authorized := authorizationService .Authorize ("token" , []string {"a" }); ! authorized {
8484 t .Error ("should've returned true" )
8585 }
86- if ! authorizationService .IsAuthorized ("token" , []string {"b" }) {
86+ if _ , authorized := authorizationService .Authorize ("token" , []string {"b" }); ! authorized {
8787 t .Error ("should've returned true" )
8888 }
89- if authorizationService .IsAuthorized ("token" , []string {"c" }) {
89+ if _ , authorized := authorizationService .Authorize ("token" , []string {"c" }); authorized {
9090 t .Error ("should've returned false" )
9191 }
9292}
9393
9494func TestAuthorizationService_WithClients (t * testing.T ) {
9595 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 {
9797 t .Error ("should've returned true" )
9898 }
99- if ! authorizationService .IsAuthorized ("2" , []string {"b" }) {
99+ if _ , authorized := authorizationService .Authorize ("2" , []string {"b" }); ! authorized {
100100 t .Error ("should've returned true" )
101101 }
102- if authorizationService .IsAuthorized ("1" , []string {"b" }) {
102+ if _ , authorized := authorizationService .Authorize ("1" , []string {"b" }); authorized {
103103 t .Error ("should've returned false" )
104104 }
105- if authorizationService .IsAuthorized ("2" , []string {"a" }) {
105+ if _ , authorized := authorizationService .Authorize ("2" , []string {"a" }); authorized {
106106 t .Error ("should've returned false" )
107107 }
108108}
0 commit comments