public void KiiObjectAclTest()
        {
            KiiObject objectA  = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/a"));
            KiiObject objectA_ = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/a"));
            KiiObject objectB  = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/b"));

            KiiObjectAcl acl1 = null;
            KiiObjectAcl acl2 = null;

            // same object
            acl1 = new KiiObjectAcl(objectA);
            acl2 = new KiiObjectAcl(objectA_);
            Assert.IsTrue(acl1.Equals(acl2));
            Assert.IsTrue(acl1.GetHashCode() == acl2.GetHashCode());
            Assert.IsFalse(acl1 == acl2);
            // same object and action
            acl1 = new KiiObjectAcl(objectA, ObjectAction.READ_EXISTING_OBJECT);
            acl2 = new KiiObjectAcl(objectA_, ObjectAction.READ_EXISTING_OBJECT);
            Assert.IsTrue(acl1.Equals(acl2));
            Assert.IsTrue(acl1.GetHashCode() == acl2.GetHashCode());
            Assert.IsFalse(acl1 == acl2);
            // different object
            acl1 = new KiiObjectAcl(objectA);
            acl2 = new KiiObjectAcl(objectB);
            Assert.IsFalse(acl1.Equals(acl2));
            Assert.IsFalse(acl1.GetHashCode() == acl2.GetHashCode());
            Assert.IsFalse(acl1 == acl2);
            // different action
            acl1 = new KiiObjectAcl(objectA, ObjectAction.WRITE_EXISTING_OBJECT);
            acl2 = new KiiObjectAcl(objectA, ObjectAction.READ_EXISTING_OBJECT);
            Assert.IsFalse(acl1.Equals(acl2));
            Assert.IsFalse(acl1.GetHashCode() == acl2.GetHashCode());
            Assert.IsFalse(acl1 == acl2);
        }
        public void KiiNotSavedObjectAclTest()
        {
            KiiObject objectA = Kii.Bucket("app_bucket").NewKiiObject();

            KiiObjectAcl acl1 = null;
            KiiObjectAcl acl2 = null;

            acl1 = new KiiObjectAcl(objectA);
            acl2 = new KiiObjectAcl(objectA);
            Assert.IsFalse(acl1.Equals(acl2));
            Assert.IsTrue(acl1.GetHashCode() == acl2.GetHashCode());
            Assert.IsFalse(acl1 == acl2);
        }
        public void Test_0002_PutAclEntry_server_error()
        {
            // set response
            client.AddResponse(new CloudException(400, "{}"));

            KiiObject    obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd"));
            KiiObjectAcl acl = obj.Acl(ObjectAction.READ_EXISTING_OBJECT);

            // user
            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/id1234"));

            acl.Subject(user).Save(ACLOperation.GRANT);
        }
        public void Test_0000_PutAclEntry()
        {
            // set response
            this.SetStandardResponse(client);

            KiiObject    obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd"));
            KiiObjectAcl acl = obj.Acl(ObjectAction.READ_EXISTING_OBJECT);

            // user
            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/id1234"));

            acl.Subject(user).Save(ACLOperation.GRANT);

            Assert.AreEqual(1, client.RequestUrl.Count);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/buckets/test/objects/abcd/acl/READ_EXISTING_OBJECT/UserID:id1234", client.RequestUrl[0]);
        }
Example #5
0
        public void Test_0001_PutAclEntry_2user()
        {
            // set response
            this.SetStandardResponse(client);

            KiiObject    obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd"));
            KiiObjectAcl acl = obj.Acl(ObjectAction.READ_EXISTING_OBJECT);

            // user
            KiiUser   user      = KiiUser.CreateByUri(new Uri("kiicloud://users/id1234"));
            bool      done      = false;
            Exception exception = null;

            acl.Subject(user).Save(ACLOperation.GRANT, (KiiACLEntry <KiiObject, ObjectAction> entry, Exception e) =>
            {
                done      = true;
                exception = e;
            });

            Assert.IsTrue(done);
            Assert.IsNull(exception);

            user      = KiiUser.CreateByUri(new Uri("kiicloud://users/id5678"));
            done      = false;
            exception = null;
            obj.Acl(ObjectAction.WRITE_EXISTING_OBJECT).Subject(user).Save(ACLOperation.GRANT, (KiiACLEntry <KiiObject, ObjectAction> entry, Exception e) =>
            {
                done      = true;
                exception = e;
            });

            Assert.IsTrue(done);
            Assert.IsNull(exception);

            Assert.AreEqual(2, client.RequestUrl.Count);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/buckets/test/objects/abcd/acl/READ_EXISTING_OBJECT/UserID:id1234", client.RequestUrl[0]);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/buckets/test/objects/abcd/acl/WRITE_EXISTING_OBJECT/UserID:id5678", client.RequestUrl[1]);
        }
Example #6
0
        public void Test_0002_PutAclEntry_server_error()
        {
            // set response
            client.AddResponse(new CloudException(400, "{}"));

            KiiObject    obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd"));
            KiiObjectAcl acl = obj.Acl(ObjectAction.READ_EXISTING_OBJECT);

            // user
            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/id1234"));

            bool      done      = false;
            Exception exception = null;

            acl.Subject(user).Save(ACLOperation.GRANT, (KiiACLEntry <KiiObject, ObjectAction> entry, Exception e) =>
            {
                done      = true;
                exception = e;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(exception);
            Assert.IsTrue(exception is CloudException);
        }
        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);
        }