Esempio n. 1
0
    def test_activate(self):
        """A principal can be used with a client connection."""
        client = yield self.get_zookeeper_client().connect()
        self.addCleanup(lambda: client.close())

        admin_credentials = "admin:admin"
        test_credentials = "test:test"
        yield self.client.add_auth("digest", admin_credentials)

        acl = [make_ace(make_identity(admin_credentials), all=True),
               make_ace(make_identity(
                   test_credentials), read=True, create=True)]

        yield client.create("/acl-test", "content", acls=acl)

        # Verify the acl is active
        yield self.assertFailure(
            client.get("/acl-test"), zookeeper.NoAuthException)

        # Attach the principal to the connection
        group = GroupPrincipal(self.client, "/group-b")
        yield group.create("test", "test")
        yield group.attach(client)
        content, stat = yield client.get("/acl-test")
        self.assertEqual(content, "content")
Esempio n. 2
0
 def test_create(self):
     """An identity token can be gotten from a Principal."""
     principal = GroupPrincipal(self.client, "/group-a")
     yield principal.create("group/a", "zebra")
     self.assertEqual(principal.name, "group/a")
     yield self.assertFailure(principal.create("group/a", "zebra"),
                              RuntimeError)
Esempio n. 3
0
    def test_activate(self):
        """A principal can be used with a client connection."""
        client = yield self.get_zookeeper_client().connect()
        self.addCleanup(lambda: client.close())

        admin_credentials = "admin:admin"
        test_credentials = "test:test"
        yield self.client.add_auth("digest", admin_credentials)

        acl = [
            make_ace(make_identity(admin_credentials), all=True),
            make_ace(make_identity(test_credentials), read=True, create=True)
        ]

        yield client.create("/acl-test", "content", acls=acl)

        # Verify the acl is active
        yield self.assertFailure(client.get("/acl-test"),
                                 zookeeper.NoAuthException)

        # Attach the principal to the connection
        group = GroupPrincipal(self.client, "/group-b")
        yield group.create("test", "test")
        yield group.attach(client)
        content, stat = yield client.get("/acl-test")
        self.assertEqual(content, "content")
Esempio n. 4
0
 def test_create(self):
     """An identity token can be gotten from a Principal."""
     principal = GroupPrincipal(self.client, "/group-a")
     yield principal.create("group/a", "zebra")
     self.assertEqual(principal.name, "group/a")
     yield self.assertFailure(
         principal.create("group/a", "zebra"),
         RuntimeError)
Esempio n. 5
0
    def test_add_member(self):
        group = GroupPrincipal(self.client, "/group-a")
        yield group.create("group/a", "zebra")

        principal = Principal("aladdin", "genie")
        yield group.add_member(principal)
        acl, stat = yield self.client.get_acl("/group-a")
        self.assertEqual(acl[1:], [make_ace(principal.get_token(), read=True)])
        # Adding a member again is fine
        yield group.add_member(principal)
Esempio n. 6
0
    def test_remove_member(self):
        group = GroupPrincipal(self.client, "/group-a")
        yield group.create("group/a", "zebra")

        principal = Principal("aladdin", "genie")
        # Removing a member that doesn't exist is a no-op
        yield group.remove_member(principal)
        yield group.add_member(principal)
        yield group.remove_member(principal.name)

        acl, stat = yield self.client.get_acl("/group-a")
        self.assertEqual(acl[1:], [])
Esempio n. 7
0
    def test_add_member(self):
        group = GroupPrincipal(self.client, "/group-a")
        yield group.create("group/a", "zebra")

        principal = Principal("aladdin", "genie")
        yield group.add_member(principal)
        acl, stat = yield self.client.get_acl("/group-a")
        self.assertEqual(
            acl[1:],
            [make_ace(principal.get_token(), read=True)])
        # Adding a member again is fine
        yield group.add_member(principal)
Esempio n. 8
0
    def test_initialize(self):
        principal = GroupPrincipal(self.client, "/group-a")
        yield principal.create("group/a", "zebra")

        principal = GroupPrincipal(self.client, "/group-a")
        yield principal.initialize()
        self.assertEqual(principal.name, "group/a")

        principal = GroupPrincipal(self.client, "/group-b")
        yield self.assertFailure(principal.initialize(), StateNotFound)
Esempio n. 9
0
 def test_uninitialized_usage(self):
     """Attempting to access the name before initialized raises an error"""
     principal = GroupPrincipal(self.client, "/group-a")
     try:
         principal.name
     except RuntimeError:
         pass
     else:
         self.fail("Uninitialized usage should raise error")
Esempio n. 10
0
    def test_initialize(self):
        principal = GroupPrincipal(self.client, "/group-a")
        yield principal.create("group/a", "zebra")

        principal = GroupPrincipal(self.client, "/group-a")
        yield principal.initialize()
        self.assertEqual(principal.name, "group/a")

        principal = GroupPrincipal(self.client, "/group-b")
        yield self.assertFailure(principal.initialize(), StateNotFound)
Esempio n. 11
0
    def test_remove_member(self):
        group = GroupPrincipal(self.client, "/group-a")
        yield group.create("group/a", "zebra")

        principal = Principal("aladdin", "genie")
        # Removing a member that doesn't exist is a no-op
        yield group.remove_member(principal)
        yield group.add_member(principal)
        yield group.remove_member(principal.name)

        acl, stat = yield self.client.get_acl("/group-a")
        self.assertEqual(acl[1:], [])
Esempio n. 12
0
 def test_get_token(self):
     """An identity token can be gotten from a Principal."""
     principal = GroupPrincipal(self.client, "/group-a")
     yield principal.create("foobar", "secret")
     self.assertEqual(principal.get_token(),
                      make_identity("foobar:secret"))
Esempio n. 13
0
 def test_get_token(self):
     """An identity token can be gotten from a Principal."""
     principal = GroupPrincipal(self.client, "/group-a")
     yield principal.create("foobar", "secret")
     self.assertEqual(principal.get_token(), make_identity("foobar:secret"))