public void FileUriBuilder_SasTest() { // Arrange var uriString = "https://account.file.core.windows.net/share?comp=list&sv=2015-04-05&spr=https&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sip=168.1.5.60-168.1.5.70&sr=b&sp=rw&sig=Z%2FRHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk%3D"; var originalUri = new UriBuilder(uriString); // Act var fileUriBuilder = new ShareUriBuilder(originalUri.Uri); Uri newUri = fileUriBuilder.ToUri(); // Assert Assert.AreEqual("https", fileUriBuilder.Scheme); Assert.AreEqual("account.file.core.windows.net", fileUriBuilder.Host); Assert.AreEqual("account", fileUriBuilder.AccountName); Assert.AreEqual(443, fileUriBuilder.Port); Assert.AreEqual("share", fileUriBuilder.ShareName); Assert.AreEqual("", fileUriBuilder.DirectoryOrFilePath); Assert.AreEqual("", fileUriBuilder.Snapshot); Assert.AreEqual(new DateTimeOffset(2015, 4, 30, 2, 23, 26, TimeSpan.Zero), fileUriBuilder.Sas.ExpiresOn); Assert.AreEqual("", fileUriBuilder.Sas.Identifier); Assert.AreEqual(SasIPRange.Parse("168.1.5.60-168.1.5.70"), fileUriBuilder.Sas.IPRange); Assert.AreEqual("rw", fileUriBuilder.Sas.Permissions); Assert.AreEqual(SasProtocol.Https, fileUriBuilder.Sas.Protocol); Assert.AreEqual("b", fileUriBuilder.Sas.Resource); Assert.IsNull(fileUriBuilder.Sas.ResourceTypes); Assert.IsNull(fileUriBuilder.Sas.Services); Assert.AreEqual("Z/RHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk=", fileUriBuilder.Sas.Signature); Assert.AreEqual(new DateTimeOffset(2015, 4, 29, 22, 18, 26, TimeSpan.Zero), fileUriBuilder.Sas.StartsOn); Assert.AreEqual("2015-04-05", fileUriBuilder.Sas.Version); Assert.AreEqual("comp=list", fileUriBuilder.Query); Assert.AreEqual(originalUri, newUri); }
public void FileUriBuilder_SpecialCharacters() { // Unencoded. We want to encode the special characters. string path = "!'();/[]@&%=+$/,#äÄö/ÖüÜß;"; ShareUriBuilder shareUriBuilder = new ShareUriBuilder(new Uri("https://account.file.core.windows.net/share")) { DirectoryOrFilePath = path }; Uri uri = shareUriBuilder.ToUri(); Assert.AreEqual( new Uri("https://account.file.core.windows.net/share/%21%27%28%29%3B/%5B%5D%40%26%25%3D%2B%24/%2C%23äÄö/ÖüÜß%3B"), uri); // Encoded. We want to encode again, because this is the literal path the customer wants. path = "%21%27%28%29%3B/%5B%5D%40%26%25%3D%2B%24/%2C%23äÄö/ÖüÜß%3B"; shareUriBuilder = new ShareUriBuilder(new Uri("https://account.file.core.windows.net/share")) { DirectoryOrFilePath = path }; uri = shareUriBuilder.ToUri(); Assert.AreEqual( new Uri("https://account.file.core.windows.net/share/%2521%2527%2528%2529%253B/%255B%255D%2540%2526%2525%253D%252B%2524/%252C%2523äÄö/ÖüÜß%253B"), uri); }
public async Task SharePermissionsRawPermissions(string permissionsString) { // Arrange await using DisposingShare test = await GetTestShareAsync(); ShareSasBuilder blobSasBuilder = new ShareSasBuilder { StartsOn = Recording.UtcNow.AddHours(-1), ExpiresOn = Recording.UtcNow.AddHours(1), ShareName = test.Share.Name }; blobSasBuilder.SetPermissions( rawPermissions: permissionsString, normalize: true); StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(TestConfigDefault.AccountName, TestConfigDefault.AccountKey); ShareUriBuilder blobUriBuilder = new ShareUriBuilder(test.Share.Uri) { Sas = blobSasBuilder.ToSasQueryParameters(sharedKeyCredential) }; ShareClient sasShareClient = new ShareClient(blobUriBuilder.ToUri(), GetOptions()); // Act await sasShareClient.GetRootDirectoryClient().GetPropertiesAsync(); }
public void FileUriBuilder_SnapshotTest() { // Arrange IList <string> snapshotUris = new List <string>() { "https://account.file.core.windows.net/share?sharesnapshot=2011-03-09T01:42:34.9360000Z", "https://account.file.core.windows.net/share?ShareSnapshot=2011-03-09T01:42:34.9360000Z", "https://account.file.core.windows.net/share?shareSnapshot=2011-03-09T01:42:34.9360000Z", "https://account.file.core.windows.net/share?SHARESNAPSHOT=2011-03-09T01:42:34.9360000Z", }; foreach (var uriString in snapshotUris) { var originalUri = new UriBuilder(uriString); // Act var fileUriBuilder = new ShareUriBuilder(originalUri.Uri); Uri newUri = fileUriBuilder.ToUri(); // Assert Assert.AreEqual("https", fileUriBuilder.Scheme); Assert.AreEqual("account.file.core.windows.net", fileUriBuilder.Host); Assert.AreEqual("account", fileUriBuilder.AccountName); Assert.AreEqual(443, fileUriBuilder.Port); Assert.AreEqual("share", fileUriBuilder.ShareName); Assert.AreEqual("", fileUriBuilder.DirectoryOrFilePath); Assert.AreEqual("2011-03-09T01:42:34.9360000Z", fileUriBuilder.Snapshot); Assert.IsNull(fileUriBuilder.Sas); Assert.AreEqual("", fileUriBuilder.Query); Assert.IsTrue(string.Equals(originalUri.Uri.AbsoluteUri, newUri.AbsoluteUri, StringComparison.OrdinalIgnoreCase)); } }
/// <summary> /// Initializes a new instance of the <see cref="ShareLeaseClient"/> class. /// </summary> /// <param name="client"> /// A <see cref="ShareClient"/> representing the share being leased. /// </param> /// <param name="leaseId"> /// An optional lease ID. If no lease ID is provided, a random lease /// ID will be created. /// </param> public ShareLeaseClient(ShareClient client, string leaseId = null) { _share = client ?? throw Errors.ArgumentNull(nameof(client)); LeaseId = leaseId ?? CreateUniqueLeaseId(); ShareUriBuilder uriBuilder = new ShareUriBuilder(client.Uri) { ShareName = null }; }
public void FileUriBuilder_PathTrailingSlash() { // Arrange var uriString = "https://account.file.core.windows.net/share/path/?restype=directory&comp=list"; var originalUri = new UriBuilder(uriString); // Act var fileUriBuilder = new ShareUriBuilder(originalUri.Uri); Assert.AreEqual("path", fileUriBuilder.DirectoryOrFilePath); Assert.AreEqual("path", fileUriBuilder.LastDirectoryOrFileName); }
public void FileUriBuilder_RoundTrip() { ShareServiceClient serviceUri = GetServiceClient_AccountSas(); var blobUriBuilder = new ShareUriBuilder(serviceUri.Uri); Uri blobUri = blobUriBuilder.ToUri(); var expectedUri = WebUtility.UrlDecode(serviceUri.Uri.AbsoluteUri); var actualUri = WebUtility.UrlDecode(blobUri.AbsoluteUri); Assert.AreEqual(expectedUri, actualUri, "Flaky test -- potential signature generation issue not properly encoding space and + in the output"); }
public void FileUriBuilder_SasStartExpiryTimeFormats(string startTime, string expiryTime) { // Arrange Uri initialUri = new Uri($"https://account.file.core.windows.net/share/directory/file?sv=2020-06-12&st={WebUtility.UrlEncode(startTime)}&se={WebUtility.UrlEncode(expiryTime)}&sr=b&sp=racwd&sig=%2BLsuqDlN8Us5lp%2FGdyEUMnU1XA4HdXx%2BJUdtkRNr7qI%3D"); ShareUriBuilder shareUriBuilder = new ShareUriBuilder(initialUri); // Act Uri resultUri = shareUriBuilder.ToUri(); // Assert Assert.AreEqual(initialUri, resultUri); Assert.IsTrue(resultUri.PathAndQuery.Contains($"st={WebUtility.UrlEncode(startTime)}")); Assert.IsTrue(resultUri.PathAndQuery.Contains($"se={WebUtility.UrlEncode(expiryTime)}")); }
public void FileUriBuilder_SasStartExpiryTimeFormats(string startTime, string expiryTime) { // Arrange Uri initialUri = new Uri($"https://account.file.core.windows.net/share/directory/file?sv=2020-04-08&st={WebUtility.UrlEncode(startTime)}&se={WebUtility.UrlEncode(expiryTime)}&sr=b&sp=racwd&sig=jQetX8odiJoZ7Yo0X8vWgh%2FMqRv9WE3GU%2Fr%2BLNMK3GU%3D"); ShareUriBuilder shareUriBuilder = new ShareUriBuilder(initialUri); // Act Uri resultUri = shareUriBuilder.ToUri(); // Assert Assert.AreEqual(initialUri, resultUri); Assert.IsTrue(resultUri.PathAndQuery.Contains($"st={WebUtility.UrlEncode(startTime)}")); Assert.IsTrue(resultUri.PathAndQuery.Contains($"se={WebUtility.UrlEncode(expiryTime)}")); }
public void FileUriBuilder_MalformedSubdomain() { // account and file swapped var shareUriBuilder1 = new ShareUriBuilder(new Uri("https://file.account.core.windows.net/share/dir")); // wrong service var shareUriBuilder2 = new ShareUriBuilder(new Uri("https://account.blob.core.windows.net/share/dir")); // empty service var shareUriBuilder3 = new ShareUriBuilder(new Uri("https://account./share/dir")); Assert.AreEqual(string.Empty, shareUriBuilder1.AccountName); Assert.AreEqual(string.Empty, shareUriBuilder2.AccountName); Assert.AreEqual(string.Empty, shareUriBuilder3.AccountName); }
public void FileUriBuilder_AccountTest() { // Arrange var uriString = "https://account.file.core.windows.net/?comp=list"; var originalUri = new UriBuilder(uriString); // Act var fileUriBuilder = new ShareUriBuilder(originalUri.Uri); Uri newUri = fileUriBuilder.ToUri(); // Assert Assert.AreEqual("https", fileUriBuilder.Scheme); Assert.AreEqual("account.file.core.windows.net", fileUriBuilder.Host); Assert.AreEqual(443, fileUriBuilder.Port); Assert.AreEqual("", fileUriBuilder.ShareName); Assert.AreEqual("", fileUriBuilder.DirectoryOrFilePath); Assert.AreEqual("", fileUriBuilder.Snapshot); Assert.IsNull(fileUriBuilder.Sas); Assert.AreEqual("comp=list", fileUriBuilder.Query); Assert.AreEqual(originalUri, newUri); }
public void FileUriBuilder_SnapshotTest() { // Arrange var uriString = "https://account.file.core.windows.net/share?sharesnapshot=2011-03-09T01:42:34.9360000Z"; var originalUri = new UriBuilder(uriString); // Act var fileUriBuilder = new ShareUriBuilder(originalUri.Uri); Uri newUri = fileUriBuilder.ToUri(); // Assert Assert.AreEqual("https", fileUriBuilder.Scheme); Assert.AreEqual("account.file.core.windows.net", fileUriBuilder.Host); Assert.AreEqual("account", fileUriBuilder.AccountName); Assert.AreEqual(443, fileUriBuilder.Port); Assert.AreEqual("share", fileUriBuilder.ShareName); Assert.AreEqual("", fileUriBuilder.DirectoryOrFilePath); Assert.AreEqual("2011-03-09T01:42:34.9360000Z", fileUriBuilder.Snapshot); Assert.IsNull(fileUriBuilder.Sas); Assert.AreEqual("", fileUriBuilder.Query); Assert.AreEqual(originalUri, newUri); }
public void FileUriBuilder_ShareTest() { // Arrange var uriString = "https://account.core.file.windows.net/share?restype=share"; var originalUri = new UriBuilder(uriString); // Act var fileUriBuilder = new ShareUriBuilder(originalUri.Uri); Uri newUri = fileUriBuilder.ToUri(); // Assert Assert.AreEqual("https", fileUriBuilder.Scheme); Assert.AreEqual("account.core.file.windows.net", fileUriBuilder.Host); Assert.AreEqual(443, fileUriBuilder.Port); Assert.AreEqual("share", fileUriBuilder.ShareName); Assert.AreEqual("", fileUriBuilder.DirectoryOrFilePath); Assert.AreEqual("", fileUriBuilder.Snapshot); Assert.IsNull(fileUriBuilder.Sas); Assert.AreEqual("restype=share", fileUriBuilder.Query); Assert.AreEqual(originalUri, newUri); Assert.AreEqual(string.Empty, fileUriBuilder.LastDirectoryOrFileName); }
public void ShareUriBuilder_CustomUri_AccountShareFileTest() { // Arrange var uriString = "https://www.mycustomname.com/sharename/filename"; var originalUri = new UriBuilder(uriString); // Act var fileUriBuilder = new ShareUriBuilder(originalUri.Uri); Uri newUri = fileUriBuilder.ToUri(); // Assert Assert.AreEqual("https", fileUriBuilder.Scheme); Assert.AreEqual("www.mycustomname.com", fileUriBuilder.Host); Assert.AreEqual(String.Empty, fileUriBuilder.AccountName); Assert.AreEqual("sharename", fileUriBuilder.ShareName); Assert.AreEqual("filename", fileUriBuilder.DirectoryOrFilePath); Assert.AreEqual("", fileUriBuilder.Snapshot); Assert.IsNull(fileUriBuilder.Sas); Assert.AreEqual("", fileUriBuilder.Query); Assert.AreEqual(443, fileUriBuilder.Port); Assert.AreEqual(originalUri, newUri); }
public void ShareUriBuilder_LocalDockerUrl_PortTest() { // Arrange // BlobEndpoint from https://docs.microsoft.com/en-us/azure/storage/common/storage-use-emulator#connect-to-the-emulator-account-using-the-well-known-account-name-and-key var uriString = "http://docker_container:10000/devstoreaccount1/sharename"; var originalUri = new UriBuilder(uriString); // Act var fileUriBuilder = new ShareUriBuilder(originalUri.Uri); Uri newUri = fileUriBuilder.ToUri(); // Assert Assert.AreEqual("http", fileUriBuilder.Scheme); Assert.AreEqual("docker_container", fileUriBuilder.Host); Assert.AreEqual("devstoreaccount1", fileUriBuilder.AccountName); Assert.AreEqual("sharename", fileUriBuilder.ShareName); Assert.AreEqual("", fileUriBuilder.DirectoryOrFilePath); Assert.AreEqual("", fileUriBuilder.Snapshot); Assert.IsNull(fileUriBuilder.Sas); Assert.AreEqual("", fileUriBuilder.Query); Assert.AreEqual(10000, fileUriBuilder.Port); Assert.AreEqual(originalUri, newUri); }
public void FileUriBuilder_AccountNamePeriod() { var fileUriBuilder = new ShareUriBuilder(new Uri("https://account.z.file.core.windows.net/share/dir")); Assert.AreEqual("account", fileUriBuilder.AccountName); }
public void FileUriBuilder_RegularUrl_CNAME() { var shareUriBuilder = new ShareUriBuilder(new Uri("http://www.contoso.com")); Assert.AreEqual(string.Empty, shareUriBuilder.AccountName); }
public void FileUriBuilder_AccountNameError() { var fileUriBuilder = new ShareUriBuilder(new Uri("http://notaurl")); Assert.IsEmpty(fileUriBuilder.AccountName); }