/// <summary> /// Parse URI for SAS (Shared Access Signature) information. /// </summary> /// <param name="address">The complete Uri.</param> /// <param name="credentials">The credentials to use.</param> private void ParseQueryAndVerify(StorageUri address, StorageCredentials credentials) { StorageCredentials parsedCredentials; DateTimeOffset? parsedSnapshot; this.StorageUri = NavigationHelper.ParseFileQueryAndVerify(address, out parsedCredentials, out parsedSnapshot); if (parsedCredentials != null && credentials != null && !credentials.Equals(new StorageCredentials())) { string error = string.Format(CultureInfo.CurrentCulture, SR.MultipleCredentialsProvided); throw new ArgumentException(error); } if (parsedSnapshot.HasValue && this.SnapshotTime.HasValue && !parsedSnapshot.Value.Equals(this.SnapshotTime.Value)) { string error = string.Format(CultureInfo.CurrentCulture, SR.MultipleSnapshotTimesProvided, parsedSnapshot, this.SnapshotTime); throw new ArgumentException(error); } if (parsedSnapshot.HasValue) { this.SnapshotTime = parsedSnapshot; } if (this.ServiceClient == null) { this.ServiceClient = new CloudFileClient(NavigationHelper.GetServiceClientBaseAddress(this.StorageUri, null /* usePathStyleUris */), credentials ?? parsedCredentials); } this.Name = NavigationHelper.GetShareNameFromShareAddress(this.Uri, this.ServiceClient.UsePathStyleUris); }
public void StorageCredentialsEquality() { StorageCredentials credSharedKey1 = new StorageCredentials(TestBase.TargetTenantConfig.AccountName, TestBase.TargetTenantConfig.AccountKey); StorageCredentials credSharedKey2 = new StorageCredentials(TestBase.TargetTenantConfig.AccountName, TestBase.TargetTenantConfig.AccountKey); StorageCredentials credSharedKey3 = new StorageCredentials(TestBase.TargetTenantConfig.AccountName + "1", TestBase.TargetTenantConfig.AccountKey); StorageCredentials credSharedKey4 = new StorageCredentials(TestBase.TargetTenantConfig.AccountName, Convert.ToBase64String(new byte[] { 0, 1, 2 })); StorageCredentials credSAS1 = new StorageCredentials(token); StorageCredentials credSAS2 = new StorageCredentials(token); StorageCredentials credSAS3 = new StorageCredentials(token + "1"); StorageCredentials credAnonymous1 = new StorageCredentials(); StorageCredentials credAnonymous2 = new StorageCredentials(); Assert.IsTrue(credSharedKey1.Equals(credSharedKey2)); Assert.IsFalse(credSharedKey1.Equals(credSharedKey3)); Assert.IsFalse(credSharedKey1.Equals(credSharedKey4)); Assert.IsTrue(credSAS1.Equals(credSAS2)); Assert.IsFalse(credSAS1.Equals(credSAS3)); Assert.IsTrue(credAnonymous1.Equals(credAnonymous2)); Assert.IsFalse(credSharedKey1.Equals(credSAS1)); Assert.IsFalse(credSharedKey1.Equals(credAnonymous1)); Assert.IsFalse(credSAS1.Equals(credAnonymous1)); }
/// <summary> /// Parse URI for SAS (Shared Access Signature) information. /// </summary> /// <param name="address">The complete Uri.</param> /// <param name="credentials">The credentials to use.</param> private void ParseQueryAndVerify(StorageUri address, StorageCredentials credentials) { StorageCredentials parsedCredentials; this.StorageUri = NavigationHelper.ParseQueueTableQueryAndVerify(address, out parsedCredentials); if (parsedCredentials != null && credentials != null && !credentials.Equals(new StorageCredentials())) { string error = string.Format(CultureInfo.CurrentCulture, SR.MultipleCredentialsProvided); throw new ArgumentException(error); } this.ServiceClient = new CloudQueueClient(NavigationHelper.GetServiceClientBaseAddress(this.StorageUri, null /* usePathStyleUris */), credentials ?? parsedCredentials); this.Name = NavigationHelper.GetQueueNameFromUri(this.Uri, this.ServiceClient.UsePathStyleUris); }