@@ -8,9 +8,9 @@ public class AuthorizationTests
8
8
public void Field ( )
9
9
{
10
10
var field = new FieldType ( ) ;
11
- field . RequiresAuthorization ( ) . ShouldBeFalse ( ) ;
11
+ field . IsAuthorizationRequired ( ) . ShouldBeFalse ( ) ;
12
12
field . AuthorizeWith ( "Policy1" ) ;
13
- field . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
13
+ field . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
14
14
field . AuthorizeWith ( "Policy2" ) ;
15
15
field . AuthorizeWith ( "Policy2" ) ;
16
16
field . AuthorizeWithPolicy ( "Policy3" ) ;
@@ -20,7 +20,7 @@ public void Field()
20
20
field . AuthorizeWithRoles ( "Role1" , "Role4" ) ;
21
21
field . AuthorizeWithRoles ( "" ) ;
22
22
23
- field . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
23
+ field . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
24
24
field . GetPolicies ( ) . ShouldBe ( new string [ ] { "Policy1" , "Policy2" , "Policy3" } ) ;
25
25
field . GetRoles ( ) . ShouldBe ( new string [ ] { "Role1" , "Role2" , "Role3" , "Role4" } ) ;
26
26
}
@@ -33,16 +33,25 @@ public void NoRoles()
33
33
field . AuthorizeWithRoles ( "" ) ;
34
34
field . AuthorizeWithRoles ( " " ) ;
35
35
field . AuthorizeWithRoles ( "," ) ;
36
- field . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
36
+ field . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
37
+ }
38
+
39
+ [ Fact ]
40
+ public void AllowAnonymous ( )
41
+ {
42
+ var field = new FieldType ( ) ;
43
+ field . IsAnonymousAllowed ( ) . ShouldBeFalse ( ) ;
44
+ field . AllowAnonymous ( ) ;
45
+ field . IsAnonymousAllowed ( ) . ShouldBeTrue ( ) ;
37
46
}
38
47
39
48
[ Fact ]
40
49
public void Authorize ( )
41
50
{
42
51
var field = new FieldType ( ) ;
43
- field . RequiresAuthorization ( ) . ShouldBeFalse ( ) ;
52
+ field . IsAuthorizationRequired ( ) . ShouldBeFalse ( ) ;
44
53
field . Authorize ( ) ;
45
- field . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
54
+ field . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
46
55
}
47
56
48
57
[ Fact ]
@@ -60,7 +69,7 @@ public void FieldBuilder()
60
69
. AuthorizeWithRoles ( "Role1" , "Role4" ) ;
61
70
62
71
var field = graph . Fields . Find ( "Field" ) ;
63
- field . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
72
+ field . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
64
73
field . GetPolicies ( ) . ShouldBe ( new string [ ] { "Policy1" , "Policy2" , "Policy3" } ) ;
65
74
field . GetRoles ( ) . ShouldBe ( new string [ ] { "Role1" , "Role2" , "Role3" , "Role4" } ) ;
66
75
}
@@ -81,7 +90,7 @@ public void ConnectionBuilder()
81
90
. AuthorizeWithRoles ( "Role1" , "Role4" ) ;
82
91
83
92
var field = graph . Fields . Find ( "Field" ) ;
84
- field . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
93
+ field . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
85
94
field . GetPolicies ( ) . ShouldBe ( new string [ ] { "Policy1" , "Policy2" , "Policy3" } ) ;
86
95
field . GetRoles ( ) . ShouldBe ( new string [ ] { "Role1" , "Role2" , "Role3" , "Role4" } ) ;
87
96
}
@@ -90,19 +99,26 @@ public void ConnectionBuilder()
90
99
public void AutoOutputGraphType ( )
91
100
{
92
101
var graph = new AutoRegisteringObjectGraphType < Class1 > ( ) ;
93
- graph . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
102
+ graph . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
103
+ graph . IsAnonymousAllowed ( ) . ShouldBeFalse ( ) ;
94
104
graph . GetPolicies ( ) . ShouldBe ( new string [ ] { "Policy1" , "Policy2" , "Policy3" } ) ;
95
105
graph . GetRoles ( ) . ShouldBe ( new string [ ] { "Role1" , "Role2" , "Role3" } ) ;
96
106
97
- graph . Fields . Find ( "Id" ) . RequiresAuthorization ( ) . ShouldBeFalse ( ) ;
107
+ graph . Fields . Find ( "Id" ) . IsAuthorizationRequired ( ) . ShouldBeFalse ( ) ;
98
108
99
109
var field = graph . Fields . Find ( "Name" ) ;
100
- field . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
110
+ field . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
111
+ field . IsAnonymousAllowed ( ) . ShouldBeFalse ( ) ;
101
112
field . GetPolicies ( ) . ShouldBe ( new string [ ] { "Policy1" , "Policy2" , "Policy3" } ) ;
102
113
field . GetRoles ( ) . ShouldBe ( new string [ ] { "Role1" , "Role2" , "Role3" } ) ;
103
114
104
115
field = graph . Fields . Find ( "Value" ) ;
105
- field . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
116
+ field . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
117
+ field . IsAnonymousAllowed ( ) . ShouldBeFalse ( ) ;
118
+
119
+ field = graph . Fields . Find ( "Public" ) ;
120
+ field . IsAuthorizationRequired ( ) . ShouldBeFalse ( ) ;
121
+ field . IsAnonymousAllowed ( ) . ShouldBeTrue ( ) ;
106
122
}
107
123
108
124
[ Fact ]
@@ -114,23 +130,31 @@ type Class1 {
114
130
id: String!
115
131
name: String!
116
132
value: String!
133
+ public: String!
117
134
}" ,
118
135
configure => configure . Types . Include < Class1 > ( ) ) ;
119
136
120
137
var graph = ( ObjectGraphType ) schema . AllTypes [ "Class1" ] ;
121
- graph . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
138
+ graph . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
139
+ graph . IsAnonymousAllowed ( ) . ShouldBeFalse ( ) ;
122
140
graph . GetPolicies ( ) . ShouldBe ( new string [ ] { "Policy1" , "Policy2" , "Policy3" } ) ;
123
141
graph . GetRoles ( ) . ShouldBe ( new string [ ] { "Role1" , "Role2" , "Role3" } ) ;
124
142
125
- graph . Fields . Find ( "id" ) . RequiresAuthorization ( ) . ShouldBeFalse ( ) ;
143
+ graph . Fields . Find ( "id" ) . IsAuthorizationRequired ( ) . ShouldBeFalse ( ) ;
126
144
127
145
var field = graph . Fields . Find ( "name" ) ;
128
- field . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
146
+ field . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
147
+ field . IsAnonymousAllowed ( ) . ShouldBeFalse ( ) ;
129
148
field . GetPolicies ( ) . ShouldBe ( new string [ ] { "Policy1" , "Policy2" , "Policy3" } ) ;
130
149
field . GetRoles ( ) . ShouldBe ( new string [ ] { "Role1" , "Role2" , "Role3" } ) ;
131
150
132
151
field = graph . Fields . Find ( "value" ) ;
133
- field . RequiresAuthorization ( ) . ShouldBeTrue ( ) ;
152
+ field . IsAuthorizationRequired ( ) . ShouldBeTrue ( ) ;
153
+ field . IsAnonymousAllowed ( ) . ShouldBeFalse ( ) ;
154
+
155
+ field = graph . Fields . Find ( "public" ) ;
156
+ field . IsAuthorizationRequired ( ) . ShouldBeFalse ( ) ;
157
+ field . IsAnonymousAllowed ( ) . ShouldBeTrue ( ) ;
134
158
}
135
159
136
160
[ Authorize ( "Policy1" ) ]
@@ -151,5 +175,7 @@ private class Class1
151
175
public string Name { get ; set ; }
152
176
[ Authorize ]
153
177
public string Value { get ; set ; }
178
+ [ AllowAnonymous ]
179
+ public string Public { get ; set ; }
154
180
}
155
181
}
0 commit comments