From 4f32cb95faba59be4b836385ffa4b6b003be4c2c Mon Sep 17 00:00:00 2001 From: Praburaj Date: Wed, 28 Jan 2015 10:12:27 -0800 Subject: [PATCH] Fixing some issues with OpenIdconnect E2E test 1. Adding notifications and verification for them. --- .../OpenIdConnectLoginScenarios.cs | 13 ++++++------- .../OpenIdConnectNotifications.cs | 3 --- .../Mocks/StartupOpenIdConnectTesting.cs | 19 +++++++++---------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/test/E2ETests/Implementation/OpenIdConnectLoginScenarios.cs b/test/E2ETests/Implementation/OpenIdConnectLoginScenarios.cs index ec143e3488..476343ea79 100644 --- a/test/E2ETests/Implementation/OpenIdConnectLoginScenarios.cs +++ b/test/E2ETests/Implementation/OpenIdConnectLoginScenarios.cs @@ -89,13 +89,12 @@ namespace E2ETests Assert.Null(_httpClientHandler.CookieContainer.GetCookies(new Uri(_applicationBaseUrl)).GetCookieWithName(".AspNet.Microsoft.AspNet.Identity.ExternalLogin")); _logger.WriteInformation("Successfully signed in with user '{0}'", "User3@aspnettest.onmicrosoft.com"); - //_logger.WriteInformation("Verifying if the middleware notifications were fired"); - ////Check for a non existing item - //response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result; - ////This action requires admin permissions. If notifications are fired this permission is granted - //Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); - //_logger.WriteInformation("Middleware notifications were fired successfully"); - Console.ReadLine(); + _logger.WriteInformation("Verifying if the middleware notifications were fired"); + //Check for a non existing item + response = _httpClient.GetAsync(string.Format("Admin/StoreManager/GetAlbumIdFromName?albumName={0}", "123")).Result; + //This action requires admin permissions. If notifications are fired this permission is granted + Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); + _logger.WriteInformation("Middleware notifications were fired successfully"); } } } \ No newline at end of file diff --git a/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/OpenIdConnectNotifications.cs b/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/OpenIdConnectNotifications.cs index b105af82e8..b7091a2e77 100644 --- a/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/OpenIdConnectNotifications.cs +++ b/test/E2ETests/compiler/shared/Mocks/OpenIdConnect/OpenIdConnectNotifications.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Diagnostics; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Security.Notifications; @@ -39,8 +38,6 @@ namespace MusicStore.Mocks.OpenIdConnect internal static async Task AuthorizationCodeReceived(AuthorizationCodeReceivedNotification context) { - Debugger.Launch(); - Helpers.ThrowIfConditionFailed(() => context.Code == "AAABAAAAvPM1KaPlrEqdFSBzjqfTGGBtrTYVn589oKw4lLgJ6Svz0AhPVOJr0J2-Uu_KffGlqIbYlRAyxmt-vZ7VlSVdrWvOkNhK9OaAMaSD7LDoPbBTVMEkB0MdAgBTV34l2el-s8ZI02_9PvgQaORZs7n8eGaGbcoKAoxiDn2OcKuJVplXYgrGUwU4VpRaqe6RaNzuseM7qBFbLIv4Wps8CndE6W8ccmuu6EvGC6-H4uF9EZL7gU4nEcTcvkE4Qyt8do6VhTVfM1ygRNQgmV1BCig5t_5xfhL6-xWQdy15Uzn_Df8VSsyDXe8s9cxyKlqc_AIyLFy_NEiMQFUqjZWKd_rR3A8ugug15SEEGuo1kF3jMc7dVMdE6OF9UBd-Ax5ILWT7V4clnRQb6-CXB538DlolREfE-PowXYruFBA-ARD6rwAVtuVfCSbS0Zr4ZqfNjt6x8yQdK-OkdQRZ1thiZcZlm1lyb2EquGZ8Deh2iWBoY1uNcyjzhG-L43EivxtHAp6Y8cErhbo41iacgqOycgyJWxiB5J0HHkxD0nQ2RVVuY8Ybc9sdgyfKkkK2wZ3idGaRCdZN8Q9VBhWRXPDMqHWG8t3aZRtvJ_Xd3WhjNPJC0GpepUGNNQtXiEoIECC363o1z6PZC5-E7U3l9xK06BZkcfTOnggUiSWNCrxUKS44dNqaozdYlO5E028UgAEhJ4eDtcP3PZty-0j4j5Mw0F2FmyAA", "context.Code is invalid."); notificationsFired.Add(nameof(AuthorizationCodeReceived)); diff --git a/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs index 141284a88b..34234b10b3 100644 --- a/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs +++ b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs @@ -4,6 +4,7 @@ using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Security; +using Microsoft.AspNet.Security.OpenIdConnect; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; @@ -113,18 +114,16 @@ namespace MusicStore options.TokenValidationParameters.ValidateLifetime = false; options.ProtocolValidator.RequireNonce = true; options.ProtocolValidator.NonceLifetime = TimeSpan.FromDays(36500); + options.UseTokenLifetime = false; - if (options.Notifications == null) + options.Notifications = new OpenIdConnectAuthenticationNotifications { - // Bug: Notifications should be instantiated. - options.Notifications = new Microsoft.AspNet.Security.OpenIdConnect.OpenIdConnectAuthenticationNotifications(); - } - - options.Notifications.MessageReceived = OpenIdConnectNotifications.MessageReceived; - options.Notifications.AuthorizationCodeReceived = OpenIdConnectNotifications.AuthorizationCodeReceived; - options.Notifications.RedirectToIdentityProvider = OpenIdConnectNotifications.RedirectToIdentityProvider; - options.Notifications.SecurityTokenReceived = OpenIdConnectNotifications.SecurityTokenReceived; - options.Notifications.SecurityTokenValidated = OpenIdConnectNotifications.SecurityTokenValidated; + MessageReceived = OpenIdConnectNotifications.MessageReceived, + AuthorizationCodeReceived = OpenIdConnectNotifications.AuthorizationCodeReceived, + RedirectToIdentityProvider = OpenIdConnectNotifications.RedirectToIdentityProvider, + SecurityTokenReceived = OpenIdConnectNotifications.SecurityTokenReceived, + SecurityTokenValidated = OpenIdConnectNotifications.SecurityTokenValidated + }; }); // Add MVC to the request pipeline