blob: 15de273bd9fb7ad7afd5eada507d62f8c875ecf8 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08002/**
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -07003 * Copyright (c) 2013-2016 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080020 */
21
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080022#include "interest.hpp"
Junxiao Shi2af905b2014-11-27 13:10:54 -070023#include "interest-filter.hpp"
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070024#include "data.hpp"
25#include "security/signature-sha256-with-rsa.hpp"
Yingdi Yubf6a2812014-06-17 15:32:11 -070026#include "security/digest-sha256.hpp"
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -070027#include "security/key-chain.hpp"
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070028#include "encoding/buffer-stream.hpp"
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070029
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070030#include "boost-test.hpp"
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070031#include "identity-management-fixture.hpp"
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080032
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080033namespace ndn {
Alexander Afanasyev90164962014-03-06 08:29:59 +000034namespace tests {
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080035
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070036BOOST_FIXTURE_TEST_SUITE(TestInterest, IdentityManagementFixture)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080037
38const uint8_t Interest1[] = {
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -070039 0x05, 0x59, // NDN Interest
Alexander Afanasyev4b456282014-02-13 00:34:34 -080040 0x07, 0x14, // Name
41 0x08, 0x5, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080042 0x6c, 0x6f, 0x63, 0x61, 0x6c,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080043 0x08, 0x3, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080044 0x6e, 0x64, 0x6e,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080045 0x08, 0x6, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080046 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
Junxiao Shib332e782014-03-31 14:23:46 -070047 0x09, 0x37, // Selectors
Alexander Afanasyev4b456282014-02-13 00:34:34 -080048 0x0d, 0x1, 0x1, // MinSuffix
49 0x0e, 0x1, 0x1, // MaxSuffix
Junxiao Shib332e782014-03-31 14:23:46 -070050 0x1c, 0x16, // KeyLocator
51 0x07, 0x14, // Name
52 0x08, 0x04,
53 0x74, 0x65, 0x73, 0x74,
54 0x08, 0x03,
55 0x6b, 0x65, 0x79,
56 0x08, 0x07,
57 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080058 0x10, 0x14, // Exclude
59 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080060 0x61, 0x6c, 0x65, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080061 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080062 0x78, 0x78, 0x78, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080063 0x13, 0x0, // Any
64 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080065 0x79, 0x79, 0x79, 0x79,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080066 0x11, 0x1, // ChildSelector
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080067 0x1,
Alexander Afanasyeve881e932014-06-08 14:47:03 +030068 0x0a, 0x4, // Nonce
69 0x1, 0x0, 0x0, 0x00,
Alexander Afanasyeve881e932014-06-08 14:47:03 +030070 0x0c, // InterestLifetime
71 0x2, 0x3, 0xe8
72};
73
74const uint8_t Interest2[] = {
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -070075 0x05, 0x59, // NDN Interest
Alexander Afanasyeve881e932014-06-08 14:47:03 +030076 0x07, 0x14, // Name
77 0x08, 0x5, // NameComponent
78 0x6c, 0x6f, 0x63, 0x61, 0x6c,
79 0x08, 0x3, // NameComponent
80 0x6e, 0x64, 0x6e,
81 0x08, 0x6, // NameComponent
82 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
83 0x09, 0x37, // Selectors
84 0x0d, 0x1, 0x1, // MinSuffix
85 0x0e, 0x1, 0x1, // MaxSuffix
86 0x1c, 0x16, // KeyLocator
87 0x07, 0x14, // Name
88 0x08, 0x04,
89 0x74, 0x65, 0x73, 0x74,
90 0x08, 0x03,
91 0x6b, 0x65, 0x79,
92 0x08, 0x07,
93 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
94 0x10, 0x14, // Exclude
95 0x08, 0x4, // NameComponent
96 0x61, 0x6c, 0x65, 0x78,
97 0x08, 0x4, // NameComponent
98 0x78, 0x78, 0x78, 0x78,
99 0x13, 0x0, // Any
100 0x08, 0x4, // NameComponent
101 0x79, 0x79, 0x79, 0x79,
102 0x11, 0x1, // ChildSelector
103 0x1,
104 0x0a, 0x4, // Nonce
105 0x2, 0x0, 0x0, 0x00,
Alexander Afanasyev4b456282014-02-13 00:34:34 -0800106 0x0c, // InterestLifetime
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800107 0x2, 0x3, 0xe8
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800108};
109
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700110const uint8_t InterestWithLink[] = {
111 0x05, 0xfb, // Interest
112 0x07, 0x14, // Name
113 0x08, 0x5, // NameComponent
114 0x6c, 0x6f, 0x63, 0x61, 0x6c,
115 0x08, 0x3, // NameComponent
116 0x6e, 0x64, 0x6e,
117 0x08, 0x6, // NameComponent
118 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
119 0x0a, 0x4, // Nonce
120 0x1, 0x0, 0x0, 0x00,
121 0x06, 0xda, // Data
122 0x07, 0x14, // Name
123 0x08, 0x05,
124 0x6c, 0x6f, 0x63, 0x61, 0x6c,
125 0x08, 0x03,
126 0x6e, 0x64, 0x6e,
127 0x08, 0x06,
128 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
129 0x14, 0x07, // MetaInfo
130 0x18, 0x01, // ContentType
131 0x01,
132 0x19, 0x02, // FreshnessPeriod
133 0x27, 0x10,
134 0x15, 0x1a, // Content
135 0x1f, 0x0c, // LinkDelegation
136 0x1e, 0x01, // LinkPreference
137 0x0a,
138 0x07, 0x07, // Name
139 0x08, 0x05,
140 0x6c, 0x6f, 0x63, 0x61, 0x6c,
141 0x1f, 0x0a, // LinkDelegation
142 0x1e, 0x01, // LinkPreference
143 0x14,
144 0x07, 0x05, // Name
145 0x08, 0x03,
146 0x6e, 0x64, 0x6e,
147 0x16, 0x1b, // SignatureInfo
148 0x1b, 0x01, // SignatureType
149 0x01,
150 0x1c, 0x16, // KeyLocator
151 0x07, 0x14, // Name
152 0x08, 0x04,
153 0x74, 0x65, 0x73, 0x74,
154 0x08, 0x03,
155 0x6b, 0x65, 0x79,
156 0x08, 0x07,
157 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
158 0x17, 0x80, // SignatureValue
159 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
160 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
161 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
162 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
163 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
164 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
165 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
166 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
167 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
168 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
169 0x20, 0x01, // SelectedDelegation
170 0x00
171};
172
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700173const uint8_t LINK[] = {
174 0x06, 0xda, // Data
175 0x07, 0x14, // Name
176 0x08, 0x05,
177 0x6c, 0x6f, 0x63, 0x61, 0x6c,
178 0x08, 0x03,
179 0x6e, 0x64, 0x6e,
180 0x08, 0x06,
181 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
182 0x14, 0x07, // MetaInfo
183 0x18, 0x01, // ContentType
184 0x01,
185 0x19, 0x02, // FreshnessPeriod
186 0x27, 0x10,
187 0x15, 0x1a, // Content
188 0x1f, 0x0c, // LinkDelegation
189 0x1e, 0x01, // LinkPreference
190 0x0a,
191 0x07, 0x07, // Name
192 0x08, 0x05,
193 0x6c, 0x6f, 0x63, 0x61, 0x6c,
194 0x1f, 0x0a, // LinkDelegation
195 0x1e, 0x01, // LinkPreference
196 0x14,
197 0x07, 0x05, // Name
198 0x08, 0x03,
199 0x6e, 0x64, 0x6e,
200 0x16, 0x1b, // SignatureInfo
201 0x1b, 0x01, // SignatureType
202 0x01,
203 0x1c, 0x16, // KeyLocator
204 0x07, 0x14, // Name
205 0x08, 0x04,
206 0x74, 0x65, 0x73, 0x74,
207 0x08, 0x03,
208 0x6b, 0x65, 0x79,
209 0x08, 0x07,
210 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
211 0x17, 0x80, // SignatureValue
212 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
213 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
214 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
215 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
216 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
217 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
218 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
219 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
220 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
221 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1
222};
223
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700224const uint8_t InterestWithLinkMissingContentType[] = {
225 0x05, 0xf8, // Interest
226 0x07, 0x14, // Name
227 0x08, 0x5, // NameComponent
228 0x6c, 0x6f, 0x63, 0x61, 0x6c,
229 0x08, 0x3, // NameComponent
230 0x6e, 0x64, 0x6e,
231 0x08, 0x6, // NameComponent
232 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
233 0x0a, 0x4, // Nonce
234 0x1, 0x0, 0x0, 0x00,
235 0x06, 0xd7, // Data
236 0x07, 0x14, // Name
237 0x08, 0x05,
238 0x6c, 0x6f, 0x63, 0x61, 0x6c,
239 0x08, 0x03,
240 0x6e, 0x64, 0x6e,
241 0x08, 0x06,
242 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
243 0x14, 0x04, // MetaInfo
244 0x19, 0x02, // FreshnessPeriod
245 0x27, 0x10,
246 0x15, 0x1a, // Content
247 0x1f, 0x0c, // LinkDelegation
248 0x1e, 0x01, // LinkPreference
249 0x0a,
250 0x07, 0x07, // Name
251 0x08, 0x05,
252 0x6c, 0x6f, 0x63, 0x61, 0x6c,
253 0x1f, 0x0a, // LinkDelegation
254 0x1e, 0x01, // LinkPreference
255 0x14,
256 0x07, 0x05, // Name
257 0x08, 0x03,
258 0x6e, 0x64, 0x6e,
259 0x16, 0x1b, // SignatureInfo
260 0x1b, 0x01, // SignatureType
261 0x01,
262 0x1c, 0x16, // KeyLocator
263 0x07, 0x14, // Name
264 0x08, 0x04,
265 0x74, 0x65, 0x73, 0x74,
266 0x08, 0x03,
267 0x6b, 0x65, 0x79,
268 0x08, 0x07,
269 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
270 0x17, 0x80, // SignatureValue
271 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
272 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
273 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
274 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
275 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
276 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
277 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
278 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
279 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
280 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
281 0x20, 0x01, // SelectedDelegation
282 0x00
283};
284
285const uint8_t InterestWithLinkNoMetaInfo[] = {
286 0x05, 0xf2, // Interest
287 0x07, 0x14, // Name
288 0x08, 0x5, // NameComponent
289 0x6c, 0x6f, 0x63, 0x61, 0x6c,
290 0x08, 0x3, // NameComponent
291 0x6e, 0x64, 0x6e,
292 0x08, 0x6, // NameComponent
293 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
294 0x0a, 0x4, // Nonce
295 0x1, 0x0, 0x0, 0x00,
296 0x06, 0xd1, // Data
297 0x07, 0x14, // Name
298 0x08, 0x05,
299 0x6c, 0x6f, 0x63, 0x61, 0x6c,
300 0x08, 0x03,
301 0x6e, 0x64, 0x6e,
302 0x08, 0x06,
303 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
304 0x15, 0x1a, // Content
305 0x1f, 0x0c, // LinkDelegation
306 0x1e, 0x01, // LinkPreference
307 0x0a,
308 0x07, 0x07, // Name
309 0x08, 0x05,
310 0x6c, 0x6f, 0x63, 0x61, 0x6c,
311 0x1f, 0x0a, // LinkPreference
312 0x1e, 0x01, // LinkPreference
313 0x14,
314 0x07, 0x05, // Name
315 0x08, 0x03,
316 0x6e, 0x64, 0x6e,
317 0x16, 0x1b, // SignatureInfo
318 0x1b, 0x01, // SignatureType
319 0x01,
320 0x1c, 0x16, // KeyLocator
321 0x07, 0x14, // Name
322 0x08, 0x04,
323 0x74, 0x65, 0x73, 0x74,
324 0x08, 0x03,
325 0x6b, 0x65, 0x79,
326 0x08, 0x07,
327 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
328 0x17, 0x80, // SignatureValue
329 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
330 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
331 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
332 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
333 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
334 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
335 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
336 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
337 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
338 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
339 0x20, 0x01, // SelectedDelegation
340 0x00
341};
342
343const uint8_t InterestWithLinkWrongContentType[] = {
344 0x05, 0xfb, // Interest
345 0x07, 0x14, // Name
346 0x08, 0x5, // NameComponent
347 0x6c, 0x6f, 0x63, 0x61, 0x6c,
348 0x08, 0x3, // NameComponent
349 0x6e, 0x64, 0x6e,
350 0x08, 0x6, // NameComponent
351 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
352 0x0a, 0x4, // Nonce
353 0x1, 0x0, 0x0, 0x00,
354 0x06, 0xda, // Data
355 0x07, 0x14, // Name
356 0x08, 0x05,
357 0x6c, 0x6f, 0x63, 0x61, 0x6c,
358 0x08, 0x03,
359 0x6e, 0x64, 0x6e,
360 0x08, 0x06,
361 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
362 0x14, 0x07, // MetaInfo
363 0x18, 0x01, // ContentType
364 0x00,
365 0x19, 0x02, // FreshnessPeriod
366 0x27, 0x10,
367 0x15, 0x1a, // Content
368 0x1f, 0x0c, // LinkDelegation
369 0x1e, 0x01, // LinkPreference
370 0x0a,
371 0x07, 0x07, // Name
372 0x08, 0x05,
373 0x6c, 0x6f, 0x63, 0x61, 0x6c,
374 0x1f, 0x0a, // LinkDelegation
375 0x1e, 0x01, // LinkPreference
376 0x14,
377 0x07, 0x05, // Name
378 0x08, 0x03,
379 0x6e, 0x64, 0x6e,
380 0x16, 0x1b, // SignatureInfo
381 0x1b, 0x01, // SignatureType
382 0x01,
383 0x1c, 0x16, // KeyLocator
384 0x07, 0x14, // Name
385 0x08, 0x04,
386 0x74, 0x65, 0x73, 0x74,
387 0x08, 0x03,
388 0x6b, 0x65, 0x79,
389 0x08, 0x07,
390 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
391 0x17, 0x80, // SignatureValue
392 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
393 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
394 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
395 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
396 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
397 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
398 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
399 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
400 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
401 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
402 0x20, 0x01, // SelectedDelegation
403 0x00
404};
405
406const uint8_t InterestWithSelectedDelegationButNoLink[] = {
407 0x05, 0x1f, // Interest
408 0x07, 0x14, // Name
409 0x08, 0x5, // NameComponent
410 0x6c, 0x6f, 0x63, 0x61, 0x6c,
411 0x08, 0x3, // NameComponent
412 0x6e, 0x64, 0x6e,
413 0x08, 0x6, // NameComponent
414 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
415 0x0a, 0x4, // Nonce
416 0x1, 0x0, 0x0, 0x00,
417 0x20, 0x01, // SelectedDelegation
418 0x00
419};
420
421const uint8_t InterestWithLinkNotNonIntegerSelectedDelegation[] = {
422 0x05, 0xfb, // Interest
423 0x07, 0x14, // Name
424 0x08, 0x5, // NameComponent
425 0x6c, 0x6f, 0x63, 0x61, 0x6c,
426 0x08, 0x3, // NameComponent
427 0x6e, 0x64, 0x6e,
428 0x08, 0x6, // NameComponent
429 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
430 0x0a, 0x4, // Nonce
431 0x1, 0x0, 0x0, 0x00,
432 0x06, 0xda, // Data
433 0x07, 0x14, // Name
434 0x08, 0x05,
435 0x6c, 0x6f, 0x63, 0x61, 0x6c,
436 0x08, 0x03,
437 0x6e, 0x64, 0x6e,
438 0x08, 0x06,
439 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
440 0x14, 0x07, // MetaInfo
441 0x18, 0x01, // ContentType
442 0x01,
443 0x19, 0x02, // FreshnessPeriod
444 0x27, 0x10,
445 0x15, 0x1a, // Content
446 0x1f, 0x0c, // LinkDelegation
447 0x1e, 0x01, // LinkPreference
448 0x0a,
449 0x07, 0x07, // Name
450 0x08, 0x05,
451 0x6c, 0x6f, 0x63, 0x61, 0x6c,
452 0x1f, 0x0a, // LinkDelegation
453 0x1e, 0x01, // LinkPreference
454 0x14,
455 0x07, 0x05, // Name
456 0x08, 0x03,
457 0x6e, 0x64, 0x6e,
458 0x16, 0x1b, // SignatureInfo
459 0x1b, 0x01, // SignatureType
460 0x01,
461 0x1c, 0x16, // KeyLocator
462 0x07, 0x14, // Name
463 0x08, 0x04,
464 0x74, 0x65, 0x73, 0x74,
465 0x08, 0x03,
466 0x6b, 0x65, 0x79,
467 0x08, 0x07,
468 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
469 0x17, 0x78, // SignatureValue
470 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
471 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
472 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
473 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
474 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
475 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
476 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
477 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
478 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
479 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7,
480 0x20, 0x03, // SelectedDelegation
481 0xAA, 0xAA, 0xAA
482};
483
484const uint8_t InterestWithLinkNonDecreasingOrder[] = {
485 0x05, 0xfb, // Interest
486 0x07, 0x14, // Name
487 0x08, 0x5, // NameComponent
488 0x6c, 0x6f, 0x63, 0x61, 0x6c,
489 0x08, 0x3, // NameComponent
490 0x6e, 0x64, 0x6e,
491 0x08, 0x6, // NameComponent
492 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
493 0x0a, 0x4, // Nonce
494 0x1, 0x0, 0x0, 0x00,
495 0x06, 0xda, // Data
496 0x07, 0x14, // Name
497 0x08, 0x05,
498 0x6c, 0x6f, 0x63, 0x61, 0x6c,
499 0x08, 0x03,
500 0x6e, 0x64, 0x6e,
501 0x08, 0x06,
502 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
503 0x14, 0x07, // MetaInfo
504 0x18, 0x01, // ContentType
505 0x01,
506 0x19, 0x02, // FreshnessPeriod
507 0x27, 0x10,
508 0x15, 0x1a, // Content
509 0x1f, 0x0c, // LinkDelegation
510 0x1e, 0x01, // LinkPreference
511 0x14,
512 0x07, 0x07, // Name
513 0x08, 0x05,
514 0x6c, 0x6f, 0x63, 0x61, 0x6c,
515 0x1f, 0x0a, // LinkDelegation
516 0x1e, 0x01, // LinkPreference
517 0x0a,
518 0x07, 0x05, // Name
519 0x08, 0x03,
520 0x6e, 0x64, 0x6e,
521 0x16, 0x1b, // SignatureInfo
522 0x1b, 0x01, // SignatureType
523 0x01,
524 0x1c, 0x16, // KeyLocator
525 0x07, 0x14, // Name
526 0x08, 0x04,
527 0x74, 0x65, 0x73, 0x74,
528 0x08, 0x03,
529 0x6b, 0x65, 0x79,
530 0x08, 0x07,
531 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
532 0x17, 0x80, // SignatureValue
533 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
534 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
535 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
536 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
537 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
538 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
539 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
540 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
541 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
542 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
543 0x20, 0x01, // SelectedDelegation
544 0x01
545};
546
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700547BOOST_AUTO_TEST_CASE(InterestEqualityChecks)
548{
549 // Interest ::= INTEREST-TYPE TLV-LENGTH
550 // Name
551 // Selectors?
552 // Nonce
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700553 // InterestLifetime?
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700554 // Link?
555 // SelectedDelegation?
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700556
557 Interest a;
558 Interest b;
559
560 // if nonce is not set, it will be set to a random value
561 a.setNonce(1);
562 b.setNonce(1);
563
564 BOOST_CHECK_EQUAL(a == b, true);
565 BOOST_CHECK_EQUAL(a != b, false);
566
567 // check comparison on Name
568 a.setName("ndn:/A");
569 BOOST_CHECK_EQUAL(a == b, false);
570 BOOST_CHECK_EQUAL(a != b, true);
571
572 b.setName("ndn:/B");
573 BOOST_CHECK_EQUAL(a == b, false);
574 BOOST_CHECK_EQUAL(a != b, true);
575
576 b.setName("ndn:/A");
577 BOOST_CHECK_EQUAL(a == b, true);
578 BOOST_CHECK_EQUAL(a != b, false);
579
580 // check comparison on Selectors
581 a.setChildSelector(1);
582 BOOST_CHECK_EQUAL(a == b, false);
583 BOOST_CHECK_EQUAL(a != b, true);
584
585 b.setChildSelector(1);
586 BOOST_CHECK_EQUAL(a == b, true);
587 BOOST_CHECK_EQUAL(a != b, false);
588
589 // check comparison on Nonce
590 a.setNonce(100);
591 BOOST_CHECK_EQUAL(a == b, false);
592 BOOST_CHECK_EQUAL(a != b, true);
593
594 b.setNonce(100);
595 BOOST_CHECK_EQUAL(a == b, true);
596 BOOST_CHECK_EQUAL(a != b, false);
597
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700598 // check comparison on InterestLifetime
599 a.setInterestLifetime(time::seconds(10));
600 BOOST_CHECK_EQUAL(a == b, false);
601 BOOST_CHECK_EQUAL(a != b, true);
602
603 b.setInterestLifetime(time::seconds(10));
604 BOOST_CHECK_EQUAL(a == b, true);
605 BOOST_CHECK_EQUAL(a != b, false);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700606
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700607 a.setLink(Block(LINK, sizeof(LINK)));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700608 BOOST_CHECK_EQUAL(a == b, false);
609 BOOST_CHECK_EQUAL(a != b, true);
610
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700611 b.setLink(Block(LINK, sizeof(LINK)));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700612 BOOST_CHECK_EQUAL(a == b, true);
613 BOOST_CHECK_EQUAL(a != b, false);
614
615 // Selected Delegation
616 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
617 BOOST_CHECK_EQUAL(b.hasSelectedDelegation(), false);
618
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700619 a.setSelectedDelegation(Name("/local"));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700620 BOOST_CHECK_EQUAL(a == b, false);
621 BOOST_CHECK_EQUAL(a != b, true);
622
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700623 b.setSelectedDelegation(Name("/local"));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700624 BOOST_CHECK_EQUAL(a == b, true);
625 BOOST_CHECK_EQUAL(a != b, false);
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700626}
627
628BOOST_AUTO_TEST_CASE(SelectorsEqualityChecks)
629{
630 // Selectors ::= SELECTORS-TYPE TLV-LENGTH
631 // MinSuffixComponents?
632 // MaxSuffixComponents?
633 // PublisherPublicKeyLocator?
634 // Exclude?
635 // ChildSelector?
636 // MustBeFresh?
637
638 Selectors a;
639 Selectors b;
640 BOOST_CHECK_EQUAL(a == b, true);
641 BOOST_CHECK_EQUAL(a != b, false);
642
643 // MinSuffixComponents
644 a.setMinSuffixComponents(1);
645 BOOST_CHECK_EQUAL(a == b, false);
646 BOOST_CHECK_EQUAL(a != b, true);
647
648 b.setMinSuffixComponents(2);
649 BOOST_CHECK_EQUAL(a == b, false);
650 BOOST_CHECK_EQUAL(a != b, true);
651
652 b.setMinSuffixComponents(1);
653 BOOST_CHECK_EQUAL(a == b, true);
654 BOOST_CHECK_EQUAL(a != b, false);
655
656 // MaxSuffixComponents
657 a.setMaxSuffixComponents(10);
658 BOOST_CHECK_EQUAL(a == b, false);
659 BOOST_CHECK_EQUAL(a != b, true);
660
661 b.setMaxSuffixComponents(10);
662 BOOST_CHECK_EQUAL(a == b, true);
663 BOOST_CHECK_EQUAL(a != b, false);
664
665 // PublisherPublicKeyLocator
666 a.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
667 BOOST_CHECK_EQUAL(a == b, false);
668 BOOST_CHECK_EQUAL(a != b, true);
669
670 b.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
671 BOOST_CHECK_EQUAL(a == b, true);
672 BOOST_CHECK_EQUAL(a != b, false);
673
674 // Exclude
675 a.setExclude(Exclude().excludeOne(name::Component("exclude")));
676 BOOST_CHECK_EQUAL(a == b, false);
677 BOOST_CHECK_EQUAL(a != b, true);
678
679 b.setExclude(Exclude().excludeOne(name::Component("exclude")));
680 BOOST_CHECK_EQUAL(a == b, true);
681 BOOST_CHECK_EQUAL(a != b, false);
682
683 // ChildSelector
684 a.setChildSelector(1);
685 BOOST_CHECK_EQUAL(a == b, false);
686 BOOST_CHECK_EQUAL(a != b, true);
687
688 b.setChildSelector(1);
689 BOOST_CHECK_EQUAL(a == b, true);
690 BOOST_CHECK_EQUAL(a != b, false);
691
692 // MustBeFresh
693 a.setMustBeFresh(true);
694 BOOST_CHECK_EQUAL(a == b, false);
695 BOOST_CHECK_EQUAL(a != b, true);
696
697 b.setMustBeFresh(true);
698 BOOST_CHECK_EQUAL(a == b, true);
699 BOOST_CHECK_EQUAL(a != b, false);
700}
701
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700702BOOST_AUTO_TEST_CASE(LinkObject)
703{
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700704 Link link1("test", {{100, "/test3"}, {20, "/test2"}, {10, "/test1"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700705 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700706 Block wire = link1.wireEncode();
707
708 Interest a;
709 BOOST_REQUIRE_NO_THROW(a.setLink(wire));
710
711 BOOST_REQUIRE_NO_THROW(a.getLink());
712
713 Link link2 = a.getLink();
714 Name name = link2.getName();
715 BOOST_CHECK_EQUAL(Name("test"), name);
716 BOOST_CHECK_EQUAL(a.hasLink(), true);
717 Link::DelegationSet delegations;
718 delegations = link2.getDelegations();
719
720 auto i = delegations.begin();
721 BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
722 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
723 ++i;
724 BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
725 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
726 ++i;
727 BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
728 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
729
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700730 a.setLink(Block(LINK, sizeof(LINK)));
731 BOOST_CHECK_EQUAL(a.getLink().getDelegations().size(), 2);
732
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700733 a.unsetLink();
734 BOOST_CHECK_EQUAL(a.hasLink(), false);
735}
736
737BOOST_AUTO_TEST_CASE(SelectedDelegationChecks)
738{
739 Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700740 m_keyChain.sign(link);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700741 Block wire = link.wireEncode();
742
743 Interest a;
744 a.setLink(wire);
745 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
746
747 BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(Name("test2")));
748 BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test2"));
749
750 BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(uint32_t(2)));
751 BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test3"));
752
753 a.unsetSelectedDelegation();
754 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
755}
756
757BOOST_AUTO_TEST_CASE(EncodeDecodeWithLink)
758{
759 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700760 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700761 Block wire = link1.wireEncode();
762
763 Interest a;
764 a.setName("/Test/Encode/Decode/With/Link");
765 a.setChildSelector(1);
766 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700767 a.setInterestLifetime(time::seconds(10));
768 a.setLink(wire);
769
770 Block interestBlock = a.wireEncode();
771 Interest b(interestBlock);
772
773 BOOST_CHECK_EQUAL(a == b, true);
774
775 Link link2 = b.getLink();
776 Link::DelegationSet delegations;
777 delegations = link2.getDelegations();
778
779 auto i = delegations.begin();
780 BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
781 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
782 ++i;
783 BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
784 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
785 ++i;
786 BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
787 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
788
789}
790
791BOOST_AUTO_TEST_CASE(DecodeInterestWithLink)
792{
793 Block interestBlock(InterestWithLink, sizeof(InterestWithLink));
794
795 ndn::Interest i;
796 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
797 Link link = i.getLink();
798 BOOST_CHECK_EQUAL(link.getName(), Name("/local/ndn/prefix"));
799 Link::DelegationSet delegations = link.getDelegations();
800
801 auto it = delegations.begin();
802 BOOST_CHECK_EQUAL(std::get<0>(*it), 10);
803 BOOST_CHECK_EQUAL(std::get<1>(*it), Name("local"));
804 ++it;
805 BOOST_CHECK_EQUAL(std::get<0>(*it), 20);
806 BOOST_CHECK_EQUAL(std::get<1>(*it), Name("ndn"));
807
808 BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
809 BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("local"));
810}
811
812BOOST_AUTO_TEST_CASE(DecodeInterestWithLinkNonDecreasingOrder)
813{
814 Block interestBlock(InterestWithLinkNonDecreasingOrder,
815 sizeof(InterestWithLinkNonDecreasingOrder));
816
817 ndn::Interest i;
818 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
819 BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
820 BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("ndn"));
821}
822
823BOOST_AUTO_TEST_CASE(LinkObjectMissingContentType)
824{
825 Block interestBlock(InterestWithLinkMissingContentType,
826 sizeof(InterestWithLinkMissingContentType));
827
828 ndn::Interest i;
829 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
830 BOOST_REQUIRE_THROW(i.getLink(), Link::Error);
831}
832
833BOOST_AUTO_TEST_CASE(LinkObjectNoMetaInfo)
834{
835 Block interestBlock(InterestWithLinkNoMetaInfo,
836 sizeof(InterestWithLinkNoMetaInfo));
837
838 ndn::Interest i;
839 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700840 BOOST_CHECK_THROW(i.getLink(), tlv::Error);
841 BOOST_CHECK_THROW(i.getLink(), tlv::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700842}
843
844BOOST_AUTO_TEST_CASE(LinkObjectWrongContentType)
845{
846 Block interestBlock(InterestWithLinkWrongContentType,
847 sizeof(InterestWithLinkWrongContentType));
848
849 ndn::Interest i;
850 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700851 BOOST_CHECK_THROW(i.getLink(), Link::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700852}
853
854BOOST_AUTO_TEST_CASE(InterestContainingSelectedDelegationButNoLink)
855{
856 Block interestBlock(InterestWithSelectedDelegationButNoLink,
857 sizeof(InterestWithSelectedDelegationButNoLink));
858
859 ndn::Interest i;
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700860 BOOST_CHECK_THROW(i.wireDecode(interestBlock), Interest::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700861}
862
863BOOST_AUTO_TEST_CASE(SelectedDelegationIsNotNonNegativeInteger)
864{
865 Block interestBlock(InterestWithLinkNotNonIntegerSelectedDelegation,
866 sizeof(InterestWithLinkNotNonIntegerSelectedDelegation));
867
868 ndn::Interest i;
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700869 BOOST_CHECK_THROW(i.wireDecode(interestBlock), tlv::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700870}
871
872BOOST_AUTO_TEST_CASE(SelectedDelegationEqualToDelegationCount)
873{
874 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700875 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700876 Block wire = link1.wireEncode();
877
878 Interest a;
879 a.setName("/Test/Encode/Decode/With/Link");
880 a.setChildSelector(1);
881 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700882 a.setInterestLifetime(time::seconds(10));
883 a.setLink(wire);
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700884 BOOST_CHECK_THROW(a.setSelectedDelegation(3), Interest::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700885}
886
887BOOST_AUTO_TEST_CASE(SelectedDelegationGreaterThanDelegationCount)
888{
889 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700890 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700891 Block wire = link1.wireEncode();
892
893 Interest a;
894 a.setName("/Test/Encode/Decode/With/Link");
895 a.setChildSelector(1);
896 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700897 a.setInterestLifetime(time::seconds(10));
898 a.setLink(wire);
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700899 BOOST_CHECK_THROW(a.setSelectedDelegation(4), Interest::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700900}
901
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700902BOOST_AUTO_TEST_CASE(Decode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800903{
904 Block interestBlock(Interest1, sizeof(Interest1));
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800905
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800906 ndn::Interest i;
Alexander Afanasyev049f8f72013-12-26 19:07:15 -0800907 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800908
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700909 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700910 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
911 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
912 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
913 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getType(),
914 static_cast<uint32_t>(KeyLocator::KeyLocator_Name));
915 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getName(), "ndn:/test/key/locator");
916 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
917 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
918 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
919 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700920 BOOST_CHECK_EQUAL(i.hasLink(), false);
921 BOOST_CHECK_EQUAL(i.hasSelectedDelegation(), false);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800922}
923
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700924BOOST_AUTO_TEST_CASE(DecodeFromStream)
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800925{
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -0700926 boost::iostreams::stream<boost::iostreams::array_source> is(
927 reinterpret_cast<const char *>(Interest1), sizeof(Interest1));
Junxiao Shib332e782014-03-31 14:23:46 -0700928
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700929 Block interestBlock = Block::fromStream(is);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800930
931 ndn::Interest i;
932 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
933
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700934 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700935 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
936 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
937 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
938 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
939 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
940 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
941 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700942 BOOST_CHECK_EQUAL(i.hasLink(), false);
943 BOOST_CHECK_EQUAL(i.hasSelectedDelegation(), false);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -0800944}
945
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700946BOOST_AUTO_TEST_CASE(Encode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800947{
948 ndn::Interest i(ndn::Name("/local/ndn/prefix"));
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700949 i.setInterestLifetime(time::milliseconds(1000));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800950 i.setMinSuffixComponents(1);
951 i.setMaxSuffixComponents(1);
Junxiao Shib332e782014-03-31 14:23:46 -0700952 i.setPublisherPublicKeyLocator(KeyLocator("ndn:/test/key/locator"));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800953 i.setChildSelector(1);
954 i.setMustBeFresh(false);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800955 Exclude exclude;
956 exclude
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -0800957 .excludeOne(name::Component("alex"))
958 .excludeRange(name::Component("xxxx"), name::Component("yyyy"));
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800959 i.setExclude(exclude);
Alexander Afanasyev840139f2013-12-28 15:02:50 -0800960 i.setNonce(1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800961
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300962 BOOST_CHECK_EQUAL(i.hasWire(), false);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800963 const Block &wire = i.wireEncode();
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300964 BOOST_CHECK_EQUAL(i.hasWire(), true);
Alexander Afanasyev809805d2014-02-17 17:20:33 -0800965
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -0700966 BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1 + sizeof(Interest1),
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800967 wire.begin(), wire.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800968
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300969 const uint8_t* originalWire = wire.wire();
970 i.setNonce(2);
971 BOOST_CHECK_EQUAL(i.hasWire(), true);
972 BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire());
973 BOOST_CHECK_EQUAL(i.hasWire(), true);
974
975 BOOST_CHECK_EQUAL_COLLECTIONS(Interest2, Interest2 + sizeof(Interest2),
976 wire.begin(), wire.end());
Alexander Afanasyeva0c5f832014-06-19 13:27:56 -0700977
978 std::ostringstream strStream;
979 BOOST_CHECK_NO_THROW(strStream << i);
980
981 BOOST_CHECK_EQUAL(strStream.str(),
982 "/local/ndn/prefix?"
983 "ndn.MinSuffixComponents=1&ndn.MaxSuffixComponents=1&"
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -0700984 "ndn.ChildSelector=1&"
Alexander Afanasyeva0c5f832014-06-19 13:27:56 -0700985 "ndn.InterestLifetime=1000&"
986 "ndn.Nonce=2&ndn.Exclude=alex,xxxx,*,yyyy");
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700987
988 i.refreshNonce();
989 BOOST_CHECK_EQUAL(i.hasWire(), true);
990 BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire());
991 BOOST_CHECK_NE(i.getNonce(), 2);
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300992}
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800993
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700994BOOST_AUTO_TEST_CASE(DecodeEncode) // this test case to ensure that wireDecode resets all the fields
995{
996 Interest i1;
997 i1.setName("/test");
998 i1.setMinSuffixComponents(100);
999 i1.setNonce(10);
1000 i1.setInterestLifetime(time::seconds(10));
1001 i1.setLink(Block(LINK, sizeof(LINK)));
1002 i1.setSelectedDelegation(0);
1003
1004 Interest i2(i1.wireEncode());
1005
1006 BOOST_CHECK_EQUAL(i2.getName().toUri(), "/test");
1007 BOOST_CHECK_EQUAL(i2.getInterestLifetime(), time::seconds(10));
1008 BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), 100);
1009 BOOST_CHECK_EQUAL(i2.getNonce(), 10);
1010 BOOST_CHECK_EQUAL(i2.hasLink(), true);
1011 BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), true);
1012
1013 i2.wireDecode(Interest().wireEncode());
1014
1015 BOOST_CHECK_EQUAL(i2.getName().toUri(), "/");
1016 BOOST_CHECK_EQUAL(i2.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
1017 BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), -1);
1018 BOOST_WARN_NE(i2.getNonce(), 10);
1019 BOOST_CHECK_EQUAL(i2.hasLink(), false);
1020 BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), false);
1021}
1022
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001023BOOST_AUTO_TEST_CASE(MatchesData)
1024{
1025 Interest interest;
1026 interest.setName("ndn:/A")
1027 .setMinSuffixComponents(2)
1028 .setMaxSuffixComponents(2)
1029 .setPublisherPublicKeyLocator(KeyLocator("ndn:/B"))
1030 .setExclude(Exclude().excludeBefore(name::Component("C")));
1031
1032 Data data("ndn:/A/D");
Yingdi Yu4a557052014-07-09 16:40:37 -07001033 SignatureSha256WithRsa signature(KeyLocator("ndn:/B"));
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001034 data.setSignature(signature);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001035 data.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001036 BOOST_CHECK_EQUAL(interest.matchesData(data), true);
1037
1038 Data data1 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001039 data1.setName("ndn:/A"); // violates MinSuffixComponents
1040 data1.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001041 BOOST_CHECK_EQUAL(interest.matchesData(data1), false);
1042
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001043 interest.setMinSuffixComponents(1);
1044 BOOST_CHECK_EQUAL(interest.matchesData(data1), true);
1045 interest.setMinSuffixComponents(2);
1046
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001047 Data data2 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001048 data2.setName("ndn:/A/E/F"); // violates MaxSuffixComponents
1049 data2.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001050 BOOST_CHECK_EQUAL(interest.matchesData(data2), false);
1051
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001052 interest.setMaxSuffixComponents(3);
1053 BOOST_CHECK_EQUAL(interest.matchesData(data2), true);
1054 interest.setMaxSuffixComponents(2);
1055
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001056 Data data3 = data;
Yingdi Yu4a557052014-07-09 16:40:37 -07001057 SignatureSha256WithRsa signature3(KeyLocator("ndn:/G")); // violates PublisherPublicKeyLocator
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001058 data3.setSignature(signature3);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001059 data3.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001060 BOOST_CHECK_EQUAL(interest.matchesData(data3), false);
1061
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001062 interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/G"));
1063 BOOST_CHECK_EQUAL(interest.matchesData(data3), true);
1064 interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/B"));
1065
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001066 Data data4 = data;
Yingdi Yubf6a2812014-06-17 15:32:11 -07001067 DigestSha256 signature4; // violates PublisherPublicKeyLocator
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001068 data4.setSignature(signature4);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001069 data4.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001070 BOOST_CHECK_EQUAL(interest.matchesData(data4), false);
1071
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001072 interest.setPublisherPublicKeyLocator(KeyLocator());
1073 BOOST_CHECK_EQUAL(interest.matchesData(data4), true);
1074 interest.setPublisherPublicKeyLocator(KeyLocator("ndn:/B"));
1075
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001076 Data data5 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001077 data5.setName("ndn:/A/C"); // violates Exclude
1078 data5.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001079 BOOST_CHECK_EQUAL(interest.matchesData(data5), false);
1080
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001081 interest.setExclude(Exclude().excludeBefore(name::Component("A")));
1082 BOOST_CHECK_EQUAL(interest.matchesData(data5), true);
1083 interest.setExclude(Exclude().excludeBefore(name::Component("C")));
1084
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001085 Data data6 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001086 data6.setName("ndn:/H/I"); // violates Name
1087 data6.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001088 BOOST_CHECK_EQUAL(interest.matchesData(data6), false);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001089
1090 Data data7 = data;
1091 data7.setName("ndn:/A/B");
1092 data7.wireEncode();
1093
1094 interest = Interest()
Alexander Afanasyev56860f52014-11-07 11:51:17 -08001095 .setName("/A/B/sha256digest=D548DECEFC4B880720DC9257A8D815E9DF4465E63742EE55C29133055DAA67C2");
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001096 BOOST_CHECK_EQUAL(interest.matchesData(data7), true);
1097
1098 interest = Interest()
1099 .setName("/A/B/%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00"
1100 "%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00");
1101 BOOST_CHECK_EQUAL(interest.matchesData(data7), false); // violates implicit digest
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001102}
1103
Alexander Afanasyev90164962014-03-06 08:29:59 +00001104BOOST_AUTO_TEST_CASE(InterestFilterMatching)
1105{
1106 BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true);
1107 BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true);
1108 BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false);
1109
1110 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true);
1111 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false);
1112
1113 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false);
1114 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true);
1115
1116 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false);
1117 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true);
1118 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true);
1119 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false);
1120 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true);
1121}
1122
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001123BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -08001124
Alexander Afanasyev90164962014-03-06 08:29:59 +00001125} // namespace tests
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -08001126} // namespace ndn