def test_generated_role_admin_addr(self):
        """Tests the role admin address creation function as well as the
        address_is function.
        """

        role_id = uuid4().hex
        admin_id = uuid4().hex
        address = addresser.make_role_admins_address(role_id, admin_id)

        self.assertEqual(len(address), addresser.ADDRESS_LENGTH,
                         "The address is 70 characters")

        self.assertTrue(addresser.is_address(address),
                        "The address is 70 character hexidecimal")

        self.assertTrue(addresser.namespace_ok(address),
                        "The address has correct namespace prefix")

        self.assertTrue(
            addresser.is_family_address(address),
            "The address is 70 character hexidecimal with family prefix",
        )

        self.assertEqual(
            addresser.address_is(address),
            AddressSpace.ROLES_ADMINS,
            "The address created must be a Role Attributes address.",
        )
    def test_determine_role_admin_addr(self):
        """Tests that a specific role_id and admin_id generates the
        expected role admin address, and thus is probably deterministic.
        """

        role_id = "99968acb8f1a48b3a4bc21e2cd252e67"
        admin_id = "966ab67317234df489adb4bc1f517b88"
        expected_address = "9f444809326a1713a905b26359fc8d\
a2817c1a5f67de6f464701f0c10042da345d28f7"

        address = addresser.make_role_admins_address(role_id, admin_id)

        self.assertEqual(len(address), addresser.ADDRESS_LENGTH,
                         "The address is 70 characters")

        self.assertTrue(addresser.is_address(address),
                        "The address is 70 character hexidecimal")

        self.assertTrue(addresser.namespace_ok(address),
                        "The address has correct namespace prefix")

        self.assertTrue(
            addresser.is_family_address(address),
            "The address is 70 character hexidecimal with family prefix",
        )

        self.assertEqual(address, expected_address,
                         "The address is the one we expected it to be")

        self.assertEqual(
            addresser.address_is(address),
            AddressSpace.ROLES_ADMINS,
            "The address created must be a Role Attributes address.",
        )
Beispiel #3
0
    def test_legacy_make_addresses(self):
        user_id = Key().public_key
        unique_id = addresser.role.unique_id()
        unique_id2 = addresser.task.unique_id()

        self.assertEqual(
            legacy.make_user_address(user_id=user_id),
            addresser.user.address(object_id=user_id),
        )

        self.assertEqual(
            legacy.make_role_attributes_address(role_id=unique_id),
            addresser.role.address(object_id=unique_id),
        )
        self.assertEqual(
            legacy.make_role_owners_address(role_id=unique_id,
                                            user_id=user_id),
            addresser.role.owner.address(object_id=unique_id,
                                         target_id=user_id),
        )
        self.assertEqual(
            legacy.make_role_admins_address(role_id=unique_id,
                                            user_id=user_id),
            addresser.role.admin.address(object_id=unique_id,
                                         target_id=user_id),
        )
        self.assertEqual(
            legacy.make_role_members_address(role_id=unique_id,
                                             user_id=user_id),
            addresser.role.member.address(object_id=unique_id,
                                          target_id=user_id),
        )
        self.assertEqual(
            legacy.make_role_tasks_address(role_id=unique_id,
                                           task_id=unique_id2),
            addresser.role.task.address(object_id=unique_id,
                                        target_id=unique_id2),
        )

        self.assertEqual(
            legacy.make_task_attributes_address(task_id=unique_id),
            addresser.task.address(object_id=unique_id),
        )
        self.assertEqual(
            legacy.make_task_owners_address(task_id=unique_id,
                                            user_id=user_id),
            addresser.task.owner.address(object_id=unique_id,
                                         target_id=user_id),
        )
        self.assertEqual(
            legacy.make_task_admins_address(task_id=unique_id,
                                            user_id=user_id),
            addresser.task.admin.address(object_id=unique_id,
                                         target_id=user_id),
        )

        self.assertEqual(legacy.make_sysadmin_attr_address(),
                         addresser.sysadmin.address())
        self.assertEqual(
            legacy.make_sysadmin_owners_address(user_id=user_id),
            addresser.sysadmin.owner.address(object_id=user_id),
        )
        self.assertEqual(
            legacy.make_sysadmin_admins_address(user_id=user_id),
            addresser.sysadmin.admin.address(object_id=user_id),
        )
        self.assertEqual(
            legacy.make_sysadmin_members_address(user_id=user_id),
            addresser.sysadmin.member.address(object_id=user_id),
        )
Beispiel #4
0
    def test_role_addresses(self):
        """Tests the Role address creation functions as well as the
        address_is function.

        Notes:
            1. Create an address of a particular type:
                - Role Attributes
                - Role Members
                - Role Owners
                - Role Admins
                - Role Tasks
            2. Assert that address_is returns the correct address type.

        """

        role_address = addresser.make_role_attributes_address(
            role_id=uuid4().hex)

        self.assertEqual(len(role_address), 70,
                         "The address is a well-formed address.")

        self.assertEqual(
            addresser.address_is(role_address),
            AddressSpace.ROLES_ATTRIBUTES,
            "The Role Attributes address created must "
            "be found to be a Role Attributes address.",
        )

        role_members_address = addresser.make_role_members_address(
            role_id=uuid4().hex, user_id=uuid4().hex)

        self.assertEqual(len(role_members_address), 70,
                         "The address is a well-formed address.")

        self.assertEqual(
            addresser.address_is(role_members_address),
            AddressSpace.ROLES_MEMBERS,
            "The Role Members address created must be "
            "found to be a Role Members address.",
        )

        role_owners_address = addresser.make_role_owners_address(
            role_id=uuid4().hex, user_id=uuid4().hex)

        self.assertEqual(len(role_owners_address), 70,
                         "The address is a well-formed address.")

        self.assertEqual(
            addresser.address_is(role_owners_address),
            AddressSpace.ROLES_OWNERS,
            "The Role Owners address created must be found to be "
            "a Role Members address.",
        )

        role_admins_address = addresser.make_role_admins_address(
            role_id=uuid4().hex, user_id=uuid4().hex)

        self.assertEqual(len(role_admins_address), 70,
                         "The address is a well-formed address.")

        self.assertEqual(
            addresser.address_is(role_admins_address),
            AddressSpace.ROLES_ADMINS,
            "The Role Admins address created must be "
            "found to be a Role Admins address.",
        )

        role_tasks_address = addresser.make_role_tasks_address(
            role_id=uuid4().hex, task_id=uuid4().hex)

        self.assertEqual(len(role_tasks_address), 70,
                         "The address is a well-formed address.")

        self.assertEqual(
            addresser.address_is(role_tasks_address),
            AddressSpace.ROLES_TASKS,
            "The Role Tasks address created must be "
            "found to be a Role Tasks address.",
        )
    def test_legacy_make_addresses(self):
        """Test equality of the legacy addresser and new addresser classes"""
        user_id = Key().public_key
        unique_id = addresser.role.unique_id()
        unique_id2 = addresser.task.unique_id()

        self.assertEqual(
            legacy.make_user_address(user_id=user_id),
            addresser.user.address(object_id=user_id),
        )

        self.assertEqual(
            legacy.make_role_attributes_address(role_id=unique_id),
            addresser.role.address(object_id=unique_id),
        )
        self.assertEqual(
            legacy.make_role_owners_address(role_id=unique_id,
                                            user_id=user_id),
            addresser.role.owner.address(object_id=unique_id,
                                         related_id=user_id),
        )
        self.assertEqual(
            legacy.make_role_admins_address(role_id=unique_id,
                                            user_id=user_id),
            addresser.role.admin.address(object_id=unique_id,
                                         related_id=user_id),
        )
        self.assertEqual(
            legacy.make_role_members_address(role_id=unique_id,
                                             user_id=user_id),
            addresser.role.member.address(object_id=unique_id,
                                          related_id=user_id),
        )
        self.assertEqual(
            legacy.make_role_tasks_address(role_id=unique_id,
                                           task_id=unique_id2),
            addresser.role.task.address(object_id=unique_id,
                                        related_id=unique_id2),
        )

        self.assertEqual(
            legacy.make_task_attributes_address(task_id=unique_id),
            addresser.task.address(object_id=unique_id),
        )
        self.assertEqual(
            legacy.make_task_owners_address(task_id=unique_id,
                                            user_id=user_id),
            addresser.task.owner.address(object_id=unique_id,
                                         related_id=user_id),
        )
        self.assertEqual(
            legacy.make_task_admins_address(task_id=unique_id,
                                            user_id=user_id),
            addresser.task.admin.address(object_id=unique_id,
                                         related_id=user_id),
        )

        self.assertEqual(legacy.make_sysadmin_attr_address(),
                         addresser.sysadmin.address())
        self.assertEqual(
            legacy.make_sysadmin_owners_address(user_id=user_id),
            addresser.sysadmin.owner.address(object_id=user_id),
        )
        self.assertEqual(
            legacy.make_sysadmin_admins_address(user_id=user_id),
            addresser.sysadmin.admin.address(object_id=user_id),
        )
        self.assertEqual(
            legacy.make_sysadmin_members_address(user_id=user_id),
            addresser.sysadmin.member.address(object_id=user_id),
        )
Beispiel #6
0
 def address(self, object_id, target_id=None):
     """Makes a blockchain address of this address type"""
     return legacy.make_role_admins_address(role_id=object_id,
                                            user_id=target_id)