Skip to content

Commit

Permalink
make generator for roles and policy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abaez committed Sep 17, 2019
1 parent cdf88bd commit 4b84119
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions tests/acl_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
import json
import uuid
import random

import httmock

Expand Down Expand Up @@ -55,6 +56,18 @@ class TestCase(base.TestCase):
def uuidv4():
return str(uuid.uuid4())

@staticmethod
def random():
return str(random.random())

def _generate_policies(self):
sample = self.consul.acl.create_policy(self.random())
sample_update = self.consul.acl.create_policy(self.random())
return [dict(ID=sample["ID"]), dict(ID=sample_update["ID"])]

def _generate_roles(self):
return [dict(ID=self.consul.acl.create_role(self.random()))]

def test_bootstrap_request_exception(self):
@httmock.all_requests
def response_content(_url_unused, _request):
Expand Down Expand Up @@ -176,7 +189,7 @@ def test_create_and_read_policy(self):
self.assertEqual(result['Rules'], ACL_NEW_RULES)

def test_create_and_update_policy(self):
value = self.consul.acl.create_policy("unittest_read_policy",
value = self.consul.acl.create_policy("unittest_update_policy",
rules=ACL_NEW_RULES)
result = self.consul.acl.update_policy(value["ID"],
value["Name"],
Expand All @@ -197,34 +210,33 @@ def test_list_policy_exception(self):
def test_create_role(self):
result = self.consul.acl.create_role(
"unittest_create_role",
policies=POLICYLINKS_SAMPLE,
service_identities=SERVICE_IDENTITIES_SAMPLE)
self.assertEqual(result[0]['ID'], POLICYLINKS_SAMPLE[0]['ID'])
policies=self._generate_policies(),
service_identities=SERVICE_IDENTITIES_SAMPLE,
self.assertEqual(result['ServiceIdentities'][0]['ID'], SERVICE_IDENTITIES_SAMPLE[0]['ID'])

def test_create_and_read_role(self):
value = self.consul.acl.create_role(
"unittest_read_role",
policies=POLICYLINKS_SAMPLE,
policies=self._generate_policies(),
service_identities=SERVICE_IDENTITIES_SAMPLE)
result = self.consul.acl.read_role(value["ID"])
self.assertEqual(result['Policies'][0]['ID'],
POLICYLINKS_SAMPLE[0]["ID"])
self.assertEqual(result['ID'], value['ID'])

def test_create_and_update_role(self):
value = self.consul.acl.create_role(
"unittest_read_role",
policies=POLICYLINKS_SAMPLE,
"unittest_update_role",
policies=self._generate_policies(),
service_identities=SERVICE_IDENTITIES_SAMPLE)
result = self.consul.acl.update_role(
value["ID"],
"unittest_read_role",
"unittest_update_role",
policies=POLICYLINKS_UPDATE_SAMPLE)
self.assertGreater(result["ModifyIndex"], result["CreateIndex"])

def test_create_and_delete_role(self):
value = self.consul.acl.create_role(
"unittest_delete_role",
policies=POLICYLINKS_SAMPLE,
policies=self._generate_policies(),
service_identities=SERVICE_IDENTITIES_SAMPLE)
result = self.consul.acl.delete_role(value["ID"])
self.assertTrue(result)
Expand All @@ -240,8 +252,8 @@ def test_create_token(self):
result = self.consul.acl.create_token(
accessor_id=accessor_id,
secret_id=secret_id,
roles=ROLELINKS_SAMPLE,
policies=POLICYLINKS_SAMPLE,
roles=self._generate_roles(),
policies=self._generate_policies(),
service_identities=SERVICE_IDENTITIES_SAMPLE)
self.assertEqual(result['AccessorID'], accessor_id)
self.assertEqual(result['SecretID'], secret_id)
Expand All @@ -252,8 +264,8 @@ def test_create_and_read_token(self):
value = self.consul.acl.create_token(
accessor_id=accessor_id,
secret_id=secret_id,
roles=ROLELINKS_SAMPLE,
policies=POLICYLINKS_SAMPLE,
roles=self._generate_roles(),
policies=self._generate_policies(),
service_identities=SERVICE_IDENTITIES_SAMPLE)
result = self.consul.acl.read_token(value["AccessorID"])
self.assertEqual(result['AccessorID'], accessor_id)
Expand All @@ -264,11 +276,11 @@ def test_create_and_update_token(self):
value = self.consul.acl.create_token(
accessor_id=accessor_id,
secret_id=secret_id,
roles=ROLELINKS_SAMPLE,
policies=POLICYLINKS_SAMPLE,
roles=self._generate_roles(),
policies=self._generate_policies(),
service_identities=SERVICE_IDENTITIES_SAMPLE)
result = self.consul.acl.update_token(
value["AccessorID"], policies=POLICYLINKS_UPDATE_SAMPLE)
value["AccessorID"], policies=self._generate_policies())
self.assertGreater(result["ModifyIndex"], result["CreateIndex"])

def test_create_and_clone_token(self):
Expand Down

0 comments on commit 4b84119

Please sign in to comment.