Exemple #1
0
        private void readAcl( Acl acl, string header, EsuApiLib.Grantee.GRANTEE_TYPE type )
        {
            log.TraceEvent(TraceEventType.Verbose, 0,  "readAcl: " + header );
            string[] grants = header.Split( new string[] { "," }, StringSplitOptions.RemoveEmptyEntries );
            for( int i = 0; i < grants.Length; i++ ) {
                string[] nvpair = grants[i].Split( new string[] { "=" }, 2, StringSplitOptions.RemoveEmptyEntries );
                string grantee = nvpair[0];
                string permission = nvpair[1];

                grantee = grantee.Trim();

                // Currently, the server returns "FULL" instead of "FULL_CONTROL".
                // For consistency, change this to value use in the request
                if( "FULL".Equals( permission ) ) {
                    permission = Permission.FULL_CONTROL;
                }

                log.TraceEvent(TraceEventType.Verbose, 0,  "grant: " + grantee + "." + permission + " (" + type
                        + ")" );

                Grantee ge = new Grantee( grantee, type );
                Grant gr = new Grant( ge, permission );
                log.TraceEvent(TraceEventType.Verbose, 0,  "Grant: " + gr );
                acl.AddGrant( gr );
            }
        }
        public void testUpdateObjectAcl() {
            // Create an object with an ACL
            Acl acl = new Acl();
            acl.AddGrant( new Grant( new Grantee( getUid(esu.GetUid()), Grantee.GRANTEE_TYPE.USER ), Permission.FULL_CONTROL ) );
            Grant other = new Grant( Grantee.OTHER, Permission.READ );
            acl.AddGrant( other );
            ObjectId id = this.esu.CreateObject( acl, null, null, null );
            Assert.IsNotNull( id,"null ID returned" );
            cleanup.Add( id );

            // Read back the ACL and make sure it matches
            Acl newacl = this.esu.GetAcl( id );
            Debug.WriteLine( "Comparing " + newacl + " with " + acl );

            Assert.AreEqual( acl, newacl, "ACLs don't match" );
            
            // Change the ACL and update the object.
            acl.RemoveGrant( other );
            Grant o2 = new Grant( Grantee.OTHER, Permission.NONE );
            acl.AddGrant( o2 );
            this.esu.SetAcl( id, acl );
            
            // Read the ACL back and check it
            newacl = this.esu.GetAcl( id );
            Debug.WriteLine( "Comparing " + newacl + " with " + acl );
            Assert.AreEqual( acl, newacl, "ACLs don't match" );
        }
	    public void testGetAllMetadataById() {
            // Create an object with an ACL
            Acl acl = new Acl();
            acl.AddGrant(new Grant(new Grantee(getUid(esu.GetUid()), Grantee.GRANTEE_TYPE.USER), Permission.FULL_CONTROL));
            acl.AddGrant( new Grant( Grantee.OTHER, Permission.READ ) );
            MetadataList mlist = new MetadataList();
            Metadata listable = new Metadata( "listable", "foo", true );
            Metadata unlistable = new Metadata( "unlistable", "bar", false );
            Metadata listable2 = new Metadata( "listable2", "foo2 foo2", true );
            Metadata unlistable2 = new Metadata( "unlistable2", "bar2 bar2", false );
            mlist.AddMetadata(listable);
            mlist.AddMetadata(unlistable);
            mlist.AddMetadata(listable2);
            mlist.AddMetadata(unlistable2);

            ObjectId id = this.esu.CreateObject( acl, mlist, null, null );
            Assert.IsNotNull( id, "null ID returned" );
            cleanup.Add( id );
            
            // Read it back with HEAD call
            ObjectMetadata om = this.esu.GetAllMetadata( id );
            Assert.IsNotNull(om.Metadata.GetMetadata("listable"), "value of 'listable' missing");
            Assert.IsNotNull(om.Metadata.GetMetadata("unlistable"), "value of 'unlistable' missing");
            Assert.IsNotNull(om.Metadata.GetMetadata("atime"), "value of 'atime' missing");
            Assert.IsNotNull(om.Metadata.GetMetadata("ctime"), "value of 'ctime' missing");
            Assert.AreEqual("foo", om.Metadata.GetMetadata("listable").Value, "value of 'listable' wrong");
            Assert.AreEqual("bar", om.Metadata.GetMetadata("unlistable").Value, "value of 'unlistable' wrong");

            // Check the ACL
            Assert.AreEqual( acl, om.ACL, "ACLs don't match" );
    		
	    }
        public void testReadObjectStream()
        {
            Acl acl = new Acl();
            acl.AddGrant(new Grant(new Grantee(getUid(esu.GetUid()), Grantee.GRANTEE_TYPE.USER), Permission.FULL_CONTROL));
            acl.AddGrant(new Grant(Grantee.OTHER, Permission.READ));
            MetadataList mlist = new MetadataList();
            Metadata listable = new Metadata("listable", "foo", true);
            Metadata unlistable = new Metadata("unlistable", "bar", false);
            Metadata listable2 = new Metadata("listable2", "foo2 foo2", true);
            Metadata unlistable2 = new Metadata("unlistable2", "bar2 bar2", false);
            Metadata empty = new Metadata("empty", "", false);
            //Metadata withEqual = new Metadata("withEqual", "x=y=z", false);
            mlist.AddMetadata(listable);
            mlist.AddMetadata(unlistable);
            mlist.AddMetadata(listable2);
            mlist.AddMetadata(unlistable2);
            mlist.AddMetadata(empty);

            ObjectId id = esu.CreateObject(acl, mlist, Encoding.UTF8.GetBytes("hello"), "text/plain; charset=UTF-8");
            cleanup.Add(id);

            // Read back
            ReadObjectStreamResponse response = esu.ReadObjectStream(id, null);

            // Check content
            Assert.AreEqual(5, response.Length, "Content length incorrect");
            Assert.AreEqual("text/plain; charset=UTF-8", response.ContentType, "Content type incorrect");
            byte[] buffer = new byte[1024];
            int count = response.Content.Read(buffer, 0, buffer.Length);
            response.Close();

            Assert.AreEqual(5, count, "Incorrect number of bytes read from stream");
            string content = Encoding.UTF8.GetString(buffer, 0, count);
            Assert.AreEqual("hello", content, "Stream content incorrect");

            // Check metadata
            MetadataList meta = response.Metadata;
            Assert.AreEqual("foo", meta.GetMetadata("listable").Value, "value of 'listable' wrong");
            Assert.AreEqual("foo2 foo2", meta.GetMetadata("listable2").Value, "value of 'listable2' wrong");
            Assert.AreEqual("bar", meta.GetMetadata("unlistable").Value, "value of 'unlistable' wrong");
            Assert.AreEqual("bar2 bar2", meta.GetMetadata("unlistable2").Value, "value of 'unlistable2' wrong");
            Assert.AreEqual("", meta.GetMetadata("empty").Value, "value of 'empty' wrong");

            // Check ACL
            Acl newacl = response.Acl;
            Debug.WriteLine("Comparing " + newacl + " with " + acl);

            Assert.AreEqual(acl, newacl, "ACLs don't match");

            // Read a segment of the data back
            Extent extent = new Extent(1, 2);
            response = esu.ReadObjectStream(id, extent);
            count = response.Content.Read(buffer, 0, buffer.Length);
            response.Close();
            Assert.AreEqual(2, count, "Incorrect number of bytes read from stream");
            content = Encoding.UTF8.GetString(buffer, 0, count);
            Assert.AreEqual("el", content, "Stream content incorrect");

        }
	    public void testGetAllMetadataByPath() {
    	    ObjectPath op = new ObjectPath( "/" + rand8char() + ".tmp" );
            // Create an object with an ACL
            Acl acl = new Acl();
            acl.AddGrant(new Grant(new Grantee(esu.GetUid(), Grantee.GRANTEE_TYPE.USER), Permission.FULL_CONTROL));
            acl.AddGrant( new Grant( Grantee.OTHER, Permission.READ ) );
            MetadataList mlist = new MetadataList();
            Metadata listable = new Metadata( "listable", "foo", true );
            Metadata unlistable = new Metadata( "unlistable", "bar", false );
            Metadata listable2 = new Metadata( "listable2", "foo2 foo2", true );
            Metadata unlistable2 = new Metadata( "unlistable2", "bar2 bar2", false );
            mlist.AddMetadata( listable );
            mlist.AddMetadata( unlistable );
            mlist.AddMetadata( listable2 );
            mlist.AddMetadata( unlistable2 );

            ObjectId id = this.esu.CreateObjectOnPath( op, acl, null, null, null );
            this.esu.UpdateObject( op, null, mlist, null, null, null );
            Assert.IsNotNull( id, "null ID returned" );
            cleanup.Add( op );
            
            // Read it back with HEAD call
            ObjectMetadata om = this.esu.GetAllMetadata( op );
            Assert.IsNotNull( om.Metadata.GetMetadata( "listable" ), "value of 'listable' missing" );
            Assert.IsNotNull( om.Metadata.GetMetadata("unlistable"), "value of 'unlistable' missing" );
            Assert.IsNotNull( om.Metadata.GetMetadata("atime"), "value of 'atime' missing" );
            Assert.IsNotNull( om.Metadata.GetMetadata("ctime"), "value of 'ctime' missing" );
            Assert.AreEqual( "foo", om.Metadata.GetMetadata("listable").Value, "value of 'listable' wrong" );
            Assert.AreEqual( "bar", om.Metadata.GetMetadata("unlistable").Value, "value of 'unlistable' wrong" );

            // Check the ACL
            // not checking this by path because an extra groupid is added 
            // during the create calls by path.
            //Assert.AreEqual( acl, om.getAcl(), "ACLs don't match" );

	    }