Beispiel #1
0
        public void Test_0205_ListAclEntries_QUERY_ONLY()
        {
            LogIn("test-user-00001");
            // set response
            client.AddResponse(200, "{" +
                               "\"QUERY_OBJECTS_IN_BUCKET\":[" +
                               "{\"userID\":\"user1234\"}" +
                               "]" +
                               "}"
                               );

            KiiBucket bucket = Kii.Bucket("test");

            // list
            IList <KiiACLEntry <KiiBucket, BucketAction> > entries = bucket.ListAclEntries();

            Assert.AreEqual(1, entries.Count);

            // entry 1
            KiiACLEntry <KiiBucket, BucketAction> entry = entries[0];

            Assert.AreEqual(BucketAction.QUERY_OBJECTS_IN_BUCKET, entry.Action);
            Assert.IsTrue(entry.Subject is KiiUser);
            Assert.AreEqual("kiicloud://users/user1234", ((KiiUser)entry.Subject).Uri.ToString());
        }
        public void Test_0204_ListAclEntries_unknown_id()
        {
            // set response
            client.AddResponse(200, "{" +
                               "\"READ_EXISTING_OBJECT\":[" +
                               "{\"userID\":\"user1234\"}" +
                               "]," +
                               "\"WRITE_EXISTING_OBJECT\":[" +
                               "{\"objectID\":\"object5678\"}" +
                               "]" +
                               "}"
                               );

            KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd"));

            // list
            IList <KiiACLEntry <KiiObject, ObjectAction> > entries = obj.ListAclEntries();

            Assert.AreEqual(1, entries.Count);

            // entry 1
            KiiACLEntry <KiiObject, ObjectAction> entry = entries[0];

            Assert.AreEqual(ObjectAction.READ_EXISTING_OBJECT, entry.Action);
            Assert.IsTrue(entry.Subject is KiiUser);
            Assert.AreEqual("kiicloud://users/user1234", ((KiiUser)entry.Subject).Uri.ToString());
        }
Beispiel #3
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.");
            }
        }
        public void Test_0200_ListAclEntries()
        {
            // set response
            this.SetStandardGetResponse(client);

            KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd"));

            // list
            IList <KiiACLEntry <KiiObject, ObjectAction> > entries = obj.ListAclEntries();

            Assert.AreEqual(2, entries.Count);

            // entry 1
            KiiACLEntry <KiiObject, ObjectAction> entry = entries[0];

            Assert.AreEqual(ObjectAction.READ_EXISTING_OBJECT, entry.Action);
            Assert.IsTrue(entry.Subject is KiiUser);
            Assert.AreEqual("kiicloud://users/user1234", ((KiiUser)entry.Subject).Uri.ToString());

            // entry 2
            entry = entries[1];
            Assert.AreEqual(ObjectAction.WRITE_EXISTING_OBJECT, entry.Action);
            Assert.IsTrue(entry.Subject is KiiUser);
            Assert.AreEqual("kiicloud://users/user5678", ((KiiUser)entry.Subject).Uri.ToString());
        }
Beispiel #5
0
        public void Test_0105_ListAclEntries_READ_ONLY()
        {
            // set response
            client.AddResponse(200, "{" +
                               "\"READ_EXISTING_OBJECT\":[" +
                               "{\"userID\":\"user1234\"}" +
                               "]" +
                               "}"
                               );

            KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd"));

            // list
            IList <KiiACLEntry <KiiObject, ObjectAction> > entries = null;
            Exception exception = null;

            obj.ListAclEntries((IList <KiiACLEntry <KiiObject, ObjectAction> > entryList, Exception e) =>
            {
                entries   = entryList;
                exception = e;
            });
            Assert.IsNull(exception);
            Assert.IsNotNull(entries);

            Assert.AreEqual(1, entries.Count);

            // entry 1
            KiiACLEntry <KiiObject, ObjectAction> entry = entries[0];

            Assert.AreEqual(ObjectAction.READ_EXISTING_OBJECT, entry.Action);
            Assert.IsTrue(entry.Subject is KiiUser);
            Assert.AreEqual("kiicloud://users/user1234", ((KiiUser)entry.Subject).Uri.ToString());
        }
Beispiel #6
0
        private IList <KiiACLEntry <T, U> > ParseListResponse(JsonObject json)
        {
            List <KiiACLEntry <T, U> > entries = new List <KiiACLEntry <T, U> >();

            string[] actionNames = ActionNames;
            foreach (string name in actionNames)
            {
                JsonArray whiteList = json.OptJsonArray(name);
                if (whiteList == null)
                {
                    continue;
                }
                for (int i = 0; i < whiteList.Length(); ++i)
                {
                    U action;
                    try
                    {
                        action = ToAction(name);
                    }
                    catch (Exception)
                    {
                        // Just ignore and continue if failed to parse action.
                        // Could be the action newly introduced.
                        continue;
                    }

                    KiiACL <T, U> acl = CreateFromAction(mParent, action);

                    JsonObject         entry = whiteList.GetJsonObject(i);
                    KiiACLEntry <T, U> kae   = null;
                    if (entry.Has("groupID"))
                    {
                        string gid = entry.GetString("groupID");
                        kae = acl.Subject(KiiGroup.GroupWithID(gid));
                        entries.Add(kae);
                    }
                    else if (entry.Has("userID"))
                    {
                        string     uid = entry.GetString("userID");
                        KiiSubject sbj = GetSubjetFromUserID(uid);
                        kae = acl.Subject(sbj);
                        entries.Add(kae);
                    }
                }
            }
            return(entries);
        }
        public void Test_1003_ListAclEntries_unknown_action()
        {
            LogIn("test-user-00001");
            // set response
            client.AddResponse(200, "{" +
                               "\"QUERY_OBJECTS_IN_BUCKET\":[" +
                               "{\"userID\":\"user1234\"}" +
                               "]," +
                               "\"READ_EXISTING_OBJECT\":[" +
                               "{\"userID\":\"user5678\"}" +
                               "]," +
                               "\"DROP_BUCKET_WITH_ALL_CONTENT\":[" +
                               "{\"groupID\":\"group5678\"}" +
                               "]" +
                               "}"
                               );

            KiiBucket bucket = Kii.Bucket("test");

            // list
            IList <KiiACLEntry <KiiBucket, BucketAction> > entries = null;
            Exception exception = null;

            bucket.ListAclEntries((IList <KiiACLEntry <KiiBucket, BucketAction> > list, Exception e) =>
            {
                entries   = list;
                exception = e;
            });
            // Assertion
            Assert.IsNotNull(entries);
            Assert.IsNull(exception);

            Assert.AreEqual(2, entries.Count);

            // entry 1
            KiiACLEntry <KiiBucket, BucketAction> entry = entries[0];

            Assert.AreEqual(BucketAction.DROP_BUCKET_WITH_ALL_CONTENT, entry.Action);
            Assert.IsTrue(entry.Subject is KiiGroup);
            Assert.AreEqual("kiicloud://groups/group5678", ((KiiGroup)entry.Subject).Uri.ToString());

            // entry 2
            entry = entries[1];
            Assert.AreEqual(BucketAction.QUERY_OBJECTS_IN_BUCKET, entry.Action);
            Assert.IsTrue(entry.Subject is KiiUser);
            Assert.AreEqual("kiicloud://users/user1234", ((KiiUser)entry.Subject).Uri.ToString());
        }
Beispiel #8
0
        public void Test_0103_ListAclEntries_unknown_action()
        {
            // set response
            client.AddResponse(200, "{" +
                               "\"READ_EXISTING_OBJECT\":[" +
                               "{\"userID\":\"user1234\"}" +
                               "]," +
                               "\"CREATE_OBJECTS_IN_BUCKET\":[" +
                               "{\"userID\":\"user5678\"}" +
                               "]," +
                               "\"WRITE_EXISTING_OBJECT\":[" +
                               "{\"groupID\":\"group5678\"}" +
                               "]" +
                               "}"
                               );

            KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd"));

            // list
            IList <KiiACLEntry <KiiObject, ObjectAction> > entries = null;
            Exception exception = null;

            obj.ListAclEntries((IList <KiiACLEntry <KiiObject, ObjectAction> > entryList, Exception e) =>
            {
                entries   = entryList;
                exception = e;
            });
            Assert.IsNull(exception);
            Assert.IsNotNull(entries);
            Assert.AreEqual(2, entries.Count);

            // entry 1
            KiiACLEntry <KiiObject, ObjectAction> entry = entries[0];

            Assert.AreEqual(ObjectAction.READ_EXISTING_OBJECT, entry.Action);
            Assert.IsTrue(entry.Subject is KiiUser);
            Assert.AreEqual("kiicloud://users/user1234", ((KiiUser)entry.Subject).Uri.ToString());

            // entry 2
            entry = entries[1];
            Assert.AreEqual(ObjectAction.WRITE_EXISTING_OBJECT, entry.Action);
            Assert.IsTrue(entry.Subject is KiiGroup);
            Assert.AreEqual("kiicloud://groups/group5678", ((KiiGroup)entry.Subject).Uri.ToString());
        }
        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);
        }
        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);
        }