Skip to content

Commit fb07f5c

Browse files
Merge branch 'release/0.15.0'
2 parents 11d97a0 + 8f6660e commit fb07f5c

File tree

12 files changed

+91
-115
lines changed

12 files changed

+91
-115
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
# Intellij
1010
.idea/
1111
*.iml
12-
*.iws
12+
*.iws
13+
vendor/

api/policies_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

features/delete_policies.feature

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,30 @@ Feature: Behaviour of application when performing requests against /v1/policies
1111
"entities": [
1212
"group/admin"
1313
],
14-
"conditions": []
14+
"condition": {}
1515
},
1616
{
1717
"id": "publisher",
1818
"role": "publisher",
1919
"entities": [
2020
"group/publisher"
2121
],
22-
"conditions": []
22+
"condition": {}
2323
},
2424
{
2525
"id": "viewer",
2626
"role": "viewer",
2727
"entities": [
2828
"group/viewer"
2929
],
30-
"conditions": [
31-
{
30+
"condition": {
3231
"operator": "StringEquals",
3332
"attribute": "collection-id",
3433
"values": [
3534
"collection-765"
3635
]
3736
}
38-
]
37+
3938
}
4039
]
4140
"""

features/get_permissions_bundle.feature

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,29 @@ Feature: GET /v1/permissions-bundle endpoint
3636
"entities": [
3737
"group/admin"
3838
],
39-
"conditions": []
39+
"condition": {}
4040
},
4141
{
4242
"id": "publisher",
4343
"role": "publisher",
4444
"entities": [
4545
"group/publisher"
4646
],
47-
"conditions": []
47+
"condition": {}
4848
},
4949
{
5050
"id": "viewer",
5151
"role": "viewer",
5252
"entities": [
5353
"group/viewer"
5454
],
55-
"conditions": [
56-
{
55+
"condition": {
5756
"operator": "StringEquals",
5857
"attribute": "collection-id",
5958
"values": [
6059
"collection-765"
6160
]
62-
}
63-
]
61+
}
6462
}
6563
]
6664
"""
@@ -86,15 +84,13 @@ Feature: GET /v1/permissions-bundle endpoint
8684
"group/viewer": [
8785
{
8886
"id": "viewer",
89-
"conditions": [
90-
{
87+
"condition":{
9188
"attribute": "collection-id",
9289
"operator": "StringEquals",
9390
"values": [
9491
"collection-765"
9592
]
96-
}
97-
]
93+
}
9894
}
9995
]
10096
},

features/get_policies.feature

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,29 @@ Feature: Behaviour of application when performing requests against /v1/policies
1111
"entities": [
1212
"group/admin"
1313
],
14-
"conditions": []
14+
"condition": {}
1515
},
1616
{
1717
"id": "publisher",
1818
"role": "publisher",
1919
"entities": [
2020
"group/publisher"
2121
],
22-
"conditions": []
22+
"condition": {}
2323
},
2424
{
2525
"id": "viewer",
2626
"role": "viewer",
2727
"entities": [
2828
"group/viewer"
2929
],
30-
"conditions": [
31-
{
30+
"condition": {
3231
"operator": "StringEquals",
3332
"attribute": "collection-id",
3433
"values": [
3534
"collection-765"
3635
]
37-
}
38-
]
36+
}
3937
}
4038
]
4139
"""
@@ -74,15 +72,13 @@ Feature: Behaviour of application when performing requests against /v1/policies
7472
"entities": [
7573
"group/viewer"
7674
],
77-
"conditions": [
78-
{
75+
"condition":{
7976
"operator": "StringEquals",
8077
"attribute": "collection-id",
8178
"values": [
8279
"collection-765"
8380
]
84-
}
85-
]
81+
}
8682
}
8783
"""
8884

features/post_policies.feature

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
1010
"e2"
1111
],
1212
"role": "r1",
13-
"conditions": [
14-
{
13+
"condition": {
1514
"attribute": "a1",
1615
"operator": "StringEquals",
1716
"values": [
1817
"v1"
1918
]
20-
}
21-
]
19+
}
2220
}
2321
"""
2422
Then the HTTP status code should be "201"
@@ -43,15 +41,13 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
4341
"""
4442
{
4543
"role": "r1",
46-
"conditions": [
47-
{
44+
"condition": {
4845
"attribute": "a1",
4946
"operator": "StringEquals",
5047
"values": [
5148
"v1"
5249
]
53-
}
54-
]
50+
}
5551
}
5652
"""
5753
Then the HTTP status code should be "400"
@@ -63,15 +59,13 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
6359
{
6460
"entities": [],
6561
"role": "r1",
66-
"conditions": [
67-
{
62+
"condition":{
6863
"attribute": "a1",
6964
"operator": "StringEquals",
7065
"values": [
7166
"v1"
7267
]
73-
}
74-
]
68+
}
7569
}
7670
"""
7771
Then the HTTP status code should be "400"
@@ -85,15 +79,13 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
8579
"e1",
8680
"e2"
8781
],
88-
"conditions": [
89-
{
82+
"condition": {
9083
"attribute": "a1",
9184
"operator": "StringEquals",
9285
"values": [
9386
"v1"
9487
]
95-
}
96-
]
88+
}
9789
}
9890
"""
9991
Then the HTTP status code should be "400"
@@ -105,15 +97,13 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
10597
{
10698
"entities": ["e1"],
10799
"role": "",
108-
"conditions": [
109-
{
100+
"condition": {
110101
"attribute": "a1",
111102
"operator": "StringEquals",
112103
"values": [
113104
"v1"
114105
]
115-
}
116-
]
106+
}
117107
}
118108
"""
119109
Then the HTTP status code should be "400"
@@ -125,15 +115,13 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
125115
{
126116
"entities": ["e1"],
127117
"role": "",
128-
"conditions": [
129-
{
118+
"condition": {
130119
"attribute": "a1",
131120
"operator": "StringEquals",
132121
"values": [
133122
"v1"
134123
]
135-
}
136-
]
124+
}
137125
}
138126
"""
139127
Then the HTTP status code should be "403"

0 commit comments

Comments
 (0)