26 lines
1.0 KiB
C#
26 lines
1.0 KiB
C#
using System.Net.Http.Json;
|
|||
|
|
using System.Text.Json.Nodes;
|
||
|
|
|
||
|
|
namespace decePubClient.E2E.Support
|
||
|
|
{
|
||
|
|
// PrivaPub's /clientapi as the pasture's administrator (pastureroot, whom the scenarios make): what its moderators
|
||
|
|
// and administrators see
|
||
|
|
public static class PastureAdmin
|
||
|
|
{
|
||
|
|
public const string Root = "pastureroot";
|
||
|
|
public const string Password = "Pasture-Pass-1!";
|
||
|
|
|
||
|
|
public static async Task<JsonNode> Get(string path)
|
||
|
|
{
|
||
|
|
using var http = Pasture.Http();
|
||
|
|
var login = await http.PostAsJsonAsync($"{Pasture.Api}/clientapi/user/login", new { userName = Root, password = Password });
|
||
|
|
login.EnsureSuccessStatusCode();
|
||
|
|
var jwt = (await login.Content.ReadFromJsonAsync<JsonObject>())!["token"]!.GetValue<string>();
|
||
|
|
using var request = new HttpRequestMessage(HttpMethod.Get, Pasture.Api + path);
|
||
|
|
request.Headers.Authorization = new("Bearer", jwt);
|
||
|
|
using var response = await http.SendAsync(request);
|
||
|
|
response.EnsureSuccessStatusCode();
|
||
|
|
return JsonNode.Parse(await response.Content.ReadAsStringAsync());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|