Browse Source
* Use all organization memberships for LaunchDarkly context * Use simpler null check Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com> * Remove unnecessary interpolation Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com> * Remove unnecessary interpolation Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com> * Fully spell out organizations * Use client type for context separation decisions --------- Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com>pull/2817/head
2 changed files with 93 additions and 20 deletions
@ -1,30 +1,79 @@ |
|||||||
using System.Net.Http.Headers; |
using System.Net.Http.Headers; |
||||||
using Bit.Api.IntegrationTest.Factories; |
using Bit.Api.IntegrationTest.Factories; |
||||||
|
using Bit.Api.IntegrationTest.Helpers; |
||||||
using Bit.Api.Models.Response; |
using Bit.Api.Models.Response; |
||||||
|
using Bit.Core.Entities; |
||||||
using Xunit; |
using Xunit; |
||||||
|
|
||||||
namespace Bit.Api.IntegrationTest.Controllers; |
namespace Bit.Api.IntegrationTest.Controllers; |
||||||
|
|
||||||
public class ConfigControllerTests : IClassFixture<ApiApplicationFactory> |
public class ConfigControllerTests : IClassFixture<ApiApplicationFactory>, IAsyncLifetime |
||||||
{ |
{ |
||||||
|
private readonly HttpClient _client; |
||||||
private readonly ApiApplicationFactory _factory; |
private readonly ApiApplicationFactory _factory; |
||||||
|
|
||||||
public ConfigControllerTests(ApiApplicationFactory factory) => _factory = factory; |
private string _email = null!; |
||||||
|
|
||||||
|
public ConfigControllerTests(ApiApplicationFactory factory) |
||||||
|
{ |
||||||
|
_factory = factory; |
||||||
|
_client = _factory.CreateClient(); |
||||||
|
} |
||||||
|
|
||||||
|
public async Task InitializeAsync() |
||||||
|
{ |
||||||
|
_email = $"integration-test{Guid.NewGuid()}@bitwarden.com"; |
||||||
|
|
||||||
|
var tokens = await _factory.LoginWithNewAccount(_email); |
||||||
|
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token); |
||||||
|
} |
||||||
|
|
||||||
|
public Task DisposeAsync() |
||||||
|
{ |
||||||
|
_client.Dispose(); |
||||||
|
return Task.CompletedTask; |
||||||
|
} |
||||||
|
|
||||||
|
private async Task LoginAsync() |
||||||
|
{ |
||||||
|
var tokens = await _factory.LoginAsync(_email); |
||||||
|
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token); |
||||||
|
} |
||||||
|
|
||||||
[Fact] |
[Fact] |
||||||
public async Task GetConfigs() |
public async Task GetConfigs() |
||||||
{ |
{ |
||||||
var tokens = await _factory.LoginWithNewAccount(); |
var response = await _client.GetAsync("/config"); |
||||||
var client = _factory.CreateClient(); |
response.EnsureSuccessStatusCode(); |
||||||
|
var result = await response.Content.ReadFromJsonAsync<ConfigResponseModel>(); |
||||||
|
|
||||||
|
Assert.NotNull(result); |
||||||
|
Assert.NotEmpty(result!.Version); |
||||||
|
} |
||||||
|
|
||||||
|
[Theory] |
||||||
|
[InlineData(1)] |
||||||
|
[InlineData(3)] |
||||||
|
public async Task GetConfigs_WithOrganizations(int orgCount) |
||||||
|
{ |
||||||
|
for (var i = 0; i < orgCount; i++) |
||||||
|
{ |
||||||
|
var ownerEmail = $"integration-test{Guid.NewGuid()}@bitwarden.com"; |
||||||
|
await _factory.LoginWithNewAccount(ownerEmail); |
||||||
|
|
||||||
using var message = new HttpRequestMessage(HttpMethod.Get, "/config"); |
Organization org; |
||||||
message.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token); |
(org, _) = await OrganizationTestHelpers.SignUpAsync(_factory, plan: Core.Enums.PlanType.Free, ownerEmail: ownerEmail, |
||||||
var response = await client.SendAsync(message); |
name: i.ToString(), billingEmail: ownerEmail, ownerKey: i.ToString()); |
||||||
|
await OrganizationTestHelpers.CreateUserAsync(_factory, org.Id, _email, Core.Enums.OrganizationUserType.User); |
||||||
|
} |
||||||
|
|
||||||
response.EnsureSuccessStatusCode(); |
await LoginAsync(); |
||||||
|
|
||||||
var content = await response.Content.ReadFromJsonAsync<ConfigResponseModel>(); |
var response = await _client.GetAsync("/config"); |
||||||
|
response.EnsureSuccessStatusCode(); |
||||||
|
var result = await response.Content.ReadFromJsonAsync<ConfigResponseModel>(); |
||||||
|
|
||||||
Assert.NotEmpty(content!.Version); |
Assert.NotNull(result); |
||||||
|
Assert.NotEmpty(result!.Version); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue