コード例 #1
0
        public void TestReadObjectInBucket()
        {
            CountDownLatch cd     = new CountDownLatch(1);
            KiiUser        user   = KiiUser.CurrentUser;
            KiiBucket      bucket = user.Bucket("aclTest");
            KiiBucketAcl   acl    = bucket.Acl(BucketAction.READ_OBJECTS_IN_BUCKET);

            KiiACLEntry <KiiBucket, BucketAction> entry = acl.Subject(KiiAnyAuthenticatedUser.Get());

            entry.Save(ACLOperation.GRANT, (KiiACLEntry <KiiBucket, BucketAction> savedEntry, Exception e) => {
                Assert.IsNull(e);
                Assert.AreEqual(BucketAction.READ_OBJECTS_IN_BUCKET, savedEntry.Action);
                bucket.ListAclEntries((IList <KiiACLEntry <KiiBucket, BucketAction> > list, Exception e2) => {
                    Assert.IsNull(e2);
                    CheckEntriesAfterAdd(user, list);

                    // Remove ACL Entry
                    entry.Save(ACLOperation.REVOKE, (KiiACLEntry <KiiBucket, BucketAction> savedEntry2, Exception e3) => {
                        Assert.IsNull(e3);
                        Assert.AreEqual(BucketAction.READ_OBJECTS_IN_BUCKET, savedEntry2.Action);

                        bucket.ListAclEntries((IList <KiiACLEntry <KiiBucket, BucketAction> > list2, Exception e4) => {
                            Assert.IsNull(e4);
                            CheckEntriesAfterRemove(user, list2);
                            cd.Signal();
                        });
                    });
                });
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 10)))
            {
                Assert.Fail("Callback not fired.");
            }
        }
コード例 #2
0
        public void Test_AppScopeSync()
        {
            LogIn("test-user-00001");
            client.AddResponse(200, RESPONSE_BODY);
            string   topicName = "test_topic";
            KiiTopic topic     = Kii.Topic(topicName);
            IList <KiiACLEntry <KiiTopic, TopicAction> > entries = topic.ListAclEntries();

            Assert.AreEqual(6, entries.Count);
            Assert.AreEqual(TopicAction.SEND_MESSAGE_TO_TOPIC, entries [0].Action);
            Assert.AreEqual("UUUU-5555-6666-7777-8888", ((KiiUser)entries [0].Subject).ID);
            Assert.AreEqual(TopicAction.SEND_MESSAGE_TO_TOPIC, entries [1].Action);
            Assert.AreEqual("GGGG-5555-6666-7777-8888", ((KiiGroup)entries[1].Subject).ID);
            Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [2].Action);
            Assert.AreEqual(KiiAnonymousUser.Get(), entries [2].Subject);
            Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [3].Action);
            Assert.AreEqual(KiiAnyAuthenticatedUser.Get(), entries [3].Subject);
            Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [4].Action);
            Assert.AreEqual("UUUU-1111-2222-3333-4444", ((KiiUser)entries [4].Subject).ID);
            Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [5].Action);
            Assert.AreEqual("GGGG-1111-2222-3333-4444", ((KiiGroup)entries[5].Subject).ID);

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics", topicName, "acl"), client.RequestUrl [0]);
        }
コード例 #3
0
 private KiiSubject GetSubjetFromUserID(string userID)
 {
     if (string.Compare(userID, "ANONYMOUS_USER", true) == 0)
     {
         return(KiiAnonymousUser.Get());
     }
     else if (string.Compare(userID, "ANY_AUTHENTICATED_USER", true) == 0)
     {
         return(KiiAnyAuthenticatedUser.Get());
     }
     else
     {
         return(KiiUser.UserWithID(userID));
     }
 }
コード例 #4
0
        public void Test_UserScopeASync()
        {
            LogIn("test-user-00001");
            client.AddResponse(200, RESPONSE_BODY);
            string         userID    = "test_user";
            string         topicName = "test_topic";
            KiiTopic       topic     = KiiUser.UserWithID(userID).Topic(topicName);
            CountDownLatch cd        = new CountDownLatch(1);
            IList <KiiACLEntry <KiiTopic, TopicAction> > entries = null;
            Exception exception = null;

            topic.ListAclEntries((IList <KiiACLEntry <KiiTopic, TopicAction> > result, Exception e) => {
                entries   = result;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }

            Assert.IsNull(exception);
            Assert.AreEqual(6, entries.Count);
            Assert.AreEqual(TopicAction.SEND_MESSAGE_TO_TOPIC, entries [0].Action);
            Assert.AreEqual("UUUU-5555-6666-7777-8888", ((KiiUser)entries [0].Subject).ID);
            Assert.AreEqual(TopicAction.SEND_MESSAGE_TO_TOPIC, entries [1].Action);
            Assert.AreEqual("GGGG-5555-6666-7777-8888", ((KiiGroup)entries[1].Subject).ID);
            Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [2].Action);
            Assert.AreEqual(KiiAnonymousUser.Get(), entries [2].Subject);
            Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [3].Action);
            Assert.AreEqual(KiiAnyAuthenticatedUser.Get(), entries [3].Subject);
            Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [4].Action);
            Assert.AreEqual("UUUU-1111-2222-3333-4444", ((KiiUser)entries [4].Subject).ID);
            Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [5].Action);
            Assert.AreEqual("GGGG-1111-2222-3333-4444", ((KiiGroup)entries[5].Subject).ID);

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "users", userID, "topics", topicName, "acl"), client.RequestUrl [0]);
        }
コード例 #5
0
        public void KiiBucketAclTest()
        {
            KiiBucketAcl acl1 = new KiiBucketAcl(Kii.Bucket("AA"), BucketAction.CREATE_OBJECTS_IN_BUCKET);
            KiiBucketAcl acl2 = new KiiBucketAcl(Kii.Bucket("AA"), BucketAction.CREATE_OBJECTS_IN_BUCKET);

            KiiUser userA  = KiiUser.CreateByUri(new Uri("kiicloud://users/userA"));
            KiiUser userA_ = KiiUser.CreateByUri(new Uri("kiicloud://users/userA"));
            KiiUser userB  = KiiUser.CreateByUri(new Uri("kiicloud://users/userB"));
            KiiUser userC  = KiiUser.CreateByUri(new Uri("kiicloud://users/C"));

            KiiGroup groupA  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupA"));
            KiiGroup groupA_ = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupA"));
            KiiGroup groupB  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupB"));
            KiiGroup groupC  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/C"));

            KiiACLEntry <KiiBucket, BucketAction> aclEntry1 = null;
            KiiACLEntry <KiiBucket, BucketAction> aclEntry2 = null;

            // same user
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, userA);
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, userA_);
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // same user
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, KiiAnonymousUser.Get());
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, KiiAnonymousUser.Get());
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different user
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, userA);
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, userB);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different user
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, KiiAnonymousUser.Get());
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, KiiAnyAuthenticatedUser.Get());
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // same group
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, groupA);
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, groupA_);
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different group
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, groupA);
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, groupB);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different subject kind
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, userC);
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, groupC);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
        }
コード例 #6
0
        public void KiiObjectAclTest()
        {
            KiiObject    objectA = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/a"));
            KiiObjectAcl acl1    = new KiiObjectAcl(objectA, ObjectAction.READ_EXISTING_OBJECT);
            KiiObjectAcl acl2    = new KiiObjectAcl(objectA, ObjectAction.READ_EXISTING_OBJECT);

            KiiUser userA  = KiiUser.CreateByUri(new Uri("kiicloud://users/userA"));
            KiiUser userA_ = KiiUser.CreateByUri(new Uri("kiicloud://users/userA"));
            KiiUser userB  = KiiUser.CreateByUri(new Uri("kiicloud://users/userB"));
            KiiUser userC  = KiiUser.CreateByUri(new Uri("kiicloud://users/C"));

            KiiGroup groupA  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupA"));
            KiiGroup groupA_ = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupA"));
            KiiGroup groupB  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupB"));
            KiiGroup groupC  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/C"));

            KiiACLEntry <KiiObject, ObjectAction> aclEntry1 = null;
            KiiACLEntry <KiiObject, ObjectAction> aclEntry2 = null;

            // same user
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, userA);
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, userA_);
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // same user
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, KiiAnonymousUser.Get());
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, KiiAnonymousUser.Get());
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different user
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, userA);
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, userB);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different user
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, KiiAnonymousUser.Get());
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, KiiAnyAuthenticatedUser.Get());
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // same group
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, groupA);
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, groupA_);
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different group
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, groupA);
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, groupB);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different subject kind
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, userC);
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, groupC);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
        }