-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into km/userkey-rotation-v2
- Loading branch information
Showing
17 changed files
with
328 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/Events.IntegrationTest/Controllers/CollectControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Net.Http.Json; | ||
using Bit.Core.Enums; | ||
using Bit.Events.Models; | ||
|
||
namespace Bit.Events.IntegrationTest.Controllers; | ||
|
||
public class CollectControllerTests | ||
{ | ||
// This is a very simple test, and should be updated to assert more things, but for now | ||
// it ensures that the events startup doesn't throw any errors with fairly basic configuration. | ||
[Fact] | ||
public async Task Post_Works() | ||
{ | ||
var eventsApplicationFactory = new EventsApplicationFactory(); | ||
var (accessToken, _) = await eventsApplicationFactory.LoginWithNewAccount(); | ||
var client = eventsApplicationFactory.CreateAuthedClient(accessToken); | ||
|
||
var response = await client.PostAsJsonAsync<IEnumerable<EventModel>>("collect", | ||
[ | ||
new EventModel | ||
{ | ||
Type = EventType.User_ClientExportedVault, | ||
Date = DateTime.UtcNow, | ||
}, | ||
]); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<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="$(MicrosoftNetTestSdkVersion)" /> | ||
<PackageReference Include="xunit" Version="$(XUnitVersion)" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioVersion)"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Events\Events.csproj" /> | ||
<ProjectReference Include="..\IntegrationTestCommon\IntegrationTestCommon.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Bit.Identity.Models.Request.Accounts; | ||
using Bit.IntegrationTestCommon.Factories; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Data.Sqlite; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Bit.Events.IntegrationTest; | ||
|
||
public class EventsApplicationFactory : WebApplicationFactoryBase<Startup> | ||
{ | ||
private readonly IdentityApplicationFactory _identityApplicationFactory; | ||
private const string _connectionString = "DataSource=:memory:"; | ||
|
||
public EventsApplicationFactory() | ||
{ | ||
SqliteConnection = new SqliteConnection(_connectionString); | ||
SqliteConnection.Open(); | ||
|
||
_identityApplicationFactory = new IdentityApplicationFactory(); | ||
_identityApplicationFactory.SqliteConnection = SqliteConnection; | ||
} | ||
|
||
protected override void ConfigureWebHost(IWebHostBuilder builder) | ||
{ | ||
base.ConfigureWebHost(builder); | ||
|
||
builder.ConfigureTestServices(services => | ||
{ | ||
services.Configure<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme, options => | ||
{ | ||
options.BackchannelHttpHandler = _identityApplicationFactory.Server.CreateHandler(); | ||
}); | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Helper for registering and logging in to a new account | ||
/// </summary> | ||
public async Task<(string Token, string RefreshToken)> LoginWithNewAccount(string email = "[email protected]", string masterPasswordHash = "master_password_hash") | ||
{ | ||
await _identityApplicationFactory.RegisterAsync(new RegisterRequestModel | ||
{ | ||
Email = email, | ||
MasterPasswordHash = masterPasswordHash, | ||
}); | ||
|
||
return await _identityApplicationFactory.TokenFromPasswordAsync(email, masterPasswordHash); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
SqliteConnection!.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.