Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
"description": "Dependencies used in test projects",
"commitMessagePrefix": "[deps] Test:",
"matchPackageNames": [
"coverlet.collector",
"Microsoft.Testing.Extensions.CodeCoverage",
"Microsoft.AspNetCore.TestHost",
"Microsoft.NET.Test.Sdk",
"NSubstitute",
"xunit",
"xunit.v3",
"xunit.runner.visualstudio",
"Testcontainers",
"MSBuild.ProjectCreation",
"Microsoft.Extensions.Diagnostics.Testing"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0

- name: Test solution
run: dotnet test --configuration Debug --logger "trx;LogFileName=test-results.trx" /p:CoverletOutputFormatter="cobertura" --collect:"XPlat Code Coverage"
run: dotnet test --configuration Debug -- --coverage --coverage-output-format cobertura --coverage-output "coverage.cobertura.xml" --report-xunit-trx --report-xunit-trx-filename "test-results.trx"

- name: Report test results
uses: dorny/test-reporter@dc3a92680fcc15842eef52e8c4606ea7ce6bd3f3 # v2.1.1
Expand Down
6 changes: 1 addition & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ See the [README.md](README.md) for detailed information about each package. Main

### Test Framework

- **xUnit**
- `Microsoft.NET.Test.Sdk`
- `coverlet.collector` for code coverage
- **xUnit.v3**

### Additional Test Tools

- `xunit.runner.visualstudio`
- `NSubstitute` for mocking
- `Microsoft.AspNetCore.TestHost` for integration tests
- `Testcontainers` for container-based tests
Expand All @@ -40,7 +37,6 @@ See the [README.md](README.md) for detailed information about each package. Main

- Test projects are in `tests/` subfolder of each extension
- Test projects use exact version pinning: `Version="[X.Y.Z]"`
- `<IsPackable>false</IsPackable>` and `<IsTestProject>true</IsTestProject>` properties
- `<Using Include="Xunit" />` for global xUnit usings

## Code Style and Conventions
Expand Down
12 changes: 12 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>
<PropertyGroup>
<IsTestProject Condition="'$(IsTestProject)' == '' and ($(MSBuildProjectName.EndsWith('.Tests')) or $(MSBuildProjectName.EndsWith('.IntegrationTests')))">true</IsTestProject>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<OutputType Condition="'$(OutputType)' == ''">Exe</OutputType>
<IsPackable Condition="'$(IsPackable)' == ''">false</IsPackable>
<TestingPlatformDotnetTestSupport Condition="'$(TestingPlatformDotnetTestSupport)' == ''">true</TestingPlatformDotnetTestSupport>
<UseMicrosoftTestingPlatformRunner Condition="'$(UseMicrosoftTestingPlatformRunner)' == ''">true</UseMicrosoftTestingPlatformRunner>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions extensions/Bitwarden.Core/src/Bitwarden.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<IsPackable>true</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>

<PropertyGroup>
Expand Down
15 changes: 2 additions & 13 deletions extensions/Bitwarden.Core/tests/Bitwarden.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,11 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[17.14.1]" />
<PackageReference Include="xunit" Version="[2.9.3]" />
<PackageReference Include="xunit.runner.visualstudio" Version="[3.1.5]">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="[6.0.4]">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="[18.0.4]" />
<PackageReference Include="xunit.v3" Version="[3.1.0]" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<!-- This project will not run any tests unless a debugger is attached, so ignore the exit code that fails if 0 tests run -->
<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --ignore-exit-code 8</TestingPlatformCommandLineArguments>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="[7.0.0]" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[17.14.1]" />
<PackageReference Include="xunit" Version="[2.9.3]" />
<PackageReference Include="xunit.runner.visualstudio" Version="[3.1.5]">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="[6.0.4]">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="[18.0.4]" />
<PackageReference Include="xunit.v3" Version="[3.1.0]" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System.Diagnostics;

namespace Bitwarden.Extensions.Configuration.Tests;

public class DebuggerFactAttribute : FactAttribute
{
public DebuggerFactAttribute()
{
if (!Debugger.IsAttached)
{
Skip = "This test can only be ran while a debugger is attached.";
}
}
}
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace Bitwarden.Extensions.Configuration.Tests;

public class DebuggerFactAttribute : FactAttribute
{
public DebuggerFactAttribute([CallerFilePath] string? sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = -1)
: base(sourceFilePath, sourceLineNumber)
{
if (!Debugger.IsAttached)
{
Skip = "This test can only be ran while a debugger is attached.";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using Xunit.Abstractions;

namespace Bitwarden.Server.Sdk.Authentication.Tests;

Expand All @@ -33,13 +32,13 @@ public AuthenticationServiceCollectionExtensionsTests(ITestOutputHelper testOutp
public async Task AddBitwardenAuthentication_NoBearerToken_Unauthorized()
{
using var authHost = CreateAuthHost(out _);
await authHost.StartAsync();
await authHost.StartAsync(TestContext.Current.CancellationToken);
using var appHost = CreateAppHost(authHost);
await appHost.StartAsync();
await appHost.StartAsync(TestContext.Current.CancellationToken);

var client = appHost.GetTestClient();

var response = await client.GetAsync("/authed-user");
var response = await client.GetAsync("/authed-user", TestContext.Current.CancellationToken);

Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}
Expand All @@ -48,17 +47,17 @@ public async Task AddBitwardenAuthentication_NoBearerToken_Unauthorized()
public async Task AddBitwardenAuthentication_QueryString_DoesNotWork()
{
using var authHost = CreateAuthHost(out var certificate);
await authHost.StartAsync();
await authHost.StartAsync(TestContext.Current.CancellationToken);
using var appHost = CreateAppHost(authHost);

await appHost.StartAsync();
await appHost.StartAsync(TestContext.Current.CancellationToken);

var client = appHost.GetTestClient();

var accessToken = CreateAccessToken(certificate,
new JwtPayload(issuer: "http://localhost", audience: null, claims: null, notBefore: DateTime.UtcNow, expires: DateTime.UtcNow.AddDays(1)));

var response = await client.GetAsync($"/authed-user?access_token={accessToken}");
var response = await client.GetAsync($"/authed-user?access_token={accessToken}", TestContext.Current.CancellationToken);

Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}
Expand All @@ -67,10 +66,10 @@ public async Task AddBitwardenAuthentication_QueryString_DoesNotWork()
public async Task AddBitwardenAuthentication_Header_Works()
{
using var authHost = CreateAuthHost(out var certificate);
await authHost.StartAsync();
await authHost.StartAsync(TestContext.Current.CancellationToken);
using var appHost = CreateAppHost(authHost);

await appHost.StartAsync();
await appHost.StartAsync(TestContext.Current.CancellationToken);

var client = appHost.GetTestClient();

Expand All @@ -80,7 +79,7 @@ public async Task AddBitwardenAuthentication_Header_Works()
var request = new HttpRequestMessage(HttpMethod.Get, "/authed-user");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

var response = await client.SendAsync(request);
var response = await client.SendAsync(request, TestContext.Current.CancellationToken);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
Expand All @@ -89,7 +88,7 @@ public async Task AddBitwardenAuthentication_Header_Works()
public async Task AddBitwardenAuthentication_DoesNotMapClaims()
{
using var authHost = CreateAuthHost(out var certificate);
await authHost.StartAsync();
await authHost.StartAsync(TestContext.Current.CancellationToken);

using var appHost = CreateAppHost(authHost, configureServices: null,
endpoints =>
Expand All @@ -105,7 +104,7 @@ public async Task AddBitwardenAuthentication_DoesNotMapClaims()
}
);

await appHost.StartAsync();
await appHost.StartAsync(TestContext.Current.CancellationToken);

var client = appHost.GetTestClient();

Expand All @@ -116,17 +115,17 @@ public async Task AddBitwardenAuthentication_DoesNotMapClaims()

var request = new HttpRequestMessage(HttpMethod.Get, "/test");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var response = await client.SendAsync(request);
var response = await client.SendAsync(request, TestContext.Current.CancellationToken);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("test", await response.Content.ReadAsStringAsync());
Assert.Equal("test", await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken));
}

[Fact]
public async Task AddBitwardenAuthentication_UsesEmailForNameClaimType()
{
using var authHost = CreateAuthHost(out var certificate);
await authHost.StartAsync();
await authHost.StartAsync(TestContext.Current.CancellationToken);

using var appHost = CreateAppHost(authHost, configureServices: null,
endpoints =>
Expand All @@ -139,7 +138,7 @@ public async Task AddBitwardenAuthentication_UsesEmailForNameClaimType()
}
);

await appHost.StartAsync();
await appHost.StartAsync(TestContext.Current.CancellationToken);

var client = appHost.GetTestClient();

Expand All @@ -150,17 +149,17 @@ public async Task AddBitwardenAuthentication_UsesEmailForNameClaimType()

var request = new HttpRequestMessage(HttpMethod.Get, "/test");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var response = await client.SendAsync(request);
var response = await client.SendAsync(request, TestContext.Current.CancellationToken);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("[email protected]", await response.Content.ReadAsStringAsync());
Assert.Equal("[email protected]", await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken));
}

[Fact]
public async Task AddBitwardenAuthentication_LogInEndpoint_ContainsScope()
{
using var authHost = CreateAuthHost(out var certificate);
await authHost.StartAsync();
await authHost.StartAsync(TestContext.Current.CancellationToken);

using var appHost = CreateAppHost(authHost, configureServices: null,
endpoints =>
Expand All @@ -172,7 +171,7 @@ public async Task AddBitwardenAuthentication_LogInEndpoint_ContainsScope()
}
);

await appHost.StartAsync();
await appHost.StartAsync(TestContext.Current.CancellationToken);

var client = appHost.GetTestClient();

Expand All @@ -183,7 +182,7 @@ public async Task AddBitwardenAuthentication_LogInEndpoint_ContainsScope()

var request = new HttpRequestMessage(HttpMethod.Get, "/test");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var response = await client.SendAsync(request);
var response = await client.SendAsync(request, TestContext.Current.CancellationToken);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<RootNamespace>Bitwarden.Server.Sdk.Authentication.Tests</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
Expand All @@ -13,12 +12,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="[6.0.4]" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[17.14.1]" />
<PackageReference Include="xunit" Version="[2.9.3]" />
<PackageReference Include="xunit.runner.visualstudio" Version="[3.1.5]" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="[18.0.4]" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="[8.0.20]" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.Testing" Version="[9.9.0]" />
<PackageReference Include="xunit.v3" Version="[3.1.0]" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="[6.0.4]" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="[18.0.4]" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="[8.0.20]" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[17.14.1]" />
<PackageReference Include="NSubstitute" Version="[5.3.0]" />
<PackageReference Include="xunit" Version="[2.9.3]" />
<PackageReference Include="xunit.runner.visualstudio" Version="[3.1.5]" />
<PackageReference Include="xunit.v3" Version="[3.1.0]" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading