|
| 1 | +Feature: Policy Factory |
| 2 | + |
| 3 | + Background: |
| 4 | + Given I am the super-user |
| 5 | + And I create a new user "alice" |
| 6 | + And I create a new user "bob" |
| 7 | + And I successfully PATCH "/policies/cucumber/policy/root" with body: |
| 8 | + """ |
| 9 | + - !policy certificates |
| 10 | + - !policy-factory |
| 11 | + id: certificates |
| 12 | + base: !policy certificates |
| 13 | + template: |
| 14 | + - !variable |
| 15 | + id: <%=role.identifier%> |
| 16 | + annotations: |
| 17 | + provision/provisioner: context |
| 18 | + provision/context/parameter: value |
| 19 | +
|
| 20 | + - !permit |
| 21 | + role: !user |
| 22 | + id: /<%=role.identifier%> |
| 23 | + resource: !variable |
| 24 | + id: <%=role.identifier%> |
| 25 | + privileges: [ read, execute ] |
| 26 | +
|
| 27 | + - !policy nested-policy |
| 28 | + - !policy-factory |
| 29 | + id: nested-policy |
| 30 | + owner: !user alice |
| 31 | + base: !policy nested-policy |
| 32 | + template: |
| 33 | + - !host |
| 34 | + id: outer-<%=role.identifier%> |
| 35 | + owner: !user /<%=role.identifier%> |
| 36 | + annotations: |
| 37 | + outer: <%=role.identifier%> |
| 38 | +
|
| 39 | + - !policy |
| 40 | + id: inner |
| 41 | + owner: !user /<%=role.identifier%> |
| 42 | + body: |
| 43 | + - !host |
| 44 | + id: inner-<%=role.identifier%> |
| 45 | + annotations: |
| 46 | + inner: <%=role.identifier%> |
| 47 | +
|
| 48 | + - !policy edit-template |
| 49 | + - !policy-factory |
| 50 | + id: edit-template |
| 51 | + owner: !user alice |
| 52 | + base: !policy edit-template |
| 53 | + template: |
| 54 | + - !variable to-be-edited |
| 55 | +
|
| 56 | + - !policy-factory |
| 57 | + id: root-factory |
| 58 | + template: |
| 59 | + - !variable created-in-root |
| 60 | +
|
| 61 | + - !policy annotated-variables |
| 62 | + - !policy-factory |
| 63 | + id: parameterized |
| 64 | + base: !policy annotated-variables |
| 65 | + template: |
| 66 | + - !variable |
| 67 | + id: <%=role.identifier%> |
| 68 | + annotations: |
| 69 | + description: <%=params[:description]%> |
| 70 | +
|
| 71 | + - !permit |
| 72 | + role: !user bob |
| 73 | + resource: !policy-factory parameterized |
| 74 | + privileges: [ read ] |
| 75 | +
|
| 76 | + - !permit |
| 77 | + role: !user alice |
| 78 | + resource: !policy-factory certificates |
| 79 | + privileges: [ read, execute ] |
| 80 | +
|
| 81 | + - !permit |
| 82 | + role: !user alice |
| 83 | + resource: !policy-factory parameterized |
| 84 | + privileges: [ read, execute ] |
| 85 | + """ |
| 86 | + |
| 87 | + Scenario: Dry run loading policy using a factory |
| 88 | + Given I login as "alice" |
| 89 | + |
| 90 | + When I POST "/policy_factories/cucumber/certificates?dry_run=true" |
| 91 | + Then the JSON should be: |
| 92 | + """ |
| 93 | + { |
| 94 | + "policy_text": "---\n- !variable\n id: alice\n annotations:\n provision/provisioner: context\n provision/context/parameter: value\n- !permit\n privilege:\n - read\n - execute\n role: !user\n id: \"/alice\"\n resource: !variable\n id: alice\n", |
| 95 | + "load_to": "certificates", |
| 96 | + "dry_run": true, |
| 97 | + "response": null |
| 98 | + } |
| 99 | + """ |
| 100 | + |
| 101 | + Scenario: Nested policy within factory template |
| 102 | + Given I login as "alice" |
| 103 | + When I successfully POST "/policy_factories/cucumber/nested-policy" |
| 104 | + Then I successfully GET "/resources/cucumber/host/nested-policy/outer-alice" |
| 105 | + Then I successfully GET "/resources/cucumber/host/nested-policy/inner/inner-alice" |
| 106 | + |
| 107 | + Scenario: Load policy using a factory |
| 108 | + Given I login as "alice" |
| 109 | + And I set the "Content-Type" header to "multipart/form-data; boundary=demo" |
| 110 | + When I successfully POST "/policy_factories/cucumber/certificates" with body from file "policy-factory-context.txt" |
| 111 | + Then the JSON should be: |
| 112 | + """ |
| 113 | + { |
| 114 | + "policy_text": "---\n- !variable\n id: alice\n annotations:\n provision/provisioner: context\n provision/context/parameter: value\n- !permit\n privilege:\n - read\n - execute\n role: !user\n id: \"/alice\"\n resource: !variable\n id: alice\n", |
| 115 | + "load_to": "certificates", |
| 116 | + "dry_run": false, |
| 117 | + "response": { |
| 118 | + "created_roles": { |
| 119 | + }, |
| 120 | + "version": 1 |
| 121 | + } |
| 122 | + } |
| 123 | + """ |
| 124 | + And I successfully GET "/secrets/cucumber/variable/certificates/alice" |
| 125 | + Then the JSON should be: |
| 126 | + """ |
| 127 | + "test value" |
| 128 | + """ |
| 129 | + |
| 130 | + Scenario: Load parameterized policy using a factory |
| 131 | + Given I login as "alice" |
| 132 | + |
| 133 | + When I POST "/policy_factories/cucumber/parameterized?description=first%20description" |
| 134 | + Then the JSON should be: |
| 135 | + """ |
| 136 | + { |
| 137 | + "policy_text": "---\n- !variable\n id: alice\n annotations:\n description: first description\n", |
| 138 | + "load_to": "annotated-variables", |
| 139 | + "dry_run": false, |
| 140 | + "response": { |
| 141 | + "created_roles": { |
| 142 | + }, |
| 143 | + "version": 1 |
| 144 | + } |
| 145 | + } |
| 146 | + """ |
| 147 | + |
| 148 | + Scenario: Get a 404 response without read permission |
| 149 | + Given I login as "bob" |
| 150 | + When I POST "/policy_factories/cucumber/certificates" |
| 151 | + Then the HTTP response status code is 404 |
| 152 | + |
| 153 | + Scenario: Get a 403 response without execute permission |
| 154 | + Given I login as "bob" |
| 155 | + When I POST "/policy_factories/cucumber/parameterized" |
| 156 | + Then the HTTP response status code is 403 |
| 157 | + |
| 158 | + Scenario: A policy factory without a base loads into the root policy |
| 159 | + Given I POST "/policy_factories/cucumber/root-factory" |
| 160 | + And the HTTP response status code is 201 |
| 161 | + Then I successfully GET "/resources/cucumber/variable/created-in-root" |
| 162 | + |
| 163 | + Scenario: I retrieve the policy factory template through the API |
| 164 | + Given I login as "alice" |
| 165 | + When I GET "/policy_factories/cucumber/edit-template/template" |
| 166 | + Then the HTTP response status code is 200 |
| 167 | + And the JSON response should be: |
| 168 | + """ |
| 169 | + { |
| 170 | + "body": "---\n- !variable\n id: to-be-edited\n" |
| 171 | + } |
| 172 | + """ |
| 173 | + |
| 174 | + Scenario: I update the policy factory template through the API |
| 175 | + Given I login as "alice" |
| 176 | + When I PUT "/policy_factories/cucumber/edit-template/template" with body: |
| 177 | + """ |
| 178 | + ---\n- !variable replaced |
| 179 | + """ |
| 180 | + Then the HTTP response status code is 202 |
| 181 | + When I GET "/policy_factories/cucumber/edit-template/template" |
| 182 | + Then the JSON response should be: |
| 183 | + """ |
| 184 | + { |
| 185 | + "body": "---\\n- !variable replaced" |
| 186 | + } |
| 187 | + """ |
| 188 | + |
| 189 | + Scenario: I don't have permission to retrieve the policy factory template |
| 190 | + Given I login as "bob" |
| 191 | + When I GET "/policy_factories/cucumber/edit-template/template" |
| 192 | + Then the HTTP response status code is 404 |
0 commit comments