示例#1
0
 protected void deleteRecursively( ObjectPath path ) {
     if ( path.IsDirectory() ) {
         ListOptions options = new ListOptions();
         do {
             foreach ( DirectoryEntry entry in this.esu.ListDirectory( path, options ) ) {
                 deleteRecursively( entry.Path );
             }
         } while ( options.Token != null );
     }
     this.esu.DeleteObject( path );
 }
示例#2
0
        public void testListObjectsWithMetadata()
        {
            // Create an object
            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(null, mlist, null, null);
            Assert.IsNotNull(id, "null ID returned");
            cleanup.Add(id);

            // List the objects.  Make sure the one we created is in the list
            ListOptions options = new ListOptions();
            options.IncludeMetadata = true;
            List<ObjectResult> objects = this.esu.ListObjects("listable", options);
            Assert.IsTrue(objects.Count > 0, "No objects returned");

            bool found = false;
            foreach (ObjectResult or in objects)
            {
                if (or.Id.Equals(id))
                {
                    found = true;
                    //Test metadata value
                    Assert.AreEqual("foo", or.meta.GetMetadata("listable").Value, "Metadata value wrong");
                }
            }

            Assert.IsTrue(found, "object not found in list");

            
        }
示例#3
0
        public void testListObjectsPaged()
        {
            // Create an object
            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(null, mlist, null, null);
            ObjectId id2 = this.esu.CreateObject(null, mlist, null, null);
            Assert.IsNotNull(id, "null ID returned");
            cleanup.Add(id);
            cleanup.Add(id2);

            // List the objects.  Make sure the one we created is in the list
            ListOptions options = new ListOptions();
            options.Limit = 1;
            List<ObjectResult> objects = this.esu.ListObjects("listable", options);
            while (options.Token != null)
            {
                Debug.WriteLine("Continuing results with token " + options.Token);
                objects.AddRange(this.esu.ListObjects("listable", options));
            }
            Assert.IsTrue(objects.Count > 0, "No objects returned");
            Assert.IsTrue(containsId(objects, id), "object not found in list");
            Assert.IsTrue(containsId(objects, id2), "object2 not found in list");
        }
示例#4
0
        public void testReadAccessToken()
        {
            string dir = rand8char();
            string file = rand8char();
            ObjectPath op = new ObjectPath("/" + dir + "/" + file);
            string data = "hello";
            ObjectId id = esu.CreateObjectOnPath(op, null, null, Encoding.UTF8.GetBytes(data), "text/plain");

            DateTime expiration = DateTime.UtcNow;
            expiration += TimeSpan.FromMinutes(5);

            SourceType source = new SourceType();
            source.Allow = new string[] {"10.0.0.0/8", "128.0.0.0/8"};
            source.Disallow = new string[] {"1.1.1.1"};

            ContentLengthRangeType range = new ContentLengthRangeType();
            range.From = 0;
            range.To = 1024; // 1KB

            FormFieldType formField1 = new FormFieldType();
            formField1.Name = "x-emc-meta";
            formField1.Optional = true;
            FormFieldType formField2 = new FormFieldType();
            formField2.Name = "x-emc-listable-meta";
            formField2.Optional = true;

            PolicyType policy = new PolicyType();
            policy.Expiration = expiration;
            policy.Source = source;
            policy.MaxDownloads = 2;
            policy.MaxUploads = 0;
            policy.ContentLengthRange = range;
            policy.FormField = new FormFieldType[] {formField1, formField2};

            Uri tokenUri = esu.CreateAccessToken(id, policy, null);

            WebResponse response = WebRequest.Create(tokenUri).GetResponse();
            string content = new StreamReader(response.GetResponseStream()).ReadToEnd();
            response.Close();
            Assert.AreEqual(data, content, "Token URL does not contain proper content");

            esu.DeleteAccessToken(tokenUri);

            tokenUri = esu.CreateAccessToken(op, policy, null);

            response = WebRequest.Create(tokenUri).GetResponse();
            content = new StreamReader(response.GetResponseStream()).ReadToEnd();
            response.Close();
            Assert.AreEqual(data, content, "Token URL does not contain proper content");

            policy.MaxDownloads = policy.MaxDownloads - 1; // we already used one

            ListOptions options = new ListOptions();
            List<AccessTokenType> tokens = esu.ListAccessTokens(options);
            Assert.AreEqual(1, tokens.Count, "ListTokens returns wrong count");
            AssertTokenPolicy(tokens[0], policy);

            AccessTokenType token = esu.GetAccessToken(tokenUri);

            esu.DeleteAccessToken(token.AccessTokenId);

            string path = tokenUri.GetComponents(UriComponents.Path, UriFormat.Unescaped);
            Assert.AreEqual(path.Split('/').Last(), token.AccessTokenId, "token ID doesn't match");
            AssertTokenPolicy(token, policy);
        }
示例#5
0
        public void testListDirectoryWithMetadata()
        {
            // Create an object
            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);
            string dir = rand8char();
            string file = rand8char();
            ObjectPath dirPath = new ObjectPath("/" + dir + "/");
            ObjectPath op = new ObjectPath("/" + dir + "/" + file);

            ObjectId dirId = this.esu.CreateObjectOnPath(dirPath, null, null, null, null);
            ObjectId id = this.esu.CreateObjectOnPath(op, null, mlist, null, null);
            cleanup.Add(op);
            cleanup.Add(dirPath);
            Debug.WriteLine("Path: " + op + " ID: " + id);
            Assert.IsNotNull(id);
            Assert.IsNotNull(dirId);

            // Read back the content
            string content = Encoding.UTF8.GetString(this.esu.ReadObject(op, null, null));
            Assert.AreEqual("", content, "object content wrong");
            content = Encoding.UTF8.GetString(this.esu.ReadObject(id, null, null));
            Assert.AreEqual("", content, "object content wrong when reading by id");

            // List the parent path
            ListOptions options = new ListOptions();
            options.IncludeMetadata = true;
            //options.UserMetadata = new List<string>();
            //options.UserMetadata.Add("listable");
            List<DirectoryEntry> dirList = esu.ListDirectory(dirPath, options);
            Debug.WriteLine("Dir content: " + content);
            DirectoryEntry ent = findInDirectory(dirList, op);
            Assert.IsNotNull(ent, "File not found in directory");

            // Check metadata
            Assert.IsNotNull(ent.SystemMetadata.GetMetadata("size"), "Size missing from metadata");
            Assert.AreEqual("foo", ent.UserMetadata.GetMetadata("listable").Value, "Metadata value wrong");

            // listable2 should not be present
            //Assert.IsNull(ent.UserMetadata.GetMetadata("listable2"), "listable2 shouldn't be present");
        }
示例#6
0
        public void testListDirectoryPaged()
        {
            string dir = rand8char();
            string file = rand8char();
            string file2 = rand8char();
            string dir2 = rand8char();
            ObjectPath dirPath = new ObjectPath("/" + dir + "/");
            ObjectPath op = new ObjectPath("/" + dir + "/" + file);
            ObjectPath dirPath2 = new ObjectPath("/" + dir + "/" + dir2 + "/");
            ObjectPath op2 = new ObjectPath("/" + dir + "/" + file2);

            ObjectId dirId = this.esu.CreateObjectOnPath(dirPath, null, null, null, null);
            ObjectId id = this.esu.CreateObjectOnPath(op, null, null, null, null);
            this.esu.CreateObjectOnPath(dirPath2, null, null, null, null);
            this.esu.CreateObjectOnPath(op2, null, null, null, null);
            cleanup.Add(op);
            cleanup.Add(op2);
            cleanup.Add(dirPath2);
            cleanup.Add(dirPath);

            Debug.WriteLine("Path: " + op + " ID: " + id);
            Assert.IsNotNull(id);
            Assert.IsNotNull(dirId);

            // List the parent path
            ListOptions options = new ListOptions();
            options.IncludeMetadata = false;
            options.Limit = 1;
            List<DirectoryEntry> dirList = esu.ListDirectory(dirPath, options);
            // Iterate over token
            while (options.Token != null)
            {
                Debug.WriteLine("Continuing with token " + options.Token);
                dirList.AddRange(esu.ListDirectory(dirPath, options));
            }
            Assert.IsTrue(directoryContains(dirList, op), "File not found in directory");
            Assert.IsTrue(directoryContains(dirList, op2), "File2 not found in directory");
        }
示例#7
0
       	public void testListDirectory() {
		    string dir = rand8char();
		    string file = rand8char();
		    string dir2 = rand8char();
            ObjectPath dirPath = new ObjectPath( "/" + dir + "/" );
    	    ObjectPath op = new ObjectPath( "/" + dir + "/" + file );
    	    ObjectPath dirPath2 = new ObjectPath( "/" + dir + "/" + dir2 + "/" );
        	
    	    ObjectId dirId = this.esu.CreateObjectOnPath( dirPath, null, null, null, null );
            ObjectId id = this.esu.CreateObjectOnPath( op, null, null, null, null );
            this.esu.CreateObjectOnPath( dirPath2, null, null, null, null );
            cleanup.Add( op );
            cleanup.Add( dirPath2 );
            cleanup.Add( dirPath );
            Debug.WriteLine( "Path: " + op + " ID: " + id );
            Assert.IsNotNull( id );
            Assert.IsNotNull(dirId);

            // Read back the content
            string content = Encoding.UTF8.GetString( this.esu.ReadObject( op, null, null ) );
            Assert.AreEqual(  "", content, "object content wrong" );
            content = Encoding.UTF8.GetString( this.esu.ReadObject( id, null, null ) );
            Assert.AreEqual("", content, "object content wrong when reading by id");
            
            // List the parent path
            ListOptions options = new ListOptions();
            options.IncludeMetadata = false;
            List<DirectoryEntry> dirList = esu.ListDirectory( dirPath, options );
            Debug.WriteLine( "Dir content: " + content );
            Assert.IsTrue( directoryContains( dirList, op ), "File not found in directory" );
            Assert.IsTrue( directoryContains( dirList, dirPath2 ), "subdirectory not found in directory" );
	    }