Add read-only MCP server with token access
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b8328f6998
commit
49a8fa1154
34 files changed
+1625
No files matched your search
@@ -0,0 +1,62 @@
|
||||
using Flypaper.Storage.Settings;
|
||||
using Flypaper.Tests.Fakes;
|
||||
using Flypaper.Web.Mcp;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Shouldly;
|
||||
|
||||
namespace Flypaper.Tests.Mcp;
|
||||
|
||||
public sealed class McpTokenServiceTests : IDisposable
|
||||
{
|
||||
private readonly McpTestData _data = new();
|
||||
private readonly McpTokenStore _store;
|
||||
|
||||
public McpTokenServiceTests() => _store = new McpTokenStore(_data.Factory, new FixedTimeProvider(McpTestData.Now));
|
||||
|
||||
[Fact]
|
||||
public async Task Created_token_is_valid_and_stored_only_as_hash()
|
||||
{
|
||||
var service = Create(environmentToken: null);
|
||||
|
||||
var token = await service.CreateAsync("Claude Desktop");
|
||||
|
||||
token.Length.ShouldBeGreaterThan(40);
|
||||
(await service.ValidateAsync(token)).ShouldBeTrue();
|
||||
var stored = (await _store.ListAsync()).ShouldHaveSingleItem();
|
||||
stored.Name.ShouldBe("Claude Desktop");
|
||||
stored.TokenHash.ShouldBe(McpTokenService.Hash(token));
|
||||
stored.TokenHash.ShouldNotContain(token);
|
||||
stored.LastUsedAt.ShouldBe(McpTestData.Now.UtcDateTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Wrong_missing_and_revoked_tokens_are_rejected()
|
||||
{
|
||||
var service = Create(environmentToken: null);
|
||||
var token = await service.CreateAsync("test");
|
||||
|
||||
(await service.ValidateAsync(null)).ShouldBeFalse();
|
||||
(await service.ValidateAsync("")).ShouldBeFalse();
|
||||
(await service.ValidateAsync(token + "x")).ShouldBeFalse();
|
||||
|
||||
(await _store.RevokeAsync((await _store.ListAsync())[0].Id)).ShouldBeTrue();
|
||||
(await service.ValidateAsync(token)).ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Environment_token_is_accepted_alongside_stored_ones()
|
||||
{
|
||||
var service = Create(environmentToken: "fixed-token-from-environment");
|
||||
var stored = await service.CreateAsync("test");
|
||||
|
||||
service.UsesEnvironmentToken.ShouldBeTrue();
|
||||
(await service.ValidateAsync("fixed-token-from-environment")).ShouldBeTrue();
|
||||
(await service.ValidateAsync(stored)).ShouldBeTrue();
|
||||
(await service.ValidateAsync("fixed-token")).ShouldBeFalse();
|
||||
}
|
||||
|
||||
private McpTokenService Create(string? environmentToken) =>
|
||||
new(_store, Options.Create(new McpOptions { Token = environmentToken }));
|
||||
|
||||
public void Dispose() => _data.Dispose();
|
||||
}
|
||||
Reference in new issue
Block a user