Beispiel #1
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)
Beispiel #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)
Beispiel #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")
Beispiel #4
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")
Beispiel #5
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)
Beispiel #6
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)
Beispiel #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)
Beispiel #8
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:], [])
Beispiel #9
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)
Beispiel #10
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:], [])
Beispiel #11
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"))
Beispiel #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"))