Files
ClawdDotNet/tests/ClawdDotNet.Core.Tests/Deploymentcenter/TokenProvisionerTests.cs
T
RichardandClaude Opus 5.5 837a634a22 Stufe 4c (#764): Kommentare in C#, WebUI-Skripten, CSS und HTML auf Englisch
Rund 2.600 Kommentarblöcke in 310 C#-Dateien übersetzt, Begründungen vollständig
erhalten: blockweise gleiche Anzahl wie vorher, kein Block unter 60 % seiner
Länge, der Code außerhalb der Kommentare per Tokenizer byte-identisch geprüft.
Zitate deutscher Oberflächentexte und Testdaten bleiben deutsch.

WebUI: Kommentare in JS/CSS/HTML übersetzt, JSDoc-@param an die in 4b
umbenannten Parameter angeglichen.

Dabei behoben:
- 4b hatte "tag" (HTML-Tag) als deutsches "Tag" gelesen und zu "dayValue"
  gemacht (makeElement, svg, Tagesübersicht) - zurück auf tag/day.
- Aufgaben "InProgress" bekamen die Plakettenart "laufend", für die es nie eine
  CSS-Klasse gab - jetzt "success" wie laufende Instanzen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 12:45:03 +02:00

120 lines
4.8 KiB
C#

using System.Net;
using ClawdDotNet.Core.Deploymentcenter;
using Shouldly;
namespace ClawdDotNet.Core.Tests.Deploymentcenter;
public sealed class TokenProvisionerTests
{
[Fact]
public async Task Instanz_bekommt_ein_eigenes_Sub_Token()
{
var handler = new CapturingHandler(HttpStatusCode.Created,
"""
{"status":"success","sub_token":"dc_sub_abc","token_id":"tok_s_1",
"scopes":["watchdog:ping","bugtracker:report"]}
""");
using var api = new DeploymentcenterApi("https://dc.example", "master", new HttpClient(handler));
var token = await new TokenProvisioner(api).ProvisionAsync(
"ClawdDotNet Produktion", "inst-1", TokenProvisioner.InstanceScopes);
handler.LastRequest!.RequestUri!.ToString().ShouldBe("https://dc.example/api/tokens/v1/provision");
handler.LastRequest.Headers.Authorization!.ToString().ShouldBe("Bearer master");
handler.LastBody!.ShouldContain("\"instance_id\":\"inst-1\"");
handler.LastBody.ShouldNotBeNull().ShouldContain("watchdog:ping");
token.Token.ShouldBe("dc_sub_abc");
token.TokenId.ShouldBe("tok_s_1");
token.Scopes.ShouldContain("bugtracker:report");
}
/// <summary>
/// A sub-token may not issue further ones. That is the normal case at the second
/// start and must come out as a clean error, not as a crash.
/// </summary>
[Fact]
public async Task Abgelehnte_Provisionierung_wirft_mit_Code()
{
var handler = new CapturingHandler(HttpStatusCode.Forbidden,
"""{"status":"error","error":{"code":"provision_denied","message":"Kein Master-Token."}}""");
using var api = new DeploymentcenterApi("https://dc.example", "sub", new HttpClient(handler));
var ex = await Should.ThrowAsync<DeploymentcenterException>(
() => new TokenProvisioner(api).ProvisionAsync("x", "inst-1", ["watchdog:ping"]));
ex.Code.ShouldBe("provision_denied");
}
// ─── whoami (SDK 2.7.1) ───
/// <summary>
/// The information that matters: which project the token is bound to.
///
/// <para>Since SDK 2.8.1 a watchdog monitor inherits the project of its ping token.
/// If the binding is missing, the findings land in the phantom project "default" — and a
/// query for the own project returns zero findings for a running, reporting instance.
/// Supervision would look like "nothing unusual".</para>
/// </summary>
[Fact]
public async Task Whoami_liest_die_Projektbindung()
{
var handler = new CapturingHandler(HttpStatusCode.OK,
"""
{"status":"success","token_id":"tok_m_1","name":"DEV-ClawdDotNet","type":"master",
"owner_type":"dev_agent","is_workbench":true,"project_slug":"clawddotnet",
"environment":"all","scopes":["*"]}
""");
using var api = new DeploymentcenterApi("https://dc.example", "master", new HttpClient(handler));
var identity = await new TokenProvisioner(api).WhoAmIAsync();
handler.LastRequest!.RequestUri!.ToString().ShouldBe("https://dc.example/api/tokens/v1/whoami");
handler.LastRequest.Method.ShouldBe(HttpMethod.Get);
identity.TokenId.ShouldBe("tok_m_1");
identity.Name.ShouldBe("DEV-ClawdDotNet");
identity.Type.ShouldBe("master");
identity.ProjectSlug.ShouldBe("clawddotnet");
identity.IsProjectBound.ShouldBeTrue();
identity.Scopes.ShouldContain("*");
}
[Fact]
public async Task Ein_Token_ohne_Projekt_faellt_auf()
{
// project_slug is JSON null, not absent - exactly as it comes from the server.
var handler = new CapturingHandler(HttpStatusCode.OK,
"""
{"status":"success","token_id":"tok_s_9","name":"Instanz","type":"sub",
"project_slug":null,"environment":"production","scopes":["watchdog:ping"]}
""");
using var api = new DeploymentcenterApi("https://dc.example", "sub", new HttpClient(handler));
var identity = await new TokenProvisioner(api).WhoAmIAsync();
identity.ProjectSlug.ShouldBeNull();
identity.IsProjectBound.ShouldBeFalse();
}
[Fact]
public async Task Eine_Antwort_ohne_Felder_wirft_nicht()
{
// An older server does not know whoami in this form. The information may
// be missing; it must not crash.
var handler = new CapturingHandler(HttpStatusCode.OK, """{"status":"success"}""");
using var api = new DeploymentcenterApi("https://dc.example", "t", new HttpClient(handler));
var identity = await new TokenProvisioner(api).WhoAmIAsync();
identity.TokenId.ShouldBe("");
identity.Type.ShouldBe("unknown");
identity.IsProjectBound.ShouldBeFalse();
identity.Scopes.ShouldBeEmpty();
}
}