626a42de08
ShellOpenCommandPayload and CreateShellRequest carry an optional ShellKinds value (auto, pwsh, powershell, cmd, builtin; null = automatic) and ShellStatePayload reports the shell the agent started. The backend validates the choice (400 on unknown), passes it to the agent and records it in the shell audit detail. Old agents ignore the new field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using Shared.Contracts.Api;
|
|
using Xunit;
|
|
|
|
namespace Backend.Tests;
|
|
|
|
/// <summary>Opening a remote shell: the shell choice is validated before anything else happens.</summary>
|
|
public class ShellEndpointTests(BackendTestFixture fixture) : IClassFixture<BackendTestFixture>
|
|
{
|
|
[Fact]
|
|
public async Task AnUnknownShellIsRejected()
|
|
{
|
|
using var admin = await fixture.SignedInAsync("shell-admin");
|
|
|
|
var response = await admin.PostAsJsonAsync(
|
|
ApiRoutes.For.DeviceShell("shell-device"),
|
|
new { browserSessionId = "browser-1", cols = 80, rows = 24, shell = "bash" });
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
|
Assert.Contains("Unknown shell 'bash'", await response.Content.ReadAsStringAsync());
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("auto")]
|
|
[InlineData("PWSH")]
|
|
[InlineData("builtin")]
|
|
public async Task AKnownShellPassesValidation(string shell)
|
|
{
|
|
using var admin = await fixture.SignedInAsync("shell-admin");
|
|
|
|
// No such device: a known shell gets past validation to the device lookup.
|
|
var response = await admin.PostAsJsonAsync(
|
|
ApiRoutes.For.DeviceShell("shell-device"),
|
|
new { browserSessionId = "browser-1", cols = 80, rows = 24, shell });
|
|
|
|
Assert.DoesNotContain("Unknown shell", await response.Content.ReadAsStringAsync());
|
|
}
|
|
}
|