squash a bunch of commits
This commit is contained in:
25
Tests/AcceptanceTests/AcceptanceTests.cs
Normal file
25
Tests/AcceptanceTests/AcceptanceTests.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Shogi.AcceptanceTests.TestSetup;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Shogi.AcceptanceTests;
|
||||
|
||||
public class AcceptanceTests : IClassFixture<MsalTestFixture>
|
||||
{
|
||||
private readonly MsalTestFixture fixture;
|
||||
private readonly ITestOutputHelper console;
|
||||
|
||||
public AcceptanceTests(MsalTestFixture fixture, ITestOutputHelper console)
|
||||
{
|
||||
this.fixture = fixture;
|
||||
this.console = console;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateAndReadSession()
|
||||
{
|
||||
var response = await fixture.Service.GetAsync(new Uri("Game", UriKind.Relative));
|
||||
console.WriteLine(await response.Content.ReadAsStringAsync());
|
||||
console.WriteLine(response.Headers.WwwAuthenticate.ToString());
|
||||
response.IsSuccessStatusCode.Should().BeTrue(because: "AAT Client should be authorized.");
|
||||
}
|
||||
}
|
||||
44
Tests/AcceptanceTests/AcceptanceTests.csproj
Normal file
44
Tests/AcceptanceTests/AcceptanceTests.csproj
Normal file
@@ -0,0 +1,44 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<UserSecretsId>96d6281d-a75b-4181-b535-ea34b26dc8a2</UserSecretsId>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.7.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Identity.Client" Version="4.46.1" />
|
||||
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.8" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
76
Tests/AcceptanceTests/TestSetup/MsalTestFixture - Copy.cs
Normal file
76
Tests/AcceptanceTests/TestSetup/MsalTestFixture - Copy.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Identity.Client;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace Shogi.AcceptanceTests.TestSetup
|
||||
{
|
||||
/// <summary>
|
||||
/// Acceptance Test fixture for tests which assert features for Microsoft accounts.
|
||||
/// </summary>
|
||||
public class GuestTestFixture : IAsyncLifetime, IDisposable
|
||||
{
|
||||
private bool disposedValue;
|
||||
private readonly IConfidentialClientApplication app;
|
||||
|
||||
public GuestTestFixture()
|
||||
{
|
||||
Configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json")
|
||||
//.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
Service = new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(Configuration["ServiceUrl"], UriKind.Absolute)
|
||||
};
|
||||
|
||||
|
||||
publicApp = PublicClientApplicationBuilder
|
||||
.Create(azure["ClientId"])
|
||||
.WithTenantId("common")
|
||||
.Build();
|
||||
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; private set; }
|
||||
|
||||
|
||||
public HttpClient Service { get; }
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
var scopes = Configuration.GetSection("Auth:Scopes").Get<string[]>();
|
||||
var authResult = await app
|
||||
.AcquireTokenForClient(scopes)
|
||||
.ExecuteAsync();
|
||||
|
||||
authResult.Should().NotBeNull();
|
||||
authResult.AccessToken.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Service.Dispose();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Task DisposeAsync()
|
||||
{
|
||||
Dispose(true);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
100
Tests/AcceptanceTests/TestSetup/MsalTestFixture.cs
Normal file
100
Tests/AcceptanceTests/TestSetup/MsalTestFixture.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Identity.Client;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace Shogi.AcceptanceTests.TestSetup
|
||||
{
|
||||
/// <summary>
|
||||
/// Acceptance Test fixture for tests which assert features for Microsoft accounts.
|
||||
/// </summary>
|
||||
public class MsalTestFixture : IAsyncLifetime, IDisposable
|
||||
{
|
||||
private bool disposedValue;
|
||||
private readonly IConfidentialClientApplication app;
|
||||
|
||||
public MsalTestFixture()
|
||||
{
|
||||
Configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddEnvironmentVariables()
|
||||
.AddUserSecrets<MsalTestFixture>()
|
||||
.Build();
|
||||
|
||||
var azure = Configuration.GetSection("Auth");
|
||||
app = ConfidentialClientApplicationBuilder
|
||||
.Create(azure["ClientId"])
|
||||
.WithTenantId(azure["TenantId"])
|
||||
.WithClientSecret(azure["SecretValue"])
|
||||
.Build();
|
||||
|
||||
Service = new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(Configuration["ServiceUrl"], UriKind.Absolute)
|
||||
};
|
||||
|
||||
|
||||
publicApp = PublicClientApplicationBuilder
|
||||
.Create(azure["ClientId"])
|
||||
.WithTenantId("common")
|
||||
.Build();
|
||||
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; private set; }
|
||||
|
||||
|
||||
public HttpClient Service { get; }
|
||||
|
||||
private IPublicClientApplication publicApp;
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
var scopes = Configuration.GetSection("Auth:Scopes").Get<string[]>();
|
||||
var authResult = await app
|
||||
.AcquireTokenForClient(scopes)
|
||||
.ExecuteAsync();
|
||||
|
||||
authResult.Should().NotBeNull();
|
||||
authResult.AccessToken.Should().NotBeNullOrEmpty();
|
||||
|
||||
Service.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
|
||||
|
||||
var accounts = await publicApp.GetAccountsAsync();
|
||||
var password = new System.Security.SecureString();
|
||||
foreach (var c in "some password")
|
||||
{
|
||||
password.AppendChar(c);
|
||||
}
|
||||
var th = await publicApp
|
||||
.AcquireTokenByIntegratedWindowsAuth(scopes)
|
||||
.ExecuteAsync();
|
||||
//var thing = await publicApp.AcquireTokenByUsernamePassword(scopes, "Need to create a test email.", password)
|
||||
//.ExecuteAsync();
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Service.Dispose();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Task DisposeAsync()
|
||||
{
|
||||
Dispose(true);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Tests/AcceptanceTests/Usings.cs
Normal file
2
Tests/AcceptanceTests/Usings.cs
Normal file
@@ -0,0 +1,2 @@
|
||||
global using Xunit;
|
||||
global using FluentAssertions;
|
||||
11
Tests/AcceptanceTests/appsettings.json
Normal file
11
Tests/AcceptanceTests/appsettings.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ServiceUrl": "https://localhost:5001",
|
||||
"Auth": {
|
||||
"TenantId": "d6019544-c403-415c-8e96-50009635b6aa",
|
||||
"ClientId": "78b12a47-440c-4cc7-9402-f573a2802951",
|
||||
"SecretValue": "REDACTED",
|
||||
"Scopes": [
|
||||
"api://c1e94676-cab0-42ba-8b6c-9532b8486fff/.default"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user