|
28 | 28 | } |
29 | 29 | """ |
30 | 30 |
|
| 31 | +ACL_NEW_UPDATE_RULES = """key_prefix "" { |
| 32 | + policy = "deny" |
| 33 | +} |
| 34 | +key "foo/" { |
| 35 | + policy = "read" |
| 36 | +} |
| 37 | +""" |
| 38 | + |
31 | 39 | POLICYLINKS_SAMPLE = [ |
32 | 40 | dict(ID="783beef3-783f-f41f-7422-7087dc272765"), |
33 | 41 | ] |
34 | 42 |
|
| 43 | +POLICYLINKS_UPDATE_SAMPLE = [ |
| 44 | + dict(ID="783beef3-783f-f41f-7422-7087dc272765"), |
| 45 | + dict(Name="some_policy_name") |
| 46 | +] |
| 47 | + |
35 | 48 | SERVICE_IDENTITIES_SAMPLE = [dict(ServiceName="db", Datacenters=["dc1"])] |
36 | 49 |
|
37 | 50 | ROLELINKS_SAMPLE = [dict(Name="some_role_name")] |
@@ -162,6 +175,14 @@ def test_create_and_read_policy(self): |
162 | 175 | result = self.consul.acl.read_policy(value["ID"]) |
163 | 176 | self.assertEqual(result['Rules'], ACL_NEW_RULES) |
164 | 177 |
|
| 178 | + def test_create_and_update_policy(self): |
| 179 | + value = self.consul.acl.create_policy("unittest_read_policy", |
| 180 | + rules=ACL_NEW_RULES) |
| 181 | + result = self.consul.acl.update_policy(value["ID"], |
| 182 | + value["Name"], |
| 183 | + policy=ACL_NEW_UPDATE_RULES) |
| 184 | + self.assertGreater(result["ModifyIndex"], result["CreateIndex"]) |
| 185 | + |
165 | 186 | def test_create_and_delete_policy(self): |
166 | 187 | value = self.consul.acl.create_policy("unittest_delete_policy", |
167 | 188 | rules=ACL_NEW_RULES) |
@@ -190,6 +211,15 @@ def test_create_and_read_role(self): |
190 | 211 | self.assertEqual(result['Policies'][0]['ID'], |
191 | 212 | POLICYLINKS_SAMPLE[0]["ID"]) |
192 | 213 |
|
| 214 | + def test_create_and_update_role(self): |
| 215 | + value = self.consul.acl.create_role( |
| 216 | + "unittest_read_role", |
| 217 | + policies=POLICYLINKS_SAMPLE, |
| 218 | + service_identities=SERVICE_IDENTITIES_SAMPLE) |
| 219 | + result = self.consul.acl.update_role( |
| 220 | + value["ID"], policies=POLICYLINKS_UPDATE_SAMPLE) |
| 221 | + self.assertGreater(result["ModifyIndex"], result["CreateIndex"]) |
| 222 | + |
193 | 223 | def test_create_and_delete_role(self): |
194 | 224 | value = self.consul.acl.create_role( |
195 | 225 | "unittest_delete_role", |
@@ -227,6 +257,19 @@ def test_create_and_read_token(self): |
227 | 257 | result = self.consul.acl.read_token(value["AccessorID"]) |
228 | 258 | self.assertEqual(result['AccessorID'], accessor_id) |
229 | 259 |
|
| 260 | + def test_create_and_update_token(self): |
| 261 | + secret_id = self.uuidv4() |
| 262 | + accessor_id = self.uuidv4() |
| 263 | + value = self.consul.acl.create_token( |
| 264 | + accessor_id=accessor_id, |
| 265 | + secret_id=secret_id, |
| 266 | + roles=ROLELINKS_SAMPLE, |
| 267 | + policies=POLICYLINKS_SAMPLE, |
| 268 | + service_identities=SERVICE_IDENTITIES_SAMPLE) |
| 269 | + result = self.consul.acl.update_token( |
| 270 | + value["AccessorID"], policies=POLICYLINKS_UPDATE_SAMPLE) |
| 271 | + self.assertGreater(result["ModifyIndex"], result["CreateIndex"]) |
| 272 | + |
230 | 273 | def test_create_and_delete_token(self): |
231 | 274 | secret_id = self.uuidv4() |
232 | 275 | accessor_id = self.uuidv4() |
|
0 commit comments