public async Task PostAsync_Post_ChannelBinding_ConfiguredCorrectly() { var content = new ChannelBindingAwareContent("Test contest"); using (HttpClient client = CreateHttpClient()) using (HttpResponseMessage response = await client.PostAsync(Configuration.Http.SecureRemoteEchoServer, content)) { // Validate status. Assert.Equal(HttpStatusCode.OK, response.StatusCode); // Validate the ChannelBinding object exists. ChannelBinding channelBinding = content.ChannelBinding; if (PlatformDetection.IsUap) { // UAP currently doesn't expose channel binding information. Assert.Null(channelBinding); } else { Assert.NotNull(channelBinding); // Validate the ChannelBinding's validity. if (BackendSupportsCustomCertificateHandling) { Assert.False(channelBinding.IsInvalid, "Expected valid binding"); Assert.NotEqual(IntPtr.Zero, channelBinding.DangerousGetHandle()); // Validate the ChannelBinding's description. string channelBindingDescription = channelBinding.ToString(); Assert.NotNull(channelBindingDescription); Assert.NotEmpty(channelBindingDescription); Assert.True((channelBindingDescription.Length + 1) % 3 == 0, $"Unexpected length {channelBindingDescription.Length}"); for (int i = 0; i < channelBindingDescription.Length; i++) { char c = channelBindingDescription[i]; if (i % 3 == 2) { Assert.Equal(' ', c); } else { Assert.True((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F'), $"Expected hex, got {c}"); } } } else { // Backend doesn't support getting the details to create the CBT. Assert.True(channelBinding.IsInvalid, "Expected invalid binding"); Assert.Equal(IntPtr.Zero, channelBinding.DangerousGetHandle()); Assert.Null(channelBinding.ToString()); } } } }
public async Task PostAsync_Post_ChannelBindingHasExpectedValue() { using (var client = new HttpClient()) { string expectedContent = "Test contest"; var content = new ChannelBindingAwareContent(expectedContent); HttpResponseMessage response = await client.PostAsync(HttpTestServers.SecureRemotePostServer, content); Assert.Equal(HttpStatusCode.OK, response.StatusCode); ChannelBinding channelBinding = content.ChannelBinding; Assert.NotNull(channelBinding); _output.WriteLine("Channel Binding: {0}", channelBinding); } }
public async Task PostAsync_Post_ChannelBinding_ConfiguredCorrectly() { var content = new ChannelBindingAwareContent("Test contest"); using (var client = new HttpClient()) using (HttpResponseMessage response = await client.PostAsync(Configuration.Http.SecureRemoteEchoServer, content)) { // Validate status. Assert.Equal(HttpStatusCode.OK, response.StatusCode); // Validate the ChannelBinding object exists. ChannelBinding channelBinding = content.ChannelBinding; Assert.NotNull(channelBinding); // Validate the ChannelBinding's validity. if (BackendSupportsCustomCertificateHandling) { Assert.False(channelBinding.IsInvalid, "Expected valid binding"); Assert.NotEqual(IntPtr.Zero, channelBinding.DangerousGetHandle()); // Validate the ChannelBinding's description. string channelBindingDescription = channelBinding.ToString(); Assert.NotNull(channelBindingDescription); Assert.NotEmpty(channelBindingDescription); Assert.True((channelBindingDescription.Length + 1) % 3 == 0, $"Unexpected length {channelBindingDescription.Length}"); for (int i = 0; i < channelBindingDescription.Length; i++) { char c = channelBindingDescription[i]; if (i % 3 == 2) { Assert.Equal(' ', c); } else { Assert.True((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F'), $"Expected hex, got {c}"); } } } else { // Backend doesn't support getting the details to create the CBT. Assert.True(channelBinding.IsInvalid, "Expected invalid binding"); Assert.Equal(IntPtr.Zero, channelBinding.DangerousGetHandle()); Assert.Null(channelBinding.ToString()); } } }