aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Server.Integration.Tests/AuthHelper.cs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Jellyfin.Server.Integration.Tests/AuthHelper.cs')
-rw-r--r--tests/Jellyfin.Server.Integration.Tests/AuthHelper.cs34
1 files changed, 16 insertions, 18 deletions
diff --git a/tests/Jellyfin.Server.Integration.Tests/AuthHelper.cs b/tests/Jellyfin.Server.Integration.Tests/AuthHelper.cs
index 3737fee0a..4e8aec9f1 100644
--- a/tests/Jellyfin.Server.Integration.Tests/AuthHelper.cs
+++ b/tests/Jellyfin.Server.Integration.Tests/AuthHelper.cs
@@ -15,41 +15,41 @@ namespace Jellyfin.Server.Integration.Tests
{
public static class AuthHelper
{
- public const string AuthHeaderName = "X-Emby-Authorization";
- public const string DummyAuthHeader = "MediaBrowser Client=\"Jellyfin.Server Integration Tests\", DeviceId=\"69420\", Device=\"Apple II\", Version=\"10.8.0\"";
+ public const string AuthHeaderName = "Authorization";
+ public const string DummyAuthHeader = "MediaBrowser Client=\"Jellyfin.Server%20Integration%20Tests\", DeviceId=\"69420\", Device=\"Apple%20II\", Version=\"10.8.0\"";
public static async Task<string> CompleteStartupAsync(HttpClient client)
{
var jsonOptions = JsonDefaults.Options;
- var userResponse = await client.GetByteArrayAsync("/Startup/User").ConfigureAwait(false);
+ var userResponse = await client.GetByteArrayAsync("/Startup/User");
var user = JsonSerializer.Deserialize<StartupUserDto>(userResponse, jsonOptions);
- using var completeResponse = await client.PostAsync("/Startup/Complete", new ByteArrayContent(Array.Empty<byte>())).ConfigureAwait(false);
+ using var completeResponse = await client.PostAsync("/Startup/Complete", new ByteArrayContent(Array.Empty<byte>()));
Assert.Equal(HttpStatusCode.NoContent, completeResponse.StatusCode);
- using var content = JsonContent.Create(
+ using var httpRequest = new HttpRequestMessage(HttpMethod.Post, "/Users/AuthenticateByName");
+ httpRequest.Headers.TryAddWithoutValidation(AuthHeaderName, DummyAuthHeader);
+ httpRequest.Content = JsonContent.Create(
new AuthenticateUserByName()
{
Username = user!.Name,
Pw = user.Password,
},
options: jsonOptions);
- content.Headers.Add("X-Emby-Authorization", DummyAuthHeader);
- using var authResponse = await client.PostAsync("/Users/AuthenticateByName", content).ConfigureAwait(false);
- var auth = await JsonSerializer.DeserializeAsync<AuthenticationResultDto>(
- await authResponse.Content.ReadAsStreamAsync().ConfigureAwait(false),
- jsonOptions).ConfigureAwait(false);
+ using var authResponse = await client.SendAsync(httpRequest);
+ authResponse.EnsureSuccessStatusCode();
+
+ var auth = await authResponse.Content.ReadFromJsonAsync<AuthenticationResultDto>(jsonOptions);
return auth!.AccessToken;
}
public static async Task<UserDto> GetUserDtoAsync(HttpClient client)
{
- using var response = await client.GetAsync("Users/Me").ConfigureAwait(false);
+ using var response = await client.GetAsync("Users/Me");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- var userDto = await JsonSerializer.DeserializeAsync<UserDto>(
- await response.Content.ReadAsStreamAsync().ConfigureAwait(false), JsonDefaults.Options).ConfigureAwait(false);
+ var userDto = await response.Content.ReadFromJsonAsync<UserDto>(JsonDefaults.Options);
Assert.NotNull(userDto);
return userDto;
}
@@ -58,15 +58,13 @@ namespace Jellyfin.Server.Integration.Tests
{
if (userId.Equals(default))
{
- var userDto = await GetUserDtoAsync(client).ConfigureAwait(false);
+ var userDto = await GetUserDtoAsync(client);
userId = userDto.Id;
}
- var response = await client.GetAsync($"Users/{userId}/Items/Root").ConfigureAwait(false);
+ var response = await client.GetAsync($"Users/{userId}/Items/Root");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- var rootDto = await JsonSerializer.DeserializeAsync<BaseItemDto>(
- await response.Content.ReadAsStreamAsync().ConfigureAwait(false),
- JsonDefaults.Options).ConfigureAwait(false);
+ var rootDto = await response.Content.ReadFromJsonAsync<BaseItemDto>(JsonDefaults.Options);
Assert.NotNull(rootDto);
return rootDto;
}