Add functional tests for external provider display name
This commit is contained in:
parent
373a9c5eb2
commit
5e84c11cf9
|
|
@ -7,6 +7,7 @@ using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AngleSharp.Dom.Html;
|
||||||
using Identity.DefaultUI.WebSite;
|
using Identity.DefaultUI.WebSite;
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||||
using Microsoft.AspNetCore.TestHost;
|
using Microsoft.AspNetCore.TestHost;
|
||||||
|
|
@ -193,6 +194,31 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
|
||||||
AssertClaimsNotEqual(principals[0], principals[1], "AspNet.Identity.SecurityStamp");
|
AssertClaimsNotEqual(principals[0], principals[1], "AspNet.Identity.SecurityStamp");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CanSeeExternalLoginProviderDisplayName()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
void ConfigureTestServices(IServiceCollection services) => services.SetupTestThirdPartyLogin();
|
||||||
|
|
||||||
|
var server = ServerFactory
|
||||||
|
.WithWebHostBuilder(whb => whb.ConfigureTestServices(ConfigureTestServices));
|
||||||
|
|
||||||
|
var client = server.CreateClient();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var userName = Guid.NewGuid().ToString();
|
||||||
|
var email = $"{userName}@example.com";
|
||||||
|
var index = await UserStories.RegisterNewUserWithSocialLoginAsync(client, userName, email);
|
||||||
|
var manage = await index.ClickManageLinkWithExternalLoginAsync();
|
||||||
|
var externalLogins = await manage.ClickExternalLoginsAsync();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var title = externalLogins.Document.GetElementsByTagName("h4").FirstOrDefault(e => e.TextContent == "Registered Logins");
|
||||||
|
var table = title?.NextElementSibling as IHtmlTableElement;
|
||||||
|
var firstCell = table?.Bodies?.FirstOrDefault()?.Rows.FirstOrDefault()?.Cells?.FirstOrDefault();
|
||||||
|
Assert.Equal("Contoso auth", firstCell?.TextContent);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task CanResetAuthenticator()
|
public async Task CanResetAuthenticator()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AngleSharp.Dom.Html;
|
using AngleSharp.Dom.Html;
|
||||||
|
using AngleSharp.Extensions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account
|
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account
|
||||||
{
|
{
|
||||||
|
|
@ -19,6 +22,10 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account
|
||||||
: base(client, externalLogin, context)
|
: base(client, externalLogin, context)
|
||||||
{
|
{
|
||||||
_emailForm = HtmlAssert.HasForm(Document);
|
_emailForm = HtmlAssert.HasForm(Document);
|
||||||
|
var title = externalLogin.GetElementsByTagName("h4").FirstOrDefault(e => e.TextContent.StartsWith("Associate your"));
|
||||||
|
Assert.Equal("Associate your Contoso auth account.", title?.TextContent);
|
||||||
|
var info = externalLogin.QuerySelectorAll<IHtmlParagraphElement>(".text-info").FirstOrDefault(e => e.TextContent.Trim().StartsWith("You've successfully authenticated"));
|
||||||
|
Assert.StartsWith("You've successfully authenticated with Contoso auth.", info?.TextContent.Trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Index> SendEmailAsync(string email)
|
public async Task<Index> SendEmailAsync(string email)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
using System.Net.Http;
|
||||||
|
using AngleSharp.Dom.Html;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account.Manage
|
||||||
|
{
|
||||||
|
public class ExternalLogins : DefaultUIPage
|
||||||
|
{
|
||||||
|
public ExternalLogins(HttpClient client, IHtmlDocument externalLoginDocument, DefaultUIContext context)
|
||||||
|
: base(client, externalLoginDocument, context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -122,5 +122,13 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests.Account.Manage
|
||||||
|
|
||||||
return new LinkExternalLogin(Client, externalLoginDocument, Context);
|
return new LinkExternalLogin(Client, externalLoginDocument, Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ExternalLogins> ClickExternalLoginsAsync()
|
||||||
|
{
|
||||||
|
var goToExternalLogin = await Client.GetAsync(_externalLoginLink.Href);
|
||||||
|
var externalLoginDocument = await ResponseAssert.IsHtmlDocumentAsync(goToExternalLogin);
|
||||||
|
|
||||||
|
return new ExternalLogins(Client, externalLoginDocument, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,6 @@ namespace Identity.DefaultUI.WebSite
|
||||||
public static class ContosoAuthenticationConstants
|
public static class ContosoAuthenticationConstants
|
||||||
{
|
{
|
||||||
public const string Scheme = "Contoso";
|
public const string Scheme = "Contoso";
|
||||||
public const string DisplayName = "Contoso";
|
public const string DisplayName = "Contoso auth";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue