Skip to content

Commit 639e3dd

Browse files
authored
Fix Negotiate tests downlevel #11009 (dotnet#11101)
1 parent 4fa5a22 commit 639e3dd

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

src/Security/Authentication/Negotiate/test/Negotiate.FunctionalTest/Microsoft.AspNetCore.Authentication.Negotiate.FunctionalTest.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.0</TargetFramework>
55
<IsWindowsOnlyTest>true</IsWindowsOnlyTest>
6-
<!-- Disabled because of https://github.com/aspnet/AspNetCore/issues/11009. Tests don't run on Win7 or Win8 correctly. -->
7-
<BuildHelixPayload>false</BuildHelixPayload>
86
</PropertyGroup>
97

108
<ItemGroup>
@@ -20,9 +18,7 @@
2018
</ItemGroup>
2119

2220
<ItemGroup>
23-
<None Update="testCert.pfx">
24-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25-
</None>
21+
<Content Include="negotiateAuthCert.pfx" CopyToOutputDirectory="PreserveNewest" />
2622
</ItemGroup>
2723

2824
</Project>

src/Security/Authentication/Negotiate/test/Negotiate.FunctionalTest/NegotiateHandlerFunctionalTests.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,38 @@ public class NegotiateHandlerFunctionalTests
3535
new object[] { Http2Version },
3636
};
3737

38+
[ConditionalFact]
39+
// Only test HTTP/1.1, ALPN is not supported on Win7
40+
public async Task Anonymous_NoChallenge_NoOps_Win7()
41+
{
42+
using var host = await CreateHostAsync();
43+
using var client = CreateSocketHttpClient(host);
44+
client.DefaultRequestVersion = Http11Version;
45+
46+
var result = await client.GetAsync("/Anonymous1");
47+
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
48+
Assert.False(result.Headers.Contains(HeaderNames.WWWAuthenticate));
49+
Assert.Equal(Http11Version, result.Version);
50+
}
51+
52+
[ConditionalFact]
53+
// Only test HTTP/1.1, ALPN is not supported on Win7
54+
public async Task Anonymous_Challenge_401Negotiate_Win7()
55+
{
56+
using var host = await CreateHostAsync();
57+
// WinHttpHandler can't disable default credentials on localhost, use SocketHttpHandler.
58+
using var client = CreateSocketHttpClient(host);
59+
client.DefaultRequestVersion = Http11Version;
60+
61+
var result = await client.GetAsync("/Authenticate");
62+
Assert.Equal(HttpStatusCode.Unauthorized, result.StatusCode);
63+
Assert.Equal("Negotiate", result.Headers.WwwAuthenticate.ToString());
64+
Assert.Equal(Http11Version, result.Version);
65+
}
66+
3867
[ConditionalTheory]
3968
[MemberData(nameof(Http11And2))]
69+
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win81, SkipReason = "Windows only supports ALPN on 8.1 and later.")]
4070
public async Task Anonymous_NoChallenge_NoOps(Version version)
4171
{
4272
using var host = await CreateHostAsync();
@@ -51,6 +81,7 @@ public async Task Anonymous_NoChallenge_NoOps(Version version)
5181

5282
[ConditionalTheory]
5383
[MemberData(nameof(Http11And2))]
84+
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win81, SkipReason = "Windows only supports ALPN on 8.1 and later.")]
5485
public async Task Anonymous_Challenge_401Negotiate(Version version)
5586
{
5687
using var host = await CreateHostAsync();
@@ -148,6 +179,7 @@ public async Task RequestAfterAuth_Http2Then2_Success(bool persistNtlm)
148179
[ConditionalTheory]
149180
[InlineData(false)]
150181
[InlineData(true)]
182+
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10, SkipReason = "The client only supports HTTP/2 on Win10.")]
151183
public async Task RequestAfterAuth_Http2Then2Anonymous_Success(bool persistNtlm)
152184
{
153185
using var host = await CreateHostAsync(options => options.PersistNtlmCredentials = persistNtlm);
@@ -213,7 +245,7 @@ private static Task<IHost> CreateHostAsync(Action<NegotiateOptions> configureOpt
213245
{
214246
options.Listen(IPAddress.Loopback, 0, endpoint =>
215247
{
216-
endpoint.UseHttps("testCert.pfx", "testPassword");
248+
endpoint.UseHttps("negotiateAuthCert.pfx", "testPassword");
217249
});
218250
});
219251
webHostBuilder.Configure(app =>

0 commit comments

Comments
 (0)