public void SigningTest(SigningV4Test test) { var timestamp = test.Timestamp.ToDateTime(); var clock = new FakeClock(timestamp); var signer = UrlSigner .FromServiceAccountCredential(StorageConformanceTestData.TestCredential) .WithClock(clock); var requestTemplate = RequestTemplate .FromBucket(test.Bucket) .WithObjectName(test.Object) .WithHttpMethod(s_methods[test.Method]) .WithRequestHeaders(test.Headers.ToDictionary(kvp => kvp.Key, kvp => Enumerable.Repeat(kvp.Value, 1))) .WithQueryParameters(test.QueryParameters.ToDictionary(kvp => kvp.Key, kvp => Enumerable.Repeat(kvp.Value, 1))); var options = Options .FromDuration(TimeSpan.FromSeconds(test.Expiration)) .WithSigningVersion(SigningVersion.V4) .WithScheme(test.Scheme); switch (test.UrlStyle) { case UrlStyle.VirtualHostedStyle: options = options.WithUrlStyle(UrlSigner.UrlStyle.VirtualHostedStyle); break; case UrlStyle.BucketBoundHostname: options = options.WithBucketBoundHostname(test.BucketBoundHostname); break; default: break; } var actualUrl = signer.Sign(requestTemplate, options); // We almost always want the complete URL afterwards, which xUnit doesn't give us. if (test.ExpectedUrl != actualUrl) { FileLogger.Log($"{test.Description} failure"); FileLogger.Log($"Expected: {test.ExpectedUrl}"); FileLogger.Log($"Actual: {actualUrl}"); } Assert.Equal(test.ExpectedUrl, actualUrl); }
public void SigningTest(SigningV4Test test) { var timestamp = test.Timestamp.ToDateTime(); var clock = new FakeClock(timestamp); var signer = UrlSigner .FromServiceAccountCredential(StorageConformanceTestData.TestCredential) .WithSigningVersion(SigningVersion.V4) .WithClock(clock); var actualUrl = signer.Sign(test.Bucket, test.Object, duration: TimeSpan.FromSeconds(test.Expiration), requestMethod: s_methods[test.Method], requestHeaders: test.Headers.ToDictionary(kvp => kvp.Key, kvp => Enumerable.Repeat(kvp.Value, 1)), contentHeaders: null); // We almost always want the complete URL afterwards, which xUnit doesn't give us. if (test.ExpectedUrl != actualUrl) { FileLogger.Log($"{test.Description} failure"); FileLogger.Log($"Expected: {test.ExpectedUrl}"); FileLogger.Log($"Actual: {actualUrl}"); } Assert.Equal(test.ExpectedUrl, actualUrl); }