Skip to content

Commit efcdeed

Browse files
committed
Merge branch 'release/0.13.0'
2 parents c2927fb + 6ff1084 commit efcdeed

File tree

14 files changed

+186
-441
lines changed

14 files changed

+186
-441
lines changed

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,34 @@ API for managing access control permissions for Digital Publishing API resources
1313

1414
### Configuration
1515

16-
| Environment variable | Default | Description
17-
| ---------------------------- | --------- | -----------
18-
| BIND_ADDR | :25400 | The host and port to bind to
19-
| GRACEFUL_SHUTDOWN_TIMEOUT | 5s | The graceful shutdown timeout in seconds (`time.Duration` format)
20-
| HEALTHCHECK_INTERVAL | 30s | Time between self-healthchecks (`time.Duration` format)
21-
| HEALTHCHECK_CRITICAL_TIMEOUT | 90s | Time to wait until an unhealthy dependent propagates its state to make this app unhealthy (`time.Duration` format)
22-
| MOGODB_BIND_ADDR | localhost:27017 | The MongoDB bind address
23-
| MONGODB_PERMISSIONS_DATABASE | permissions | The MongoDB permissions database
24-
| MONGODB_ROLES_COLLECTION | roles | The MongoDB roles collection
25-
| MONGODB_POLICIES_COLLECTION | policies | The MongoDB policies collection
26-
| DEFAULT_LIMIT | 20 | Default limit for pagination
27-
| DEFAULT_OFFSET | 0 | Default offset for pagination
28-
| DEFAULT_MAXIMUM_LIMIT | 1000 | Default maximum limit for pagination
16+
| Environment variable | Default | Description |
17+
|--------------------------------|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
18+
| BIND_ADDR | :25400 | The host and port to bind to |
19+
| GRACEFUL_SHUTDOWN_TIMEOUT | 5s | The graceful shutdown timeout in seconds (`time.Duration` format) |
20+
| HEALTHCHECK_INTERVAL | 30s | Time between self-healthchecks (`time.Duration` format) |
21+
| HEALTHCHECK_CRITICAL_TIMEOUT | 90s | Time to wait until an unhealthy dependent propagates its state to make this app unhealthy (`time.Duration` format) |
22+
| MONGODB_BIND_ADDR | localhost:27017 | The MongoDB bind address |
23+
| MONGODB_USERNAME | | The MongoDB Username |
24+
| MONGODB_PASSWORD | | The MongoDB Password |
25+
| MONGODB_DATABASE | permissions | The MongoDB database |
26+
| MONGODB_COLLECTIONS | RolesCollection:roles, PoliciesCollection:policies | The MongoDB collections |
27+
| MONGODB_REPLICA_SET | | The name of the MongoDB replica set |
28+
| MONGODB_ENABLE_READ_CONCERN | false | Switch to use (or not) majority read concern |
29+
| MONGODB_ENABLE_WRITE_CONCERN | true | Switch to use (or not) majority write concern |
30+
| MONGODB_CONNECT_TIMEOUT | 5s | The timeout when connecting to MongoDB (`time.Duration` format) |
31+
| MONGODB_QUERY_TIMEOUT | 15s | The timeout for querying MongoDB (`time.Duration` format) |
32+
| MONGODB_IS_SSL | false | Switch to use (or not) TLS when connecting to mongodb |
33+
| DEFAULT_LIMIT | 20 | Default limit for pagination |
34+
| DEFAULT_OFFSET | 0 | Default offset for pagination |
35+
| DEFAULT_MAXIMUM_LIMIT | 1000 | Default maximum limit for pagination |
2936

3037
### Contributing
3138

3239
See [CONTRIBUTING](CONTRIBUTING.md) for details.
3340

3441
### License
3542

36-
Copyright © 2021, Office for National Statistics (https://www.ons.gov.uk)
43+
Copyright © 2022, Office for National Statistics (https://www.ons.gov.uk)
3744

3845
Released under MIT license, see [LICENSE](LICENSE.md) for details.
3946

api/policies_test.go

Lines changed: 9 additions & 9 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": [{"attributes": ["a1"], "operator": "StringEquals", "values": ["v1"]}]}`)
44+
reader := strings.NewReader(`{"entities": ["e1", "e2"], "role": "r1", "conditions": [{"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)
@@ -69,7 +69,7 @@ func TestSuccessfulAddPolicies(t *testing.T) {
6969
So(policy.Role, ShouldResemble, "r1")
7070
So(policy.Entities, ShouldResemble, []string{"e1", "e2"})
7171
So(policy.Conditions, ShouldResemble, []models.Condition{
72-
{Attributes: []string{"a1"}, Values: []string{"v1"}, Operator: models.OperatorStringEquals}},
72+
{Attribute: "a1", Values: []string{"v1"}, Operator: models.OperatorStringEquals}},
7373
)
7474
})
7575
})
@@ -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": [{"attributes": ["a1"], "operator": "StringEquals", "values": ["v1"]}]}`)
158+
reader := strings.NewReader(`{"entities": ["e1", "e2"], "conditions": [{"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": [{"attributes": ["a1"], "operator": "StringEquals", "values": ["v1"]}]}`)
178+
reader := strings.NewReader(`{"entities": ["e1", "e2"], "role": "", "conditions": [{"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,7 +195,7 @@ 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": [{"attributes": ["a1"], "operator": "And", "values": ["v1"]}]}`)
198+
reader := strings.NewReader(`{"entities": ["e1", "e2"], "role": "r1", "conditions": [{"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)
@@ -304,7 +304,7 @@ func TestGetPolicyHandler(t *testing.T) {
304304
ID: testPolicyID,
305305
Entities: []string{"e1", "e2"},
306306
Role: "r1",
307-
Conditions: []models.Condition{{Attributes: []string{"al"}, Operator: models.OperatorStringEquals, Values: []string{"v1"}}}}, nil
307+
Conditions: []models.Condition{{Attribute: "al", Operator: models.OperatorStringEquals, Values: []string{"v1"}}}}, nil
308308
case "NOTFOUND":
309309
return nil, apierrors.ErrPolicyNotFound
310310
default:
@@ -326,7 +326,7 @@ func TestGetPolicyHandler(t *testing.T) {
326326
ID: testPolicyID,
327327
Entities: []string{"e1", "e2"},
328328
Role: "r1",
329-
Conditions: []models.Condition{{Attributes: []string{"al"}, Operator: models.OperatorStringEquals, Values: []string{"v1"}}}}
329+
Conditions: []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": [{"attributes": ["a1"], "operator": "StringEquals", "values": ["v1"]}]}`)
381+
reader := strings.NewReader(`{"entities": ["e1", "e2"], "role": "r1", "conditions": [{"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)
@@ -521,7 +521,7 @@ func TestDeletePolicyHandler(t *testing.T) {
521521
ID: testPolicyID,
522522
Entities: []string{"e1", "e2"},
523523
Role: "r1",
524-
Conditions: []models.Condition{{Attributes: []string{"al"}, Operator: models.OperatorStringEquals, Values: []string{"v1"}}}}, nil
524+
Conditions: []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: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ Feature: Behaviour of application when performing requests against /v1/policies
3030
"conditions": [
3131
{
3232
"operator": "StringEquals",
33-
"attributes": [
34-
"collection-id"
35-
],
33+
"attribute": "collection-id",
3634
"values": [
3735
"collection-765"
3836
]
@@ -47,10 +45,10 @@ Feature: Behaviour of application when performing requests against /v1/policies
4745
When I DELETE "/v1/policies/publisher"
4846
Then the HTTP status code should be "204"
4947

50-
Scenario: [Test #2] DELETE /v1/policies/publisher with invalid JWT token in header - the response status is 403 (forbidden)
48+
Scenario: [Test #2] DELETE /v1/policies/publisher with invalid JWT token in header - the response status is 401
5149
Given I am a publisher user with invalid auth token
5250
When I DELETE "/v1/policies/publisher"
53-
Then the HTTP status code should be "403"
51+
Then the HTTP status code should be "401"
5452

5553
Scenario: [Test #3] DELETE /v1/policies/viewer to fetch a policy having all parameters
5654
Given I am a viewer user

features/get_permissions_bundle.feature

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ Feature: GET /v1/permissions-bundle endpoint
5555
"conditions": [
5656
{
5757
"operator": "StringEquals",
58-
"attributes": [
59-
"collection-id"
60-
],
58+
"attribute": "collection-id",
6159
"values": [
6260
"collection-765"
6361
]
@@ -90,9 +88,7 @@ Feature: GET /v1/permissions-bundle endpoint
9088
"id": "viewer",
9189
"conditions": [
9290
{
93-
"attributes": [
94-
"collection-id"
95-
],
91+
"attribute": "collection-id",
9692
"operator": "StringEquals",
9793
"values": [
9894
"collection-765"

features/get_policies.feature

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ Feature: Behaviour of application when performing requests against /v1/policies
3030
"conditions": [
3131
{
3232
"operator": "StringEquals",
33-
"attributes": [
34-
"collection-id"
35-
],
33+
"attribute": "collection-id",
3634
"values": [
3735
"collection-765"
3836
]
@@ -58,10 +56,10 @@ Feature: Behaviour of application when performing requests against /v1/policies
5856
}
5957
"""
6058

61-
Scenario: [Test #2] GET /v1/policies/publisher with invalid JWT token in header - the response status is 403 (forbidden)
59+
Scenario: [Test #2] GET /v1/policies/publisher with invalid JWT token in header - the response status is 401
6260
Given I am a publisher user with invalid auth token
6361
When I GET "/v1/policies/publisher"
64-
Then the HTTP status code should be "403"
62+
Then the HTTP status code should be "401"
6563

6664
Scenario: [Test #3] GET /v1/policies/viewer to fetch a policy having all parameters
6765
Given I am a viewer user
@@ -79,9 +77,7 @@ Feature: Behaviour of application when performing requests against /v1/policies
7977
"conditions": [
8078
{
8179
"operator": "StringEquals",
82-
"attributes": [
83-
"collection-id"
84-
],
80+
"attribute": "collection-id",
8581
"values": [
8682
"collection-765"
8783
]

features/post_policies.feature

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
1212
"role": "r1",
1313
"conditions": [
1414
{
15-
"attributes": [
16-
"a1"
17-
],
15+
"attribute": "a1",
1816
"operator": "StringEquals",
1917
"values": [
2018
"v1"
@@ -47,9 +45,7 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
4745
"role": "r1",
4846
"conditions": [
4947
{
50-
"attributes": [
51-
"a1"
52-
],
48+
"attribute": "a1",
5349
"operator": "StringEquals",
5450
"values": [
5551
"v1"
@@ -69,9 +65,7 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
6965
"role": "r1",
7066
"conditions": [
7167
{
72-
"attributes": [
73-
"a1"
74-
],
68+
"attribute": "a1",
7569
"operator": "StringEquals",
7670
"values": [
7771
"v1"
@@ -93,9 +87,7 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
9387
],
9488
"conditions": [
9589
{
96-
"attributes": [
97-
"a1"
98-
],
90+
"attribute": "a1",
9991
"operator": "StringEquals",
10092
"values": [
10193
"v1"
@@ -115,9 +107,7 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
115107
"role": "",
116108
"conditions": [
117109
{
118-
"attributes": [
119-
"a1"
120-
],
110+
"attribute": "a1",
121111
"operator": "StringEquals",
122112
"values": [
123113
"v1"
@@ -137,9 +127,7 @@ Feature: Behaviour of application when doing the POST /v1/policies endpoint, usi
137127
"role": "",
138128
"conditions": [
139129
{
140-
"attributes": [
141-
"a1"
142-
],
130+
"attribute": "a1",
143131
"operator": "StringEquals",
144132
"values": [
145133
"v1"

0 commit comments

Comments
 (0)