@@ -41,7 +41,7 @@ func TestSuccessfulAddPolicies(t *testing.T) {
4141 permissionsApi := setupAPIWithStore (mockedPermissionsStore )
4242
4343 Convey ("When a POST request is made to the policies endpoint with all the policies properties" , func () {
44- reader := strings .NewReader (`{"entities": ["e1", "e2"], "role": "r1", "conditions ": [ {"attribute": "a1", "operator": "StringEquals", "values": ["v1"]}] }` )
44+ reader := strings .NewReader (`{"entities": ["e1", "e2"], "role": "r1", "condition ": {"attribute": "a1", "operator": "StringEquals", "values": ["v1"]}}` )
4545 request , _ := http .NewRequest ("POST" , "http://localhost:25400/v1/policies" , reader )
4646 responseWriter := httptest .NewRecorder ()
4747 permissionsApi .Router .ServeHTTP (responseWriter , request )
@@ -68,13 +68,13 @@ func TestSuccessfulAddPolicies(t *testing.T) {
6868 So (policy .ID , ShouldEqual , testPolicyID )
6969 So (policy .Role , ShouldResemble , "r1" )
7070 So (policy .Entities , ShouldResemble , []string {"e1" , "e2" })
71- So (policy .Conditions , ShouldResemble , [] models.Condition {
72- { Attribute : "a1" , Values : []string {"v1" }, Operator : models .OperatorStringEquals } },
71+ So (policy .Condition , ShouldResemble , models.Condition {
72+ Attribute : "a1" , Values : []string {"v1" }, Operator : models .OperatorStringEquals },
7373 )
7474 })
7575 })
7676
77- Convey ("When a POST request is made to the policies endpoint without conditions " , func () {
77+ Convey ("When a POST request is made to the policies endpoint without condition " , func () {
7878 reader := strings .NewReader (`{"entities": ["e1"], "role": "r1"}` )
7979 request , _ := http .NewRequest ("POST" , "http://localhost:25400/v1/policies" , reader )
8080 responseWriter := httptest .NewRecorder ()
@@ -102,7 +102,7 @@ func TestSuccessfulAddPolicies(t *testing.T) {
102102 So (policy .ID , ShouldEqual , testPolicyID )
103103 So (policy .Role , ShouldResemble , "r1" )
104104 So (policy .Entities , ShouldResemble , []string {"e1" })
105- So (policy .Conditions , ShouldResemble , [] models.Condition ( nil ) )
105+ So (policy .Condition , ShouldResemble , models.Condition {} )
106106 })
107107 })
108108 })
@@ -155,7 +155,7 @@ func TestFailedAddPoliciesWithInvalidPolicy(t *testing.T) {
155155 Convey ("When a POST request is made to the policies without a role" , t , func () {
156156 permissionsApi := setupAPI ()
157157
158- reader := strings .NewReader (`{"entities": ["e1", "e2"], "conditions ": [ {"attribute": "a1", "operator": "StringEquals", "values": ["v1"]}] }` )
158+ reader := strings .NewReader (`{"entities": ["e1", "e2"], "condition ": {"attribute": "a1", "operator": "StringEquals", "values": ["v1"]}}` )
159159 request , _ := http .NewRequest ("POST" , "http://localhost:25400/v1/policies" , reader )
160160 responseWriter := httptest .NewRecorder ()
161161 permissionsApi .Router .ServeHTTP (responseWriter , request )
@@ -175,7 +175,7 @@ func TestFailedAddPoliciesWithInvalidPolicy(t *testing.T) {
175175 Convey ("When a POST request is made to the policies with empty role" , t , func () {
176176 permissionsApi := setupAPI ()
177177
178- reader := strings .NewReader (`{"entities": ["e1", "e2"], "role": "", "conditions ": [ {"attribute": "a1", "operator": "StringEquals", "values": ["v1"]}] }` )
178+ reader := strings .NewReader (`{"entities": ["e1", "e2"], "role": "", "condition ": {"attribute": "a1", "operator": "StringEquals", "values": ["v1"]}}` )
179179 request , _ := http .NewRequest ("POST" , "http://localhost:25400/v1/policies" , reader )
180180 responseWriter := httptest .NewRecorder ()
181181 permissionsApi .Router .ServeHTTP (responseWriter , request )
@@ -195,15 +195,15 @@ func TestFailedAddPoliciesWithInvalidPolicy(t *testing.T) {
195195 Convey ("When a POST request is made to the policies with an invalid condition operator" , t , func () {
196196 permissionsApi := setupAPI ()
197197
198- reader := strings .NewReader (`{"entities": ["e1", "e2"], "role": "r1", "conditions ": [ {"attribute": "a1", "operator": "And", "values": ["v1"]}] }` )
198+ reader := strings .NewReader (`{"entities": ["e1", "e2"], "role": "r1", "condition ": {"attribute": "a1", "operator": "And", "values": ["v1"]}}` )
199199 request , _ := http .NewRequest ("POST" , "http://localhost:25400/v1/policies" , reader )
200200 responseWriter := httptest .NewRecorder ()
201201 permissionsApi .Router .ServeHTTP (responseWriter , request )
202202
203203 Convey ("Then the response is 400 bad request, with the expected response body" , func () {
204204 So (responseWriter .Code , ShouldEqual , http .StatusBadRequest )
205205 response := responseWriter .Body .String ()
206- So (response , ShouldContainSubstring , "invalid field values: condition operator And " )
206+ So (response , ShouldContainSubstring , "invalid field values: condition operator" )
207207 })
208208 Convey ("Then the request body has been drained" , func () {
209209 bytesRead , err := request .Body .Read (make ([]byte , 1 ))
@@ -301,10 +301,10 @@ func TestGetPolicyHandler(t *testing.T) {
301301 switch id {
302302 case testPolicyID :
303303 return & models.Policy {
304- ID : testPolicyID ,
305- Entities : []string {"e1" , "e2" },
306- Role : "r1" ,
307- Conditions : [] models.Condition {{ Attribute : "al" , Operator : models .OperatorStringEquals , Values : []string {"v1" } }}}, nil
304+ ID : testPolicyID ,
305+ Entities : []string {"e1" , "e2" },
306+ Role : "r1" ,
307+ Condition : models.Condition {Attribute : "al" , Operator : models .OperatorStringEquals , Values : []string {"v1" }}}, nil
308308 case "NOTFOUND" :
309309 return nil , apierrors .ErrPolicyNotFound
310310 default :
@@ -323,10 +323,10 @@ func TestGetPolicyHandler(t *testing.T) {
323323
324324 Convey ("The matched policy is returned with status code 200" , func () {
325325 expectedPolicy := models.Policy {
326- ID : testPolicyID ,
327- Entities : []string {"e1" , "e2" },
328- Role : "r1" ,
329- Conditions : [] models.Condition {{ Attribute : "al" , Operator : models .OperatorStringEquals , Values : []string {"v1" } }}}
326+ ID : testPolicyID ,
327+ Entities : []string {"e1" , "e2" },
328+ Role : "r1" ,
329+ Condition : models.Condition {Attribute : "al" , Operator : models .OperatorStringEquals , Values : []string {"v1" }}}
330330
331331 policy := models.Policy {}
332332 payload , _ := ioutil .ReadAll (responseRecorder .Body )
@@ -378,7 +378,7 @@ func TestSuccessfulUpdatePolicy(t *testing.T) {
378378 permissionsApi := setupAPIWithStore (mockedPermissionsStore )
379379
380380 Convey ("When a PUT request is made to the update policies endpoint to update an existing policy" , func () {
381- reader := strings .NewReader (`{"entities": ["e1", "e2"], "role": "r1", "conditions ": [ {"attribute": "a1", "operator": "StringEquals", "values": ["v1"]}] }` )
381+ reader := strings .NewReader (`{"entities": ["e1", "e2"], "role": "r1", "condition ": {"attribute": "a1", "operator": "StringEquals", "values": ["v1"]}}` )
382382 request , _ := http .NewRequest ("PUT" , "http://localhost:25400/v1/policies/existing_policy" , reader )
383383 responseWriter := httptest .NewRecorder ()
384384 permissionsApi .Router .ServeHTTP (responseWriter , request )
@@ -518,10 +518,10 @@ func TestDeletePolicyHandler(t *testing.T) {
518518 switch id {
519519 case testPolicyID :
520520 return & models.Policy {
521- ID : testPolicyID ,
522- Entities : []string {"e1" , "e2" },
523- Role : "r1" ,
524- Conditions : [] models.Condition {{ Attribute : "al" , Operator : models .OperatorStringEquals , Values : []string {"v1" } }}}, nil
521+ ID : testPolicyID ,
522+ Entities : []string {"e1" , "e2" },
523+ Role : "r1" ,
524+ Condition : models.Condition {Attribute : "al" , Operator : models .OperatorStringEquals , Values : []string {"v1" }}}, nil
525525 case "NOTFOUND" :
526526 return nil , apierrors .ErrPolicyNotFound
527527 default :
0 commit comments