From efc5ea9b5de3a50734c0e789e7893fa26aa5edcb Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 16 Mar 2015 16:46:56 -0700 Subject: [PATCH] React to auth changes --- .../AuthenticationHandler.cs | 4 ++-- .../AuthenticationTests.cs | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNet.Server.WebListener/AuthenticationHandler.cs b/src/Microsoft.AspNet.Server.WebListener/AuthenticationHandler.cs index 833561b30a..bbaa799bca 100644 --- a/src/Microsoft.AspNet.Server.WebListener/AuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Server.WebListener/AuthenticationHandler.cs @@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Server.WebListener foreach (var authType in ListEnabledAuthSchemes()) { string authScheme = authType.ToString(); - if (context.AuthenticationSchemes.Contains(authScheme, StringComparer.Ordinal)) + if (string.Equals(authScheme, context.AuthenticationScheme, StringComparison.Ordinal)) { if (identity != null && identity.IsAuthenticated && string.Equals(authScheme, identity.AuthenticationType, StringComparison.Ordinal)) @@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Server.WebListener } else { - context.NotAuthenticated(authScheme, properties: null, description: GetDescription(authScheme)); + context.NotAuthenticated(); } } } diff --git a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/AuthenticationTests.cs b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/AuthenticationTests.cs index e96b810101..e78cb247be 100644 --- a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/AuthenticationTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/AuthenticationTests.cs @@ -262,8 +262,11 @@ namespace Microsoft.AspNet.Server.WebListener var context = new DefaultHttpContext((IFeatureCollection)env); Assert.NotNull(context.User); Assert.False(context.User.Identity.IsAuthenticated); - var authResults = context.Authenticate(authTypeList); - Assert.False(authResults.Any()); + foreach (var scheme in authTypeList) + { + var authResults = context.Authenticate(scheme); + Assert.Null(authResults.Principal); + } return Task.FromResult(0); })) { @@ -289,8 +292,16 @@ namespace Microsoft.AspNet.Server.WebListener var context = new DefaultHttpContext((IFeatureCollection)env); Assert.NotNull(context.User); Assert.True(context.User.Identity.IsAuthenticated); - var authResults = context.Authenticate(authTypeList); - Assert.Equal(1, authResults.Count()); + var count = 0; + foreach (var scheme in authTypeList) + { + var authResults = context.Authenticate(scheme); + if (authResults.Principal != null) + { + count++; + } + } + Assert.Equal(1, count); return Task.FromResult(0); })) {