-
-
Notifications
You must be signed in to change notification settings - Fork 946
/
Copy pathKnownHostStoreTests.cs
52 lines (46 loc) · 1.85 KB
/
KnownHostStoreTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Renci.SshNet.Common;
namespace Renci.SshNet.Tests.Classes
{
[TestClass]
public class KnownHostStoreTests
{
private static readonly byte[] ExampleKey = new byte[]
{
0x00, 0x11, 0x22, 0x33, 0x44,
0x55, 0x66, 0x77, 0x88, 0x99,
0xaa, 0xbb, 0xcc, 0xdd, 0xee,
0xff
};
private const string ExampleHost = "some.domain.com";
private const string ExampleSubDomain = "*.domain.com";
private const string ExampleKeyType = "rsa";
[TestMethod]
public void TestKnownHostStoreFindsHostIfMatch()
{
KnownHostStore hostStore = new KnownHostStore();
hostStore.AddHost(ExampleHost, 22, ExampleKeyType, ExampleKey, false);
Assert.IsTrue(hostStore.Knows(ExampleHost, ExampleKeyType, ExampleKey, 22));
}
[TestMethod]
public void TestKnownHostStoreFindsHashedHostIfMatch()
{
KnownHostStore hostStore = new KnownHostStore();
hostStore.AddHost(ExampleHost, 22, ExampleKeyType, ExampleKey, true);
Assert.IsTrue(hostStore.Knows(ExampleHost, ExampleKeyType, ExampleKey, 22));
}
[TestMethod]
[ExpectedException(typeof(RevokedKeyException), "Did not throw an exception upon finding a revoked key in the store")]
public void TestKnownHostStoreRejectsKeyIfRevoked()
{
KnownHostStore hostStore = new KnownHostStore();
hostStore.AddHost(ExampleHost, 22, ExampleKeyType, ExampleKey, false);
hostStore.AddHost(ExampleSubDomain, 22, ExampleKeyType, ExampleKey, false, "@revoked");
hostStore.Knows(ExampleHost, ExampleKeyType, ExampleKey, 22);
}
}
}