mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
[BEEEP][SM-893] Add the ability to run SM integration tests as a service account (#3187)
* Add the ability to run SM integration tests as a service account
This commit is contained in:
@ -0,0 +1,30 @@
|
||||
using System.Net.Http.Headers;
|
||||
using Bit.Api.IntegrationTest.Factories;
|
||||
using Bit.Core.SecretsManager.Models.Data;
|
||||
|
||||
namespace Bit.Api.IntegrationTest.SecretsManager.Helpers;
|
||||
|
||||
public class LoginHelper
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
private readonly ApiApplicationFactory _factory;
|
||||
|
||||
public LoginHelper(ApiApplicationFactory factory, HttpClient client)
|
||||
{
|
||||
_factory = factory;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public async Task LoginAsync(string email)
|
||||
{
|
||||
var tokens = await _factory.LoginAsync(email);
|
||||
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token);
|
||||
}
|
||||
|
||||
public async Task LoginWithApiKeyAsync(ApiKeyClientSecretDetails apiKeyDetails)
|
||||
{
|
||||
var token = await _factory.LoginWithClientSecretAsync(apiKeyDetails.ApiKey.Id, apiKeyDetails.ClientSecret);
|
||||
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
_client.DefaultRequestHeaders.Add("service_account_id", apiKeyDetails.ApiKey.ServiceAccountId.ToString());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user