Build initial MCP SSH server
This commit is contained in:
59
tests/McpSsh.Tests/DefaultSshKeyResolverTests.cs
Normal file
59
tests/McpSsh.Tests/DefaultSshKeyResolverTests.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using McpSsh.Server.Ssh;
|
||||
|
||||
namespace McpSsh.Tests;
|
||||
|
||||
public sealed class DefaultSshKeyResolverTests
|
||||
{
|
||||
[Fact]
|
||||
public void ResolveDefaultKeyPath_ReturnsFirstExistingDefaultKey()
|
||||
{
|
||||
var fileSystem = new FakeFileSystem("/home/test/.ssh/id_ecdsa", "/home/test/.ssh/id_rsa");
|
||||
var resolver = new DefaultSshKeyResolver(fileSystem, "/home/test/.ssh");
|
||||
|
||||
var path = resolver.ResolveKeyPath(null);
|
||||
|
||||
Assert.Equal("/home/test/.ssh/id_ecdsa", path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveDefaultKeyPath_ThrowsWhenNoDefaultKeyExists()
|
||||
{
|
||||
var resolver = new DefaultSshKeyResolver(new FakeFileSystem(), "/home/test/.ssh");
|
||||
|
||||
var ex = Assert.Throws<SshToolException>(() => resolver.ResolveKeyPath(null));
|
||||
|
||||
Assert.Equal("ssh_key_not_found", ex.ErrorCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveKeyPath_ReturnsExplicitKeyWhenItExists()
|
||||
{
|
||||
var resolver = new DefaultSshKeyResolver(new FakeFileSystem("/keys/deploy_ed25519"), "/home/test/.ssh");
|
||||
|
||||
var path = resolver.ResolveKeyPath("/keys/deploy_ed25519");
|
||||
|
||||
Assert.Equal("/keys/deploy_ed25519", path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveKeyPath_ThrowsWhenExplicitKeyDoesNotExist()
|
||||
{
|
||||
var resolver = new DefaultSshKeyResolver(new FakeFileSystem(), "/home/test/.ssh");
|
||||
|
||||
var ex = Assert.Throws<SshToolException>(() => resolver.ResolveKeyPath("/keys/missing"));
|
||||
|
||||
Assert.Equal("ssh_key_not_found", ex.ErrorCode);
|
||||
}
|
||||
|
||||
private sealed class FakeFileSystem : IFileSystem
|
||||
{
|
||||
private readonly HashSet<string> _paths;
|
||||
|
||||
public FakeFileSystem(params string[] paths)
|
||||
{
|
||||
_paths = paths.ToHashSet(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
public bool FileExists(string path) => _paths.Contains(path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user