testing
This commit is contained in:
@ -1,11 +1,6 @@
|
|||||||
// // YavscWorkInProgress.cs
|
using isnd.tests;
|
||||||
// /*
|
|
||||||
// paul 21/06/2018 10:11 20182018 6 21
|
|
||||||
// */
|
|
||||||
using System.Net;
|
|
||||||
using isnd.tests;
|
|
||||||
using Xunit;
|
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
using IdentityModel.Client;
|
||||||
|
|
||||||
namespace yavscTests
|
namespace yavscTests
|
||||||
{
|
{
|
||||||
@ -27,45 +22,72 @@ namespace yavscTests
|
|||||||
string password
|
string password
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ObtainServiceToken()
|
||||||
|
{
|
||||||
|
var serverUrl = _serverFixture.Addresses.FirstOrDefault(
|
||||||
|
u => u.StartsWith("https:")
|
||||||
|
);
|
||||||
|
|
||||||
|
String authority = _serverFixture.SiteSettings.Authority;
|
||||||
|
var client = new HttpClient();
|
||||||
|
var disco = await client.GetDiscoveryDocumentAsync(authority);
|
||||||
|
if (disco.IsError) throw new Exception(disco.Error);
|
||||||
|
|
||||||
|
var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
|
||||||
{
|
{
|
||||||
var serverUrl = _serverFixture.Addresses.FirstOrDefault(
|
Address = disco.TokenEndpoint,
|
||||||
u => u.StartsWith("https:")
|
|
||||||
);
|
|
||||||
|
|
||||||
String auth = _serverFixture.SiteSettings.Authority;
|
ClientId = "m2m.client", // _serverFixture.TestClientId,
|
||||||
|
ClientSecret = "511536EF-F270-4058-80CA-1C89C192F69A" //_serverFixture.TestClientSecret,
|
||||||
|
});
|
||||||
|
/*"mvc";
|
||||||
|
options.ClientSecret = "49C1A7E1-0C79-4A89-A3D6-A37998FB86B0";*/
|
||||||
|
if (response.IsError) throw new Exception(response.Error);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
var query = new Dictionary<string, string>
|
[Fact]
|
||||||
|
public async Task ObtainResourceOwnerPasswordToken()
|
||||||
|
{
|
||||||
|
var serverUrl = _serverFixture.Addresses.FirstOrDefault(
|
||||||
|
u => u.StartsWith("https:")
|
||||||
|
);
|
||||||
|
|
||||||
|
String authority = _serverFixture.SiteSettings.Authority;
|
||||||
|
var client = new HttpClient();
|
||||||
|
var disco = await client.GetDiscoveryDocumentAsync(authority);
|
||||||
|
if (disco.IsError) throw new Exception(disco.Error);
|
||||||
|
|
||||||
|
var response = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
|
||||||
|
{
|
||||||
|
Address = disco.TokenEndpoint,
|
||||||
|
|
||||||
|
ClientId = "m2m.client",
|
||||||
|
ClientSecret = "511536EF-F270-4058-80CA-1C89C192F69A",
|
||||||
|
|
||||||
|
UserName = _serverFixture.TestingUserName,
|
||||||
|
Password = _serverFixture.TestingUserPassword,
|
||||||
|
|
||||||
|
Scope = "scope1",
|
||||||
|
|
||||||
|
Parameters =
|
||||||
{
|
{
|
||||||
["Username"] = userName,
|
{ "acr_values", "tenant:custom_account_store1 foo bar quux" }
|
||||||
["Password"] = password,
|
}
|
||||||
["GrantType"] = "password"
|
});
|
||||||
};
|
|
||||||
|
|
||||||
throw new NotImplementedException();
|
if (response.IsError) throw new Exception(response.Error);
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
var webex = ex as WebException;
|
|
||||||
if (webex != null)
|
|
||||||
{
|
|
||||||
if (webex.Status == WebExceptionStatus.ProtocolError)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> GetLoginIntentData()
|
public static IEnumerable<object[]> GetLoginIntentData()
|
||||||
{
|
{
|
||||||
return new object[][] { new object[] { "testuser", "test" } };
|
return new object[][] { new object[] { "testuser", "test" } };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,9 @@ using Yavsc.Extensions;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
|
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
|
||||||
using Yavsc.Models.Auth;
|
using Yavsc.Models.Auth;
|
||||||
|
using Serilog;
|
||||||
|
using Serilog.Events;
|
||||||
|
using Serilog.Sinks.SystemConsole.Themes;
|
||||||
|
|
||||||
namespace isnd.tests
|
namespace isnd.tests
|
||||||
{
|
{
|
||||||
@ -37,6 +40,8 @@ namespace isnd.tests
|
|||||||
|
|
||||||
public IServiceProvider Services { get; private set; }
|
public IServiceProvider Services { get; private set; }
|
||||||
public string TestingUserName { get; private set; }
|
public string TestingUserName { get; private set; }
|
||||||
|
public string TestingUserPassword { get; private set; }
|
||||||
|
|
||||||
public string ProtectedTestingApiKey { get; internal set; }
|
public string ProtectedTestingApiKey { get; internal set; }
|
||||||
public ApplicationUser TestingUser { get; private set; }
|
public ApplicationUser TestingUser { get; private set; }
|
||||||
public bool DbCreated { get; internal set; }
|
public bool DbCreated { get; internal set; }
|
||||||
@ -54,11 +59,27 @@ namespace isnd.tests
|
|||||||
if (app!=null)
|
if (app!=null)
|
||||||
app.StopAsync().Wait();
|
app.StopAsync().Wait();
|
||||||
}
|
}
|
||||||
|
void ConfigureLogger() => Log.Logger = new LoggerConfiguration()
|
||||||
|
.MinimumLevel.Debug()
|
||||||
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
|
||||||
|
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
|
||||||
|
.MinimumLevel.Override("System", LogEventLevel.Warning)
|
||||||
|
.MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
|
||||||
|
.Enrich.FromLogContext()
|
||||||
|
// uncomment to write to Azure diagnostics stream
|
||||||
|
//.WriteTo.File(
|
||||||
|
// @"D:\home\LogFiles\Application\identityserver.txt",
|
||||||
|
// fileSizeLimitBytes: 1_000_000,
|
||||||
|
// rollOnFileSizeLimit: true,
|
||||||
|
// shared: true,
|
||||||
|
// flushToDiskInterval: TimeSpan.FromSeconds(1))
|
||||||
|
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
|
||||||
|
.CreateLogger();
|
||||||
public async Task SetupHost()
|
public async Task SetupHost()
|
||||||
{
|
{
|
||||||
var builder = WebApplication.CreateBuilder();
|
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder();
|
||||||
|
ConfigureLogger();
|
||||||
Configuration = builder.Configuration
|
Configuration = builder.Configuration
|
||||||
.AddJsonFile("appsettings.json")
|
.AddJsonFile("appsettings.json")
|
||||||
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
|
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
|
||||||
@ -98,9 +119,10 @@ namespace isnd.tests
|
|||||||
dbContext.Database.Migrate();
|
dbContext.Database.Migrate();
|
||||||
|
|
||||||
TestingUserName = "Tester";
|
TestingUserName = "Tester";
|
||||||
|
TestingUserPassword = "test";
|
||||||
TestClientId = "testClientId";
|
TestClientId = "testClientId";
|
||||||
TestingUser = await dbContext.Users.FirstOrDefaultAsync(u => u.UserName == TestingUserName);
|
TestingUser = await dbContext.Users.FirstOrDefaultAsync(u => u.UserName == TestingUserName);
|
||||||
EnsureUser(TestingUserName);
|
EnsureUser(TestingUserName, TestingUserPassword);
|
||||||
// ensure a client
|
// ensure a client
|
||||||
var testClient = await dbContext.Client.FirstOrDefaultAsync((c) => c.Id == TestClientId);
|
var testClient = await dbContext.Client.FirstOrDefaultAsync((c) => c.Id == TestClientId);
|
||||||
if (testClient == null)
|
if (testClient == null)
|
||||||
@ -129,7 +151,7 @@ namespace isnd.tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnsureUser(string testingUserName)
|
public void EnsureUser(string testingUserName, string password)
|
||||||
{
|
{
|
||||||
if (TestingUser == null)
|
if (TestingUser == null)
|
||||||
{
|
{
|
||||||
@ -145,7 +167,7 @@ namespace isnd.tests
|
|||||||
EmailConfirmed = true
|
EmailConfirmed = true
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = userManager.CreateAsync(TestingUser,"test").Result;
|
var result = userManager.CreateAsync(TestingUser,password).Result;
|
||||||
|
|
||||||
Assert.True(result.Succeeded);
|
Assert.True(result.Succeeded);
|
||||||
|
|
||||||
|
@ -12,15 +12,16 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||||
|
<PackageReference Include="IdentityModel.OidcClient" />
|
||||||
<PackageReference Include="Selenium.WebDriver" />
|
<PackageReference Include="Selenium.WebDriver" />
|
||||||
<PackageReference Include="xunit" />
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" />
|
<PackageReference Include="Microsoft.AspNetCore.Hosting" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
|
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" />
|
<PackageReference Include="Microsoft.Extensions.Options" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
|
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
|
||||||
<PackageReference Include="Microsoft.Playwright" />
|
<PackageReference Include="Microsoft.Playwright" />
|
||||||
<PackageReference Include="Newtonsoft.Json" />
|
<PackageReference Include="Newtonsoft.Json" />
|
||||||
|
<PackageReference Include="xunit" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Yavsc\Yavsc.csproj" />
|
<ProjectReference Include="..\..\src\Yavsc\Yavsc.csproj" />
|
||||||
@ -30,4 +31,4 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Using Include="Xunit" />
|
<Using Include="Xunit" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
Reference in New Issue
Block a user