Example #1
0
        public void CloudFileDirectorySAS()
        {
            CloudFileDirectory dir  = this.testShare.GetRootDirectoryReference().GetDirectoryReference("dirfile");
            CloudFile          file = dir.GetFileReference("dirfile");

            dir.Create();
            file.Create(512);

            SharedAccessFilePolicy policy = new SharedAccessFilePolicy()
            {
                SharedAccessStartTime  = DateTimeOffset.UtcNow.AddMinutes(-5),
                SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                Permissions            = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.List
            };

            string             sasToken = file.GetSharedAccessSignature(policy);
            CloudFileDirectory sasDir   = new CloudFileDirectory(new Uri(dir.Uri.AbsoluteUri + sasToken));

            TestHelper.ExpectedException(
                () => sasDir.FetchAttributes(),
                "Fetching attributes of a directory using a file SAS should fail",
                HttpStatusCode.Forbidden);

            sasToken = this.testShare.GetSharedAccessSignature(policy);
            sasDir   = new CloudFileDirectory(new Uri(dir.Uri.AbsoluteUri + sasToken));
            sasDir.FetchAttributes();
        }
Example #2
0
        private void FileDirectoryEscapingTest(string directoryName, string fileName)
        {
            CloudFileClient service = GenerateCloudFileClient();
            CloudFileShare  share   = GetRandomShareReference();

            try
            {
                share.Create();
                string text = Guid.NewGuid().ToString();

                // Create from CloudFileShare.
                CloudFileDirectory directory = share.GetRootDirectoryReference().GetDirectoryReference(directoryName);
                directory.Create();
                CloudFile originalFile = directory.GetFileReference(fileName);
                originalFile.Create(0);

                // List directories from share.
                IListFileItem directoryFromShareListingFiles = share.GetRootDirectoryReference().ListFilesAndDirectories().First();
                Assert.AreEqual(directory.Uri, directoryFromShareListingFiles.Uri);

                // List files from directory.
                IListFileItem fileFromDirectoryListingFiles = directory.ListFilesAndDirectories().First();
                Assert.AreEqual(originalFile.Uri, fileFromDirectoryListingFiles.Uri);

                // Check Name
                Assert.AreEqual <string>(fileName, originalFile.Name);

                // Absolute URI access from CloudFile
                CloudFile fileInfo = new CloudFile(originalFile.Uri, service.Credentials);
                fileInfo.FetchAttributes();

                // Access from CloudFileDirectory
                CloudFileDirectory cloudFileDirectory         = share.GetRootDirectoryReference().GetDirectoryReference(directoryName);
                CloudFile          fileFromCloudFileDirectory = cloudFileDirectory.GetFileReference(fileName);
                Assert.AreEqual(fileInfo.Uri, fileFromCloudFileDirectory.Uri);
            }
            finally
            {
                share.Delete();
            }
        }
        public void TestFileDirectoryEncryption()
        {
            bool requestFound = false;

            OperationContext ctxt = new OperationContext();

            ctxt.RequestCompleted += (sender, args) =>
            {
                Assert.IsTrue(args.RequestInformation.IsRequestServerEncrypted);
                requestFound = true;
            };

            CloudFileDirectory dir2 = this.share.GetRootDirectoryReference().GetDirectoryReference("dir2");

            dir2.Create(null, ctxt);
            Assert.IsTrue(requestFound);

            requestFound = false;
            dir2.SetMetadata(null, null, ctxt);
            Assert.IsTrue(requestFound);
        }