-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathDtlsUdpTests.cs
More file actions
87 lines (72 loc) · 2.32 KB
/
DtlsUdpTests.cs
File metadata and controls
87 lines (72 loc) · 2.32 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Waher.Events;
using Waher.Events.Console;
using Waher.Networking.Sniffers;
using Waher.Runtime.Inventory;
namespace Waher.Security.DTLS.Test
{
[TestClass]
public class DtlsUdpTests
{
private UdpClient udpClient;
private DtlsOverUdp dtlsOverUdp;
private IPEndPoint remoteEndpoint;
private ConsoleOutSniffer sniffer;
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext _)
{
Types.Initialize(typeof(ICipher).Assembly);
Log.Register(new ConsoleEventSink());
}
[TestInitialize]
public void TestInitialize()
{
this.sniffer = new ConsoleOutSniffer(BinaryPresentationMethod.Hexadecimal, LineEnding.NewLine);
//this.remoteEndpoint = new IPEndPoint(Dns.GetHostAddresses("vs0.inf.ethz.ch")[0], 5684);
//this.remoteEndpoint = new IPEndPoint(Dns.GetHostAddresses("californium.eclipse.org")[0], 5684);
this.remoteEndpoint = new IPEndPoint(Dns.GetHostAddresses("leshan.eclipse.org")[0], 5684);
//this.remoteEndpoint = new IPEndPoint(Dns.GetHostAddresses("lsys-home.dyndns.org")[0], 5684);
this.udpClient = new UdpClient(5684, AddressFamily.InterNetwork);
this.dtlsOverUdp = new DtlsOverUdp(this.udpClient, DtlsMode.Client, null, null, this.sniffer);
}
[TestCleanup]
public void TestCleanup()
{
this.dtlsOverUdp?.Dispose();
this.dtlsOverUdp = null;
this.udpClient?.Dispose();
this.udpClient = null;
this.sniffer = null;
}
[TestMethod]
public void Test_01_Handshake()
{
ManualResetEvent Done = new(false);
ManualResetEvent Error = new(false);
this.dtlsOverUdp.DTLS.OnHandshakeSuccessful += (Sender, e) =>
{
Done.Set();
return Task.CompletedTask;
};
this.dtlsOverUdp.DTLS.OnHandshakeFailed += (Sender, e) =>
{
Error.Set();
return Task.CompletedTask;
};
this.dtlsOverUdp.DTLS.StartHandshake(this.remoteEndpoint,
new PresharedKey("testid", new byte[] { 1, 2, 3, 4 }));
// Set Pre-shared keys at: http://leshan.eclipse.org/#/security
Assert.AreEqual(0, WaitHandle.WaitAny(new WaitHandle[] { Done, Error }, 60000));
}
[TestMethod]
public void Test_02_Retransmissions()
{
this.dtlsOverUdp.DTLS.ProbabilityPacketLoss = 0.3;
this.Test_01_Handshake();
}
}
}