public async Task AuthorizationHeaderFormat() { var expectedSyntax = $"HMAC-SHA256 Credential={s_credential}&SignedHeaders=date;host;x-ms-content-sha256&Signature=(.+)"; var response = new MockResponse(200); response.SetContent(SerializationHelpers.Serialize(s_testSetting, SerializeSetting)); var mockTransport = new MockTransport(response); ConfigurationClient service = CreateTestService(mockTransport); ConfigurationSetting setting = await service.AddConfigurationSettingAsync(s_testSetting); MockRequest request = mockTransport.SingleRequest; AssertRequestCommon(request); Assert.True(request.Headers.TryGetValue("Authorization", out var authHeader)); Assert.True(Regex.IsMatch(authHeader, expectedSyntax)); }
public async Task RequestHasSpecificApiVersion() { var response = new MockResponse(200); response.SetContent(SerializationHelpers.Serialize(s_testSetting, SerializeSetting)); var mockTransport = new MockTransport(response); var options = new ConfigurationClientOptions(ConfigurationClientOptions.ServiceVersion.V1_0); options.Diagnostics.ApplicationId = "test_application"; options.Transport = mockTransport; ConfigurationClient client = CreateClient <ConfigurationClient>(s_connectionString, options); ConfigurationSetting setting = await client.AddConfigurationSettingAsync(s_testSetting); MockRequest request = mockTransport.SingleRequest; StringAssert.Contains("api-version=1.0", request.Uri.ToUri().ToString()); }
public async Task ConfiguringTheClient() { var response = new MockResponse(200); response.SetContent(SerializationHelpers.Serialize(s_testSetting, SerializeSetting)); var mockTransport = new MockTransport(new MockResponse(503), response); var options = new ConfigurationClientOptions(); options.Diagnostics.ApplicationId = "test_application"; options.Transport = mockTransport; ConfigurationClient client = CreateClient <ConfigurationClient>(s_connectionString, options); ConfigurationSetting setting = await client.GetConfigurationSettingAsync(s_testSetting.Key); Assert.True(ConfigurationSettingEqualityComparer.Instance.Equals(s_testSetting, setting)); Assert.AreEqual(2, mockTransport.Requests.Count); }
public async Task GetWithAcceptDateTime() { var mockResponse = new MockResponse(200); mockResponse.SetContent(SerializationHelpers.Serialize(s_testSetting, SerializeSetting)); var mockTransport = new MockTransport(mockResponse); ConfigurationClient service = CreateTestService(mockTransport); Response <ConfigurationSetting> response = await service.GetAsync(s_testSetting.Key, s_testSetting.Label, DateTimeOffset.MaxValue, requestOptions : default); MockRequest request = mockTransport.SingleRequest; AssertRequestCommon(request); Assert.AreEqual(RequestMethod.Get, request.Method); Assert.AreEqual($"https://contoso.appconfig.io/kv/test_key?label=test_label&api-version={s_version}", request.Uri.ToString()); Assert.True(request.Headers.TryGetValue("Accept-Datetime", out var acceptDateTime)); Assert.AreEqual(DateTimeOffset.MaxValue.UtcDateTime.ToString("R", CultureInfo.InvariantCulture), acceptDateTime); Assert.False(request.Headers.TryGetValue("If-Match", out var ifMatch)); Assert.False(request.Headers.TryGetValue("If-None-Match", out var ifNoneMatch)); }
public async Task Add() { var response = new MockResponse(200); response.SetContent(SerializationHelpers.Serialize(s_testSetting, SerializeSetting)); var mockTransport = new MockTransport(response); ConfigurationClient service = CreateTestService(mockTransport); ConfigurationSetting setting = await service.AddAsync(s_testSetting); MockRequest request = mockTransport.SingleRequest; AssertRequestCommon(request); Assert.AreEqual(RequestMethod.Put, request.Method); Assert.AreEqual($"https://contoso.appconfig.io/kv/test_key?label=test_label&api-version={s_version}", request.UriBuilder.ToString()); Assert.True(request.Headers.TryGetValue("If-None-Match", out var ifNoneMatch)); Assert.AreEqual("*", ifNoneMatch); AssertContent(SerializationHelpers.Serialize(s_testSetting, SerializeRequestSetting), request); Assert.AreEqual(s_testSetting, setting); }
public async Task ExternalSyncTokensFollowRulesWhenAdded() { var response = new MockResponse(200); response.SetContent(SerializationHelpers.Serialize(s_testSetting, SerializeSetting)); var mockTransport = new MockTransport(response); ConfigurationClient service = CreateTestService(mockTransport); service.AddSyncToken("syncToken1=val1;sn=1"); service.AddSyncToken("syncToken1=val2;sn=2,syncToken2=val3;sn=2"); service.AddSyncToken("syncToken2=val1;sn=1"); await service.GetConfigurationSettingAsync(s_testSetting.Key, s_testSetting.Label); var request = mockTransport.Requests[0]; AssertRequestCommon(request); Assert.True(request.Headers.TryGetValues("Sync-Token", out var syncTokens)); CollectionAssert.Contains(syncTokens, "syncToken2=val3"); CollectionAssert.Contains(syncTokens, "syncToken1=val2"); }
public async Task AuthorizationHeadersAddedOnceWithRetries() { var response = new MockResponse(200); response.SetContent(SerializationHelpers.Serialize(s_testSetting, SerializeSetting)); var mockTransport = new MockTransport(new MockResponse(503), response); ConfigurationClient service = CreateTestService(mockTransport); await service.GetConfigurationSettingAsync(s_testSetting.Key, s_testSetting.Label); var retriedRequest = mockTransport.Requests[1]; AssertRequestCommon(retriedRequest); Assert.True(retriedRequest.Headers.TryGetValues("Date", out var dateHeaders)); Assert.True(retriedRequest.Headers.TryGetValues("x-ms-content-sha256", out var contentHashHeaders)); Assert.True(retriedRequest.Headers.TryGetValues("Authorization", out var authorizationHeaders)); Assert.AreEqual(1, dateHeaders.Count()); Assert.AreEqual(1, contentHashHeaders.Count()); Assert.AreEqual(1, authorizationHeaders.Count()); }