Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 9b29eb1

Browse files
committed
Enable OpenId Tests
1 parent 7f4a772 commit 9b29eb1

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

shared/Mocks/OpenIdConnect/OpenIdConnectBackChannelHttpHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
2424
{
2525
response.Content = new StringContent(File.ReadAllText(Path.Combine(basePath, "keys.json")));
2626
}
27+
else if (request.RequestUri.AbsoluteUri == "https://login.windows.net/4afbc689-805b-48cf-a24c-d4aa3248a248/oauth2/token")
28+
{
29+
response.Content = new StringContent("{\"id_token\": \"id\", \"access_token\": \"access\"}");
30+
}
2731

2832
return Task.FromResult(response);
2933
}

src/MusicStore/Controllers/AccountController.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading.Tasks;
44
using Microsoft.AspNetCore.Authorization;
55
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.AspNetCore.Http.Authentication;
67
using Microsoft.AspNetCore.Identity;
78
using Microsoft.AspNetCore.Mvc;
89
using Microsoft.AspNetCore.Mvc.Rendering;
@@ -452,7 +453,10 @@ public async Task<ActionResult> LogOff()
452453
var appEnv = HttpContext.RequestServices.GetService<IHostingEnvironment>();
453454
if (appEnv.EnvironmentName.StartsWith("OpenIdConnect"))
454455
{
455-
await HttpContext.Authentication.SignOutAsync("OpenIdConnect");
456+
return new SignOutResult("OpenIdConnect", new AuthenticationProperties
457+
{
458+
RedirectUri = Url.Action("Index", "Home")
459+
});
456460
}
457461

458462
return RedirectToAction("Index", "Home");

test/E2ETests/Implementation/OpenIdConnectLoginScenarios.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Net;
45
using System.Net.Http;
56
using System.Threading.Tasks;
@@ -36,25 +37,28 @@ public async Task LoginWithOpenIdConnect()
3637
Assert.Equal<string>("form_post", queryItems["response_mode"]);
3738
Assert.Equal<string>("code id_token", queryItems["response_type"]);
3839
Assert.Equal<string>("openid profile", queryItems["scope"]);
39-
Assert.Equal<string>("OpenIdConnect.AuthenticationProperties=ValidStateData", queryItems["state"]);
40+
Assert.Equal<string>("ValidStateData", queryItems["state"]);
4041
Assert.NotNull(queryItems["nonce"]);
4142
Assert.NotNull(_httpClientHandler.CookieContainer.GetCookies(new Uri(_deploymentResult.ApplicationBaseUri)).GetCookieWithName(".AspNetCore.OpenIdConnect.Nonce.protectedString"));
4243

4344
// This is just enable the auto-redirect.
4445
_httpClientHandler = new HttpClientHandler() { AllowAutoRedirect = true };
4546
_httpClient = new HttpClient(_httpClientHandler) { BaseAddress = new Uri(_deploymentResult.ApplicationBaseUri) };
46-
_httpClientHandler.CookieContainer.Add(new Uri(_deploymentResult.ApplicationBaseUri), new Cookie(".AspNet.OpenIdConnect.Nonce.protectedString", "N"));
47+
foreach (var header in Microsoft.Net.Http.Headers.SetCookieHeaderValue.ParseList(response.Headers.GetValues("Set-Cookie").ToList()))
48+
{
49+
_httpClientHandler.CookieContainer.Add(new Uri(_deploymentResult.ApplicationBaseUri), new Cookie(header.Name, header.Value));
50+
}
4751

4852
//Post a message to the OpenIdConnect middleware
4953
var token = new List<KeyValuePair<string, string>>
5054
{
5155
new KeyValuePair<string, string>("code", "AAABAAAAvPM1KaPlrEqdFSBzjqfTGGBtrTYVn589oKw4lLgJ6Svz0AhPVOJr0J2-Uu_KffGlqIbYlRAyxmt-vZ7VlSVdrWvOkNhK9OaAMaSD7LDoPbBTVMEkB0MdAgBTV34l2el-s8ZI02_9PvgQaORZs7n8eGaGbcoKAoxiDn2OcKuJVplXYgrGUwU4VpRaqe6RaNzuseM7qBFbLIv4Wps8CndE6W8ccmuu6EvGC6-H4uF9EZL7gU4nEcTc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UGdJalNVOVAxUy1IZWxEYVNGU2YtbVhWMVk2MC1LMnZXcXciLCJnaXZlbl9uYW1lIjoiVXNlcjMiLCJmYW1pbHlfbmFtZSI6IlVzZXIzIiwibmFtZSI6IlVzZXIzIiwidW5pcXVlX25hbWUiOiJ1c2VyM0BwcmFidXJhamdtYWlsLm9ubWljcm9zb2Z0LmNvbSIsIm5vbmNlIjoiNjM1NTc5OTI4NjM5NTE3NzE1Lk9UUmpPVFZrTTJFdE1EUm1ZUzAwWkRFM0xUaGhaR1V0WldabVpHTTRPRGt6Wkdaa01EUmxORGhrTjJNdE9XSXdNQzAwWm1Wa0xXSTVNVEl0TVRVd1ltUTRNemRtT1dJMCIsImNfaGFzaCI6IkZHdDN3Y1FBRGUwUFkxUXg3TzFyNmciLCJwd2RfZXhwIjoiNjY5MzI4MCIsInB3ZF91cmwiOiJodHRwczovL3BvcnRhbC5taWNyb3NvZnRvbmxpbmUuY29tL0NoYW5nZVBhc3N3b3JkLmFzcHgifQ.coAdCkdMgnslMHagdU8IBgH7Z0dilRdMfKytyqPJuTr6sbmbhrAoAj-KeGwbKgzrd-BeDk_rW47dntWuuAqGrAOGzxXvS2dcSWgoEKoXuDccIL5b4rIomRpfJpaeE-YwiU3usyRvoQCpHmtOa0g7xVilIj3_1-9ylMgRDY5qcrtQ_hEZlGuYyiCPR0dw8WmNU7r6PKObG-o3Yk_RbEBHjnaWxKoJwrVUEZUQOJDAvlr6ZYEmGTlD_BM0Rc_0fJZPU7A3uN9PHLw1atm-chN06IDXf23R33JI_xFuEZnj9HZQ_eIzNCl7GFmUryK3FFgYJpIbsI0BIFuksSikXz33IA"),
53-
new KeyValuePair<string, string>("state", "OpenIdConnect.AuthenticationProperties=ValidStateData"),
57+
new KeyValuePair<string, string>("state", "ValidStateData"),
5458
new KeyValuePair<string, string>("session_state", "d0b59ffa-2df9-4d8c-b43a-2c410987f4ae")
5559
};
5660

57-
response = await DoPostAsync(string.Empty, new FormUrlEncodedContent(token.ToArray()));
61+
response = await DoPostAsync("signin-oidc", new FormUrlEncodedContent(token.ToArray()));
5862
await ThrowIfResponseStatusNotOk(response);
5963
responseContent = await response.Content.ReadAsStringAsync();
6064
Assert.Equal(_deploymentResult.ApplicationBaseUri + "Account/ExternalLoginCallback?ReturnUrl=%2F", response.RequestMessage.RequestUri.AbsoluteUri);
@@ -106,7 +110,11 @@ public async Task LoginWithOpenIdConnect()
106110
"https://login.windows.net/4afbc689-805b-48cf-a24c-d4aa3248a248/oauth2/logout",
107111
response.Headers.Location.AbsoluteUri.Replace(response.Headers.Location.Query, string.Empty));
108112
queryItems = new QueryCollection(QueryHelpers.ParseQuery(response.Headers.Location.Query));
109-
Assert.Equal<string>(_deploymentResult.ApplicationBaseUri + "Account/Login", queryItems["post_logout_redirect_uri"]);
113+
Assert.Equal<string>(_deploymentResult.ApplicationBaseUri, queryItems["post_logout_redirect_uri"]);
114+
115+
response = await DoGetAsync(queryItems["post_logout_redirect_uri"]);
116+
responseContent = await response.Content.ReadAsStringAsync();
117+
Assert.Contains("Log in", responseContent);
110118
}
111119
}
112120
}

test/E2ETests/OpenIdConnectTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public OpenIdConnectTests(ITestOutputHelper output)
2222
_logger = new XunitLogger(output, LogLevel.Information);
2323
}
2424

25-
[ConditionalTheory(Skip = "Temporarily skipped the test to fix potential product issue"), Trait("E2Etests", "E2Etests")]
25+
[ConditionalTheory, Trait("E2Etests", "E2Etests")]
2626
[OSSkipCondition(OperatingSystems.Linux)]
2727
[OSSkipCondition(OperatingSystems.MacOSX)]
2828
//[InlineData(ServerType.Kestrel, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5040/")]
@@ -36,7 +36,7 @@ public async Task OpenIdConnect_OnWindowsOS(
3636
await OpenIdConnectTestSuite(serverType, runtimeFlavor, architecture, applicationBaseUrl);
3737
}
3838

39-
[ConditionalTheory(Skip = "Bug https://github.com/aspnet/dnx/issues/2958"), Trait("E2Etests", "E2Etests")]
39+
[ConditionalTheory, Trait("E2Etests", "E2Etests")]
4040
[OSSkipCondition(OperatingSystems.Windows)]
4141
[InlineData(ServerType.Kestrel, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, "http://localhost:5042/")]
4242
public async Task OpenIdConnect_OnNonWindows(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)

0 commit comments

Comments
 (0)