-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathCoapsServerTests.cs
More file actions
224 lines (191 loc) · 6.86 KB
/
CoapsServerTests.cs
File metadata and controls
224 lines (191 loc) · 6.86 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Waher.Networking.CoAP.CoRE;
using Waher.Networking.CoAP.Options;
using Waher.Networking.Sniffers;
using Waher.Security;
using Waher.Security.DTLS;
namespace Waher.Networking.CoAP.Test
{
[TestClass]
public class CoapsServerTests : CoapServerTestsBase
{
private IUserSource users;
protected override void SetupClientServer()
{
this.users = new Users(new User("testid", "01020304", "HEX", "CoAP"));
this.server = new CoapEndpoint(null, [CoapEndpoint.DefaultCoapsPort + 10],
this.users, "CoAP", false, true);
this.client = new CoapEndpoint(null, [CoapEndpoint.DefaultCoapsPort + 12],
null, null, true, false, new ConsoleOutSniffer(BinaryPresentationMethod.Hexadecimal, LineEnding.NewLine));
this.clientCredentials = new PresharedKey("testid", [1, 2, 3, 4]);
}
[TestMethod]
public async Task CoAP_Server_Test_01_GET()
{
// Default test resource
object Response = await this.Get("coaps://127.0.0.1:5694/test");
Assert.AreEqual(ResponseTest, Response);
}
[TestMethod]
public async Task CoAP_Server_Test_02_Root()
{
object Response = await this.Get("coaps://127.0.0.1:5694/");
Assert.AreEqual(ResponseRoot, Response);
}
[TestMethod]
public async Task CoAP_Server_Test_03_Discover()
{
LinkDocument Doc = await this.Get("coaps://127.0.0.1:5694/.well-known/core") as LinkDocument;
Assert.IsNotNull(Doc);
}
[TestMethod]
public async Task CoAP_Server_Test_04_Separate()
{
// Resource which cannot be served immediately and which cannot be acknowledged in a piggy-backed way
object Response = await this.Get("coaps://127.0.0.1:5694/separate");
Assert.AreEqual(ResponseTest, Response);
}
[TestMethod]
public async Task CoAP_Server_Test_05_LongPath()
{
// Long path resource
object Response = await this.Get("coaps://127.0.0.1:5694/seg1");
Assert.AreEqual(ResponseTest, Response);
}
[TestMethod]
public async Task CoAP_Server_Test_06_LongPath()
{
// Long path resource
object Response = await this.Get("coaps://127.0.0.1:5694/seg1/seg2");
Assert.AreEqual(ResponseTest, Response);
}
[TestMethod]
public async Task CoAP_Server_Test_07_LongPath()
{
// Long path resource
object Response = await this.Get("coaps://127.0.0.1:5694/seg1/seg2/seg3");
Assert.AreEqual(ResponseTest, Response);
}
[TestMethod]
public async Task CoAP_Server_Test_08_Large()
{
// Large resource
object Response = await this.Get("coaps://127.0.0.1:5694/large");
Assert.AreEqual(ResponseLarge, Response);
}
[TestMethod]
public async Task CoAP_Server_Test_09_LargeSeparate()
{
// Large resource
object Response = await this.Get("coaps://127.0.0.1:5694/large-separate");
Assert.AreEqual(ResponseLarge, Response);
}
[TestMethod]
public async Task CoAP_Server_Test_10_MultiFormat()
{
// Resource that exists in different content formats (text/plain utf8 and application/xml)
string s = await this.Get("coaps://127.0.0.1:5694/multi-format", new CoapOptionAccept(0)) as string;
AssertNotNull(s);
XmlDocument Xml = await this.Get("coaps://127.0.0.1:5694/multi-format", new CoapOptionAccept(41)) as XmlDocument;
AssertNotNull(Xml);
}
private static void AssertNotNull(object Obj)
{
Assert.IsNotNull(Obj);
}
[TestMethod]
public async Task CoAP_Server_Test_11_Hierarchical()
{
// Hierarchical link description entry
Assert.AreEqual(ResponseHierarchical, (await this.Get("coaps://127.0.0.1:5694/path")).ToString());
Assert.AreEqual("/path/sub1", await this.Get("coaps://127.0.0.1:5694/path/sub1"));
Assert.AreEqual("/path/sub2", await this.Get("coaps://127.0.0.1:5694/path/sub2"));
Assert.AreEqual("/path/sub3", await this.Get("coaps://127.0.0.1:5694/path/sub3"));
}
[TestMethod]
public async Task CoAP_Server_Test_12_Query()
{
// Hierarchical link description entry
Assert.AreEqual("?A=1&B=2", await this.Get("coaps://127.0.0.1:5694/query?A=1&B=2"));
}
[TestMethod]
public async Task CoAP_Server_Test_13_Observable()
{
// Observable resource which changes every 5 seconds
AssertNotNull(await this.Observe("coaps://127.0.0.1:5694/obs") as string);
}
[TestMethod]
public async Task CoAP_Server_Test_14_Observable_Large()
{
// Observable resource which changes every 5 seconds
AssertNotNull(await this.Observe("coaps://127.0.0.1:5694/obs-large") as string);
}
[TestMethod]
public async Task CoAP_Server_Test_15_Observable_NON()
{
// Observable resource which changes every 5 seconds
AssertNotNull(await this.Observe("coaps://127.0.0.1:5694/obs-non") as string);
}
[TestMethod]
public async Task CoAP_Server_Test_16_Observable_Pumping()
{
// Observable resource which changes every 5 seconds
AssertNotNull(await this.Observe("coaps://127.0.0.1:5694/obs-pumping") as string);
}
[TestMethod]
public async Task CoAP_Server_Test_17_Observable_Pumping_NON()
{
// Observable resource which changes every 5 seconds
AssertNotNull(await this.Observe("coaps://127.0.0.1:5694/obs-pumping-non") as string);
}
[TestMethod]
public async Task CoAP_Server_Test_18_POST()
{
// Perform POST transaction with responses containing several Location-Query options (CON mode)
await this.Post("coaps://127.0.0.1:5694/location-query", Encoding.UTF8.GetBytes("Hello"), 64, new CoapOptionContentFormat(0));
}
[TestMethod]
public async Task CoAP_Server_Test_19_POST_Large()
{
// Large resource that can be created using POST method
string s = "0123456789";
s = s + s + s + s + s + s + s + s + s + s;
s = s + s + s + s + s + s + s + s + s + s;
s += s;
await this.Post("coaps://127.0.0.1:5694/large-create", Encoding.UTF8.GetBytes(s), 64, new CoapOptionContentFormat(0));
}
[TestMethod]
public async Task CoAP_Server_Test_20_POST_Large_Response()
{
// Handle POST with two-way blockwise transfer
string s = "0123456789";
s = s + s + s + s + s + s + s + s + s + s;
s = s + s + s + s + s + s + s + s + s + s;
s += s;
await this.Post("coaps://127.0.0.1:5694/large-post", Encoding.UTF8.GetBytes(s), 64, new CoapOptionContentFormat(0));
}
[TestMethod]
public async Task CoAP_Server_Test_21_PUT()
{
// Large resource that can be updated using PUT method
await this.Put("coaps://127.0.0.1:5694/large-update", Encoding.UTF8.GetBytes("Hello"), 64, new CoapOptionContentFormat(0));
}
[TestMethod]
public async Task CoAP_Server_Test_22_PUT_Large()
{
// Large resource that can be updated using PUT method
string s = "0123456789";
s = s + s + s + s + s + s + s + s + s + s;
s = s + s + s + s + s + s + s + s + s + s;
s += s;
await this.Put("coaps://127.0.0.1:5694/large-update", Encoding.UTF8.GetBytes(s), 64, new CoapOptionContentFormat(0));
}
/*
</obs-reset>,
</validate>;title="Resource which varies", (Test with ETag)
*/
}
}