blob: 3e314386fc091054681196f8b43dac05eaaaef76 [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 Afanasyev1013fd02017-01-03 13:19:03 -08003 * Copyright (c) 2013-2017 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"
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070027#include "encoding/buffer-stream.hpp"
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070028
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070029#include "boost-test.hpp"
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070030#include "identity-management-fixture.hpp"
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080031
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080032namespace ndn {
Alexander Afanasyev90164962014-03-06 08:29:59 +000033namespace tests {
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080034
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070035BOOST_FIXTURE_TEST_SUITE(TestInterest, IdentityManagementFixture)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -080036
37const uint8_t Interest1[] = {
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -070038 0x05, 0x59, // NDN Interest
Alexander Afanasyev4b456282014-02-13 00:34:34 -080039 0x07, 0x14, // Name
40 0x08, 0x5, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080041 0x6c, 0x6f, 0x63, 0x61, 0x6c,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080042 0x08, 0x3, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080043 0x6e, 0x64, 0x6e,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080044 0x08, 0x6, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080045 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
Junxiao Shib332e782014-03-31 14:23:46 -070046 0x09, 0x37, // Selectors
Alexander Afanasyev4b456282014-02-13 00:34:34 -080047 0x0d, 0x1, 0x1, // MinSuffix
48 0x0e, 0x1, 0x1, // MaxSuffix
Junxiao Shib332e782014-03-31 14:23:46 -070049 0x1c, 0x16, // KeyLocator
50 0x07, 0x14, // Name
51 0x08, 0x04,
52 0x74, 0x65, 0x73, 0x74,
53 0x08, 0x03,
54 0x6b, 0x65, 0x79,
55 0x08, 0x07,
56 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080057 0x10, 0x14, // Exclude
58 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080059 0x61, 0x6c, 0x65, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080060 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080061 0x78, 0x78, 0x78, 0x78,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080062 0x13, 0x0, // Any
63 0x08, 0x4, // NameComponent
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080064 0x79, 0x79, 0x79, 0x79,
Alexander Afanasyev4b456282014-02-13 00:34:34 -080065 0x11, 0x1, // ChildSelector
Alexander Afanasyev636e9f12014-01-07 12:01:03 -080066 0x1,
Alexander Afanasyeve881e932014-06-08 14:47:03 +030067 0x0a, 0x4, // Nonce
68 0x1, 0x0, 0x0, 0x00,
Alexander Afanasyeve881e932014-06-08 14:47:03 +030069 0x0c, // InterestLifetime
70 0x2, 0x3, 0xe8
71};
72
73const uint8_t Interest2[] = {
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -070074 0x05, 0x59, // NDN Interest
Alexander Afanasyeve881e932014-06-08 14:47:03 +030075 0x07, 0x14, // Name
76 0x08, 0x5, // NameComponent
77 0x6c, 0x6f, 0x63, 0x61, 0x6c,
78 0x08, 0x3, // NameComponent
79 0x6e, 0x64, 0x6e,
80 0x08, 0x6, // NameComponent
81 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
82 0x09, 0x37, // Selectors
83 0x0d, 0x1, 0x1, // MinSuffix
84 0x0e, 0x1, 0x1, // MaxSuffix
85 0x1c, 0x16, // KeyLocator
86 0x07, 0x14, // Name
87 0x08, 0x04,
88 0x74, 0x65, 0x73, 0x74,
89 0x08, 0x03,
90 0x6b, 0x65, 0x79,
91 0x08, 0x07,
92 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
93 0x10, 0x14, // Exclude
94 0x08, 0x4, // NameComponent
95 0x61, 0x6c, 0x65, 0x78,
96 0x08, 0x4, // NameComponent
97 0x78, 0x78, 0x78, 0x78,
98 0x13, 0x0, // Any
99 0x08, 0x4, // NameComponent
100 0x79, 0x79, 0x79, 0x79,
101 0x11, 0x1, // ChildSelector
102 0x1,
103 0x0a, 0x4, // Nonce
104 0x2, 0x0, 0x0, 0x00,
Alexander Afanasyev4b456282014-02-13 00:34:34 -0800105 0x0c, // InterestLifetime
Alexander Afanasyev636e9f12014-01-07 12:01:03 -0800106 0x2, 0x3, 0xe8
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -0800107};
108
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700109const uint8_t InterestWithLink[] = {
110 0x05, 0xfb, // Interest
111 0x07, 0x14, // Name
112 0x08, 0x5, // NameComponent
113 0x6c, 0x6f, 0x63, 0x61, 0x6c,
114 0x08, 0x3, // NameComponent
115 0x6e, 0x64, 0x6e,
116 0x08, 0x6, // NameComponent
117 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
118 0x0a, 0x4, // Nonce
119 0x1, 0x0, 0x0, 0x00,
120 0x06, 0xda, // Data
121 0x07, 0x14, // Name
122 0x08, 0x05,
123 0x6c, 0x6f, 0x63, 0x61, 0x6c,
124 0x08, 0x03,
125 0x6e, 0x64, 0x6e,
126 0x08, 0x06,
127 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
128 0x14, 0x07, // MetaInfo
129 0x18, 0x01, // ContentType
130 0x01,
131 0x19, 0x02, // FreshnessPeriod
132 0x27, 0x10,
133 0x15, 0x1a, // Content
134 0x1f, 0x0c, // LinkDelegation
135 0x1e, 0x01, // LinkPreference
136 0x0a,
137 0x07, 0x07, // Name
138 0x08, 0x05,
139 0x6c, 0x6f, 0x63, 0x61, 0x6c,
140 0x1f, 0x0a, // LinkDelegation
141 0x1e, 0x01, // LinkPreference
142 0x14,
143 0x07, 0x05, // Name
144 0x08, 0x03,
145 0x6e, 0x64, 0x6e,
146 0x16, 0x1b, // SignatureInfo
147 0x1b, 0x01, // SignatureType
148 0x01,
149 0x1c, 0x16, // KeyLocator
150 0x07, 0x14, // Name
151 0x08, 0x04,
152 0x74, 0x65, 0x73, 0x74,
153 0x08, 0x03,
154 0x6b, 0x65, 0x79,
155 0x08, 0x07,
156 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
157 0x17, 0x80, // SignatureValue
158 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
159 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
160 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
161 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
162 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
163 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
164 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
165 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
166 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
167 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
168 0x20, 0x01, // SelectedDelegation
169 0x00
170};
171
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700172const uint8_t LINK[] = {
173 0x06, 0xda, // Data
174 0x07, 0x14, // Name
175 0x08, 0x05,
176 0x6c, 0x6f, 0x63, 0x61, 0x6c,
177 0x08, 0x03,
178 0x6e, 0x64, 0x6e,
179 0x08, 0x06,
180 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
181 0x14, 0x07, // MetaInfo
182 0x18, 0x01, // ContentType
183 0x01,
184 0x19, 0x02, // FreshnessPeriod
185 0x27, 0x10,
186 0x15, 0x1a, // Content
187 0x1f, 0x0c, // LinkDelegation
188 0x1e, 0x01, // LinkPreference
189 0x0a,
190 0x07, 0x07, // Name
191 0x08, 0x05,
192 0x6c, 0x6f, 0x63, 0x61, 0x6c,
193 0x1f, 0x0a, // LinkDelegation
194 0x1e, 0x01, // LinkPreference
195 0x14,
196 0x07, 0x05, // Name
197 0x08, 0x03,
198 0x6e, 0x64, 0x6e,
199 0x16, 0x1b, // SignatureInfo
200 0x1b, 0x01, // SignatureType
201 0x01,
202 0x1c, 0x16, // KeyLocator
203 0x07, 0x14, // Name
204 0x08, 0x04,
205 0x74, 0x65, 0x73, 0x74,
206 0x08, 0x03,
207 0x6b, 0x65, 0x79,
208 0x08, 0x07,
209 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
210 0x17, 0x80, // SignatureValue
211 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
212 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
213 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
214 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
215 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
216 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
217 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
218 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
219 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
220 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1
221};
222
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700223const uint8_t InterestWithLinkMissingContentType[] = {
224 0x05, 0xf8, // Interest
225 0x07, 0x14, // Name
226 0x08, 0x5, // NameComponent
227 0x6c, 0x6f, 0x63, 0x61, 0x6c,
228 0x08, 0x3, // NameComponent
229 0x6e, 0x64, 0x6e,
230 0x08, 0x6, // NameComponent
231 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
232 0x0a, 0x4, // Nonce
233 0x1, 0x0, 0x0, 0x00,
234 0x06, 0xd7, // Data
235 0x07, 0x14, // Name
236 0x08, 0x05,
237 0x6c, 0x6f, 0x63, 0x61, 0x6c,
238 0x08, 0x03,
239 0x6e, 0x64, 0x6e,
240 0x08, 0x06,
241 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
242 0x14, 0x04, // MetaInfo
243 0x19, 0x02, // FreshnessPeriod
244 0x27, 0x10,
245 0x15, 0x1a, // Content
246 0x1f, 0x0c, // LinkDelegation
247 0x1e, 0x01, // LinkPreference
248 0x0a,
249 0x07, 0x07, // Name
250 0x08, 0x05,
251 0x6c, 0x6f, 0x63, 0x61, 0x6c,
252 0x1f, 0x0a, // LinkDelegation
253 0x1e, 0x01, // LinkPreference
254 0x14,
255 0x07, 0x05, // Name
256 0x08, 0x03,
257 0x6e, 0x64, 0x6e,
258 0x16, 0x1b, // SignatureInfo
259 0x1b, 0x01, // SignatureType
260 0x01,
261 0x1c, 0x16, // KeyLocator
262 0x07, 0x14, // Name
263 0x08, 0x04,
264 0x74, 0x65, 0x73, 0x74,
265 0x08, 0x03,
266 0x6b, 0x65, 0x79,
267 0x08, 0x07,
268 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
269 0x17, 0x80, // SignatureValue
270 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
271 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
272 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
273 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
274 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
275 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
276 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
277 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
278 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
279 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
280 0x20, 0x01, // SelectedDelegation
281 0x00
282};
283
284const uint8_t InterestWithLinkNoMetaInfo[] = {
285 0x05, 0xf2, // Interest
286 0x07, 0x14, // Name
287 0x08, 0x5, // NameComponent
288 0x6c, 0x6f, 0x63, 0x61, 0x6c,
289 0x08, 0x3, // NameComponent
290 0x6e, 0x64, 0x6e,
291 0x08, 0x6, // NameComponent
292 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
293 0x0a, 0x4, // Nonce
294 0x1, 0x0, 0x0, 0x00,
295 0x06, 0xd1, // Data
296 0x07, 0x14, // Name
297 0x08, 0x05,
298 0x6c, 0x6f, 0x63, 0x61, 0x6c,
299 0x08, 0x03,
300 0x6e, 0x64, 0x6e,
301 0x08, 0x06,
302 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
303 0x15, 0x1a, // Content
304 0x1f, 0x0c, // LinkDelegation
305 0x1e, 0x01, // LinkPreference
306 0x0a,
307 0x07, 0x07, // Name
308 0x08, 0x05,
309 0x6c, 0x6f, 0x63, 0x61, 0x6c,
310 0x1f, 0x0a, // LinkPreference
311 0x1e, 0x01, // LinkPreference
312 0x14,
313 0x07, 0x05, // Name
314 0x08, 0x03,
315 0x6e, 0x64, 0x6e,
316 0x16, 0x1b, // SignatureInfo
317 0x1b, 0x01, // SignatureType
318 0x01,
319 0x1c, 0x16, // KeyLocator
320 0x07, 0x14, // Name
321 0x08, 0x04,
322 0x74, 0x65, 0x73, 0x74,
323 0x08, 0x03,
324 0x6b, 0x65, 0x79,
325 0x08, 0x07,
326 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
327 0x17, 0x80, // SignatureValue
328 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
329 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
330 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
331 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
332 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
333 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
334 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
335 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
336 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
337 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
338 0x20, 0x01, // SelectedDelegation
339 0x00
340};
341
342const uint8_t InterestWithLinkWrongContentType[] = {
343 0x05, 0xfb, // Interest
344 0x07, 0x14, // Name
345 0x08, 0x5, // NameComponent
346 0x6c, 0x6f, 0x63, 0x61, 0x6c,
347 0x08, 0x3, // NameComponent
348 0x6e, 0x64, 0x6e,
349 0x08, 0x6, // NameComponent
350 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
351 0x0a, 0x4, // Nonce
352 0x1, 0x0, 0x0, 0x00,
353 0x06, 0xda, // Data
354 0x07, 0x14, // Name
355 0x08, 0x05,
356 0x6c, 0x6f, 0x63, 0x61, 0x6c,
357 0x08, 0x03,
358 0x6e, 0x64, 0x6e,
359 0x08, 0x06,
360 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
361 0x14, 0x07, // MetaInfo
362 0x18, 0x01, // ContentType
363 0x00,
364 0x19, 0x02, // FreshnessPeriod
365 0x27, 0x10,
366 0x15, 0x1a, // Content
367 0x1f, 0x0c, // LinkDelegation
368 0x1e, 0x01, // LinkPreference
369 0x0a,
370 0x07, 0x07, // Name
371 0x08, 0x05,
372 0x6c, 0x6f, 0x63, 0x61, 0x6c,
373 0x1f, 0x0a, // LinkDelegation
374 0x1e, 0x01, // LinkPreference
375 0x14,
376 0x07, 0x05, // Name
377 0x08, 0x03,
378 0x6e, 0x64, 0x6e,
379 0x16, 0x1b, // SignatureInfo
380 0x1b, 0x01, // SignatureType
381 0x01,
382 0x1c, 0x16, // KeyLocator
383 0x07, 0x14, // Name
384 0x08, 0x04,
385 0x74, 0x65, 0x73, 0x74,
386 0x08, 0x03,
387 0x6b, 0x65, 0x79,
388 0x08, 0x07,
389 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
390 0x17, 0x80, // SignatureValue
391 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
392 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
393 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
394 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
395 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
396 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
397 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
398 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
399 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
400 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
401 0x20, 0x01, // SelectedDelegation
402 0x00
403};
404
405const uint8_t InterestWithSelectedDelegationButNoLink[] = {
406 0x05, 0x1f, // Interest
407 0x07, 0x14, // Name
408 0x08, 0x5, // NameComponent
409 0x6c, 0x6f, 0x63, 0x61, 0x6c,
410 0x08, 0x3, // NameComponent
411 0x6e, 0x64, 0x6e,
412 0x08, 0x6, // NameComponent
413 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
414 0x0a, 0x4, // Nonce
415 0x1, 0x0, 0x0, 0x00,
416 0x20, 0x01, // SelectedDelegation
417 0x00
418};
419
420const uint8_t InterestWithLinkNotNonIntegerSelectedDelegation[] = {
421 0x05, 0xfb, // Interest
422 0x07, 0x14, // Name
423 0x08, 0x5, // NameComponent
424 0x6c, 0x6f, 0x63, 0x61, 0x6c,
425 0x08, 0x3, // NameComponent
426 0x6e, 0x64, 0x6e,
427 0x08, 0x6, // NameComponent
428 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
429 0x0a, 0x4, // Nonce
430 0x1, 0x0, 0x0, 0x00,
431 0x06, 0xda, // Data
432 0x07, 0x14, // Name
433 0x08, 0x05,
434 0x6c, 0x6f, 0x63, 0x61, 0x6c,
435 0x08, 0x03,
436 0x6e, 0x64, 0x6e,
437 0x08, 0x06,
438 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
439 0x14, 0x07, // MetaInfo
440 0x18, 0x01, // ContentType
441 0x01,
442 0x19, 0x02, // FreshnessPeriod
443 0x27, 0x10,
444 0x15, 0x1a, // Content
445 0x1f, 0x0c, // LinkDelegation
446 0x1e, 0x01, // LinkPreference
447 0x0a,
448 0x07, 0x07, // Name
449 0x08, 0x05,
450 0x6c, 0x6f, 0x63, 0x61, 0x6c,
451 0x1f, 0x0a, // LinkDelegation
452 0x1e, 0x01, // LinkPreference
453 0x14,
454 0x07, 0x05, // Name
455 0x08, 0x03,
456 0x6e, 0x64, 0x6e,
457 0x16, 0x1b, // SignatureInfo
458 0x1b, 0x01, // SignatureType
459 0x01,
460 0x1c, 0x16, // KeyLocator
461 0x07, 0x14, // Name
462 0x08, 0x04,
463 0x74, 0x65, 0x73, 0x74,
464 0x08, 0x03,
465 0x6b, 0x65, 0x79,
466 0x08, 0x07,
467 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
468 0x17, 0x78, // SignatureValue
469 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
470 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
471 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
472 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
473 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
474 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
475 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
476 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
477 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
478 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7,
479 0x20, 0x03, // SelectedDelegation
480 0xAA, 0xAA, 0xAA
481};
482
483const uint8_t InterestWithLinkNonDecreasingOrder[] = {
484 0x05, 0xfb, // Interest
485 0x07, 0x14, // Name
486 0x08, 0x5, // NameComponent
487 0x6c, 0x6f, 0x63, 0x61, 0x6c,
488 0x08, 0x3, // NameComponent
489 0x6e, 0x64, 0x6e,
490 0x08, 0x6, // NameComponent
491 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
492 0x0a, 0x4, // Nonce
493 0x1, 0x0, 0x0, 0x00,
494 0x06, 0xda, // Data
495 0x07, 0x14, // Name
496 0x08, 0x05,
497 0x6c, 0x6f, 0x63, 0x61, 0x6c,
498 0x08, 0x03,
499 0x6e, 0x64, 0x6e,
500 0x08, 0x06,
501 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
502 0x14, 0x07, // MetaInfo
503 0x18, 0x01, // ContentType
504 0x01,
505 0x19, 0x02, // FreshnessPeriod
506 0x27, 0x10,
507 0x15, 0x1a, // Content
508 0x1f, 0x0c, // LinkDelegation
509 0x1e, 0x01, // LinkPreference
510 0x14,
511 0x07, 0x07, // Name
512 0x08, 0x05,
513 0x6c, 0x6f, 0x63, 0x61, 0x6c,
514 0x1f, 0x0a, // LinkDelegation
515 0x1e, 0x01, // LinkPreference
516 0x0a,
517 0x07, 0x05, // Name
518 0x08, 0x03,
519 0x6e, 0x64, 0x6e,
520 0x16, 0x1b, // SignatureInfo
521 0x1b, 0x01, // SignatureType
522 0x01,
523 0x1c, 0x16, // KeyLocator
524 0x07, 0x14, // Name
525 0x08, 0x04,
526 0x74, 0x65, 0x73, 0x74,
527 0x08, 0x03,
528 0x6b, 0x65, 0x79,
529 0x08, 0x07,
530 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
531 0x17, 0x80, // SignatureValue
532 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
533 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
534 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
535 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
536 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
537 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
538 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
539 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
540 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
541 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
542 0x20, 0x01, // SelectedDelegation
543 0x01
544};
545
Eric Newberryb555b002017-05-17 00:30:44 -0700546BOOST_AUTO_TEST_CASE(DefaultValues)
547{
548 Interest i;
549 BOOST_CHECK_EQUAL(i.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
550 BOOST_CHECK(!i.hasSelectedDelegation());
551}
552
553BOOST_AUTO_TEST_CASE(EncodeChildSelector)
554{
555 Interest i;
556 i.setName("/local/ndn/prefix");
557 i.setNonce(1);
558 BOOST_CHECK_EQUAL(i.getChildSelector(), 0);
559 BOOST_CHECK_THROW(i.setChildSelector(-1), std::invalid_argument);
560 BOOST_CHECK_THROW(i.setChildSelector(2), std::invalid_argument);
561 BOOST_CHECK_NO_THROW(i.setChildSelector(1));
562 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
563 BOOST_CHECK_NO_THROW(i.setChildSelector(0));
564 BOOST_CHECK_EQUAL(i.getChildSelector(), 0);
565
566 const uint8_t expectedDefault[] = {
567 0x05, 0x1e, // MetaInfo
568 0x07, 0x14, // Name
569 0x08, 0x5, // NameComponent
570 0x6c, 0x6f, 0x63, 0x61, 0x6c,
571 0x08, 0x3, // NameComponent
572 0x6e, 0x64, 0x6e,
573 0x08, 0x6, // NameComponent
574 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
575 0x09, 0x00, // Selectors
576 0x0a, 0x04, // Nonce
577 0x01, 0x00, 0x00, 0x00, // 1
578 };
579
580 BOOST_CHECK_EQUAL_COLLECTIONS(i.wireEncode().begin(), i.wireEncode().end(),
581 expectedDefault, expectedDefault + sizeof(expectedDefault));
582
583 const uint8_t expected1[] = {
584 0x05, 0x21, // MetaInfo
585 0x07, 0x14, // Name
586 0x08, 0x5, // NameComponent
587 0x6c, 0x6f, 0x63, 0x61, 0x6c,
588 0x08, 0x3, // NameComponent
589 0x6e, 0x64, 0x6e,
590 0x08, 0x6, // NameComponent
591 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
592 0x09, 0x03, // Selectors
593 0x11, 0x01, // ChildSelector
594 0x01, // 1
595 0x0a, 0x04, // Nonce
596 0x01, 0x00, 0x00, 0x00, // 1
597 };
598
599 i.setChildSelector(1);
600 BOOST_CHECK_EQUAL_COLLECTIONS(i.wireEncode().begin(), i.wireEncode().end(),
601 expected1, expected1 + sizeof(expected1));
602}
603
604BOOST_AUTO_TEST_CASE(EncodeInterestLifetime)
605{
606 Interest i;
607 i.setName("/local/ndn/prefix");
608 i.setNonce(1);
609 BOOST_CHECK_EQUAL(i.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
610 BOOST_CHECK_THROW(i.setInterestLifetime(time::milliseconds(-1)), std::invalid_argument);
611 BOOST_CHECK_EQUAL(i.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
612 BOOST_CHECK_NO_THROW(i.setInterestLifetime(time::milliseconds(1)));
613 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1));
614 BOOST_CHECK_NO_THROW(i.setInterestLifetime(DEFAULT_INTEREST_LIFETIME));
615
616 const uint8_t expectedDefault[] = {
617 0x05, 0x1e, // MetaInfo
618 0x07, 0x14, // Name
619 0x08, 0x5, // NameComponent
620 0x6c, 0x6f, 0x63, 0x61, 0x6c,
621 0x08, 0x3, // NameComponent
622 0x6e, 0x64, 0x6e,
623 0x08, 0x6, // NameComponent
624 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
625 0x09, 0x00, // Selectors
626 0x0a, 0x04, // Nonce
627 0x01, 0x00, 0x00, 0x00, // 1
628 };
629
630 BOOST_CHECK_EQUAL_COLLECTIONS(i.wireEncode().begin(), i.wireEncode().end(),
631 expectedDefault, expectedDefault + sizeof(expectedDefault));
632
633 const uint8_t expected1000ms[] = {
634 0x05, 0x22, // MetaInfo
635 0x07, 0x14, // Name
636 0x08, 0x5, // NameComponent
637 0x6c, 0x6f, 0x63, 0x61, 0x6c,
638 0x08, 0x3, // NameComponent
639 0x6e, 0x64, 0x6e,
640 0x08, 0x6, // NameComponent
641 0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
642 0x09, 0x00, // Selectors
643 0x0a, 0x04, // Nonce
644 0x01, 0x00, 0x00, 0x00, // 1
645 0x0c, 0x02, // InterestLifetime
646 0x03, 0xe8
647 };
648
649 BOOST_CHECK_NO_THROW(i.setInterestLifetime(time::milliseconds(1000)));
650 BOOST_CHECK_EQUAL_COLLECTIONS(i.wireEncode().begin(), i.wireEncode().end(),
651 expected1000ms, expected1000ms + sizeof(expected1000ms));
652}
653
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700654BOOST_AUTO_TEST_CASE(InterestEqualityChecks)
655{
656 // Interest ::= INTEREST-TYPE TLV-LENGTH
657 // Name
658 // Selectors?
659 // Nonce
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700660 // InterestLifetime?
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700661 // Link?
662 // SelectedDelegation?
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700663
664 Interest a;
665 Interest b;
666
667 // if nonce is not set, it will be set to a random value
668 a.setNonce(1);
669 b.setNonce(1);
670
671 BOOST_CHECK_EQUAL(a == b, true);
672 BOOST_CHECK_EQUAL(a != b, false);
673
674 // check comparison on Name
675 a.setName("ndn:/A");
676 BOOST_CHECK_EQUAL(a == b, false);
677 BOOST_CHECK_EQUAL(a != b, true);
678
679 b.setName("ndn:/B");
680 BOOST_CHECK_EQUAL(a == b, false);
681 BOOST_CHECK_EQUAL(a != b, true);
682
683 b.setName("ndn:/A");
684 BOOST_CHECK_EQUAL(a == b, true);
685 BOOST_CHECK_EQUAL(a != b, false);
686
687 // check comparison on Selectors
688 a.setChildSelector(1);
689 BOOST_CHECK_EQUAL(a == b, false);
690 BOOST_CHECK_EQUAL(a != b, true);
691
692 b.setChildSelector(1);
693 BOOST_CHECK_EQUAL(a == b, true);
694 BOOST_CHECK_EQUAL(a != b, false);
695
696 // check comparison on Nonce
697 a.setNonce(100);
698 BOOST_CHECK_EQUAL(a == b, false);
699 BOOST_CHECK_EQUAL(a != b, true);
700
701 b.setNonce(100);
702 BOOST_CHECK_EQUAL(a == b, true);
703 BOOST_CHECK_EQUAL(a != b, false);
704
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700705 // check comparison on InterestLifetime
706 a.setInterestLifetime(time::seconds(10));
707 BOOST_CHECK_EQUAL(a == b, false);
708 BOOST_CHECK_EQUAL(a != b, true);
709
710 b.setInterestLifetime(time::seconds(10));
711 BOOST_CHECK_EQUAL(a == b, true);
712 BOOST_CHECK_EQUAL(a != b, false);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700713
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700714 a.setLink(Block(LINK, sizeof(LINK)));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700715 BOOST_CHECK_EQUAL(a == b, false);
716 BOOST_CHECK_EQUAL(a != b, true);
717
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700718 b.setLink(Block(LINK, sizeof(LINK)));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700719 BOOST_CHECK_EQUAL(a == b, true);
720 BOOST_CHECK_EQUAL(a != b, false);
721
722 // Selected Delegation
723 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
724 BOOST_CHECK_EQUAL(b.hasSelectedDelegation(), false);
725
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700726 a.setSelectedDelegation(Name("/local"));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700727 BOOST_CHECK_EQUAL(a == b, false);
728 BOOST_CHECK_EQUAL(a != b, true);
729
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700730 b.setSelectedDelegation(Name("/local"));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700731 BOOST_CHECK_EQUAL(a == b, true);
732 BOOST_CHECK_EQUAL(a != b, false);
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700733}
734
735BOOST_AUTO_TEST_CASE(SelectorsEqualityChecks)
736{
737 // Selectors ::= SELECTORS-TYPE TLV-LENGTH
738 // MinSuffixComponents?
739 // MaxSuffixComponents?
740 // PublisherPublicKeyLocator?
741 // Exclude?
742 // ChildSelector?
743 // MustBeFresh?
744
745 Selectors a;
746 Selectors b;
747 BOOST_CHECK_EQUAL(a == b, true);
748 BOOST_CHECK_EQUAL(a != b, false);
749
750 // MinSuffixComponents
751 a.setMinSuffixComponents(1);
752 BOOST_CHECK_EQUAL(a == b, false);
753 BOOST_CHECK_EQUAL(a != b, true);
754
755 b.setMinSuffixComponents(2);
756 BOOST_CHECK_EQUAL(a == b, false);
757 BOOST_CHECK_EQUAL(a != b, true);
758
759 b.setMinSuffixComponents(1);
760 BOOST_CHECK_EQUAL(a == b, true);
761 BOOST_CHECK_EQUAL(a != b, false);
762
763 // MaxSuffixComponents
764 a.setMaxSuffixComponents(10);
765 BOOST_CHECK_EQUAL(a == b, false);
766 BOOST_CHECK_EQUAL(a != b, true);
767
768 b.setMaxSuffixComponents(10);
769 BOOST_CHECK_EQUAL(a == b, true);
770 BOOST_CHECK_EQUAL(a != b, false);
771
772 // PublisherPublicKeyLocator
773 a.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
774 BOOST_CHECK_EQUAL(a == b, false);
775 BOOST_CHECK_EQUAL(a != b, true);
776
777 b.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
778 BOOST_CHECK_EQUAL(a == b, true);
779 BOOST_CHECK_EQUAL(a != b, false);
780
781 // Exclude
782 a.setExclude(Exclude().excludeOne(name::Component("exclude")));
783 BOOST_CHECK_EQUAL(a == b, false);
784 BOOST_CHECK_EQUAL(a != b, true);
785
786 b.setExclude(Exclude().excludeOne(name::Component("exclude")));
787 BOOST_CHECK_EQUAL(a == b, true);
788 BOOST_CHECK_EQUAL(a != b, false);
789
790 // ChildSelector
791 a.setChildSelector(1);
792 BOOST_CHECK_EQUAL(a == b, false);
793 BOOST_CHECK_EQUAL(a != b, true);
794
795 b.setChildSelector(1);
796 BOOST_CHECK_EQUAL(a == b, true);
797 BOOST_CHECK_EQUAL(a != b, false);
798
799 // MustBeFresh
800 a.setMustBeFresh(true);
801 BOOST_CHECK_EQUAL(a == b, false);
802 BOOST_CHECK_EQUAL(a != b, true);
803
804 b.setMustBeFresh(true);
805 BOOST_CHECK_EQUAL(a == b, true);
806 BOOST_CHECK_EQUAL(a != b, false);
807}
808
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700809BOOST_AUTO_TEST_CASE(LinkObject)
810{
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700811 Link link1("test", {{100, "/test3"}, {20, "/test2"}, {10, "/test1"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700812 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700813 Block wire = link1.wireEncode();
814
815 Interest a;
816 BOOST_REQUIRE_NO_THROW(a.setLink(wire));
817
818 BOOST_REQUIRE_NO_THROW(a.getLink());
819
820 Link link2 = a.getLink();
821 Name name = link2.getName();
822 BOOST_CHECK_EQUAL(Name("test"), name);
823 BOOST_CHECK_EQUAL(a.hasLink(), true);
824 Link::DelegationSet delegations;
825 delegations = link2.getDelegations();
826
827 auto i = delegations.begin();
828 BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
829 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
830 ++i;
831 BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
832 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
833 ++i;
834 BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
835 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
836
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700837 a.setLink(Block(LINK, sizeof(LINK)));
838 BOOST_CHECK_EQUAL(a.getLink().getDelegations().size(), 2);
839
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700840 a.unsetLink();
841 BOOST_CHECK_EQUAL(a.hasLink(), false);
842}
843
844BOOST_AUTO_TEST_CASE(SelectedDelegationChecks)
845{
846 Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700847 m_keyChain.sign(link);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700848 Block wire = link.wireEncode();
849
850 Interest a;
851 a.setLink(wire);
852 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
853
854 BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(Name("test2")));
855 BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test2"));
856
857 BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(uint32_t(2)));
858 BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test3"));
859
860 a.unsetSelectedDelegation();
861 BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
862}
863
864BOOST_AUTO_TEST_CASE(EncodeDecodeWithLink)
865{
866 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700867 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700868 Block wire = link1.wireEncode();
869
870 Interest a;
871 a.setName("/Test/Encode/Decode/With/Link");
872 a.setChildSelector(1);
873 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700874 a.setInterestLifetime(time::seconds(10));
875 a.setLink(wire);
876
877 Block interestBlock = a.wireEncode();
878 Interest b(interestBlock);
879
880 BOOST_CHECK_EQUAL(a == b, true);
881
882 Link link2 = b.getLink();
883 Link::DelegationSet delegations;
884 delegations = link2.getDelegations();
885
886 auto i = delegations.begin();
887 BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
888 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
889 ++i;
890 BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
891 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
892 ++i;
893 BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
894 BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
895
896}
897
898BOOST_AUTO_TEST_CASE(DecodeInterestWithLink)
899{
900 Block interestBlock(InterestWithLink, sizeof(InterestWithLink));
901
902 ndn::Interest i;
903 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
904 Link link = i.getLink();
905 BOOST_CHECK_EQUAL(link.getName(), Name("/local/ndn/prefix"));
906 Link::DelegationSet delegations = link.getDelegations();
907
908 auto it = delegations.begin();
909 BOOST_CHECK_EQUAL(std::get<0>(*it), 10);
910 BOOST_CHECK_EQUAL(std::get<1>(*it), Name("local"));
911 ++it;
912 BOOST_CHECK_EQUAL(std::get<0>(*it), 20);
913 BOOST_CHECK_EQUAL(std::get<1>(*it), Name("ndn"));
914
915 BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
916 BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("local"));
917}
918
919BOOST_AUTO_TEST_CASE(DecodeInterestWithLinkNonDecreasingOrder)
920{
921 Block interestBlock(InterestWithLinkNonDecreasingOrder,
922 sizeof(InterestWithLinkNonDecreasingOrder));
923
924 ndn::Interest i;
925 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
926 BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
927 BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("ndn"));
928}
929
930BOOST_AUTO_TEST_CASE(LinkObjectMissingContentType)
931{
932 Block interestBlock(InterestWithLinkMissingContentType,
933 sizeof(InterestWithLinkMissingContentType));
934
935 ndn::Interest i;
936 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
937 BOOST_REQUIRE_THROW(i.getLink(), Link::Error);
938}
939
940BOOST_AUTO_TEST_CASE(LinkObjectNoMetaInfo)
941{
942 Block interestBlock(InterestWithLinkNoMetaInfo,
943 sizeof(InterestWithLinkNoMetaInfo));
944
945 ndn::Interest i;
946 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700947 BOOST_CHECK_THROW(i.getLink(), tlv::Error);
948 BOOST_CHECK_THROW(i.getLink(), tlv::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700949}
950
951BOOST_AUTO_TEST_CASE(LinkObjectWrongContentType)
952{
953 Block interestBlock(InterestWithLinkWrongContentType,
954 sizeof(InterestWithLinkWrongContentType));
955
956 ndn::Interest i;
957 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700958 BOOST_CHECK_THROW(i.getLink(), Link::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700959}
960
961BOOST_AUTO_TEST_CASE(InterestContainingSelectedDelegationButNoLink)
962{
963 Block interestBlock(InterestWithSelectedDelegationButNoLink,
964 sizeof(InterestWithSelectedDelegationButNoLink));
965
966 ndn::Interest i;
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700967 BOOST_CHECK_THROW(i.wireDecode(interestBlock), Interest::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700968}
969
970BOOST_AUTO_TEST_CASE(SelectedDelegationIsNotNonNegativeInteger)
971{
972 Block interestBlock(InterestWithLinkNotNonIntegerSelectedDelegation,
973 sizeof(InterestWithLinkNotNonIntegerSelectedDelegation));
974
975 ndn::Interest i;
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700976 BOOST_CHECK_THROW(i.wireDecode(interestBlock), tlv::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700977}
978
979BOOST_AUTO_TEST_CASE(SelectedDelegationEqualToDelegationCount)
980{
981 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700982 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700983 Block wire = link1.wireEncode();
984
985 Interest a;
986 a.setName("/Test/Encode/Decode/With/Link");
987 a.setChildSelector(1);
988 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700989 a.setInterestLifetime(time::seconds(10));
990 a.setLink(wire);
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700991 BOOST_CHECK_THROW(a.setSelectedDelegation(3), Interest::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700992}
993
994BOOST_AUTO_TEST_CASE(SelectedDelegationGreaterThanDelegationCount)
995{
996 Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -0700997 m_keyChain.sign(link1);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700998 Block wire = link1.wireEncode();
999
1000 Interest a;
1001 a.setName("/Test/Encode/Decode/With/Link");
1002 a.setChildSelector(1);
1003 a.setNonce(100);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -07001004 a.setInterestLifetime(time::seconds(10));
1005 a.setLink(wire);
Alexander Afanasyevcac08382015-09-02 14:52:40 -07001006 BOOST_CHECK_THROW(a.setSelectedDelegation(4), Interest::Error);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -07001007}
1008
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001009BOOST_AUTO_TEST_CASE(Decode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001010{
1011 Block interestBlock(Interest1, sizeof(Interest1));
Alexander Afanasyev636e9f12014-01-07 12:01:03 -08001012
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001013 ndn::Interest i;
Alexander Afanasyev049f8f72013-12-26 19:07:15 -08001014 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001015
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001016 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001017 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
1018 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
1019 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
1020 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getType(),
1021 static_cast<uint32_t>(KeyLocator::KeyLocator_Name));
1022 BOOST_CHECK_EQUAL(i.getPublisherPublicKeyLocator().getName(), "ndn:/test/key/locator");
1023 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
1024 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
1025 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
1026 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyevcac08382015-09-02 14:52:40 -07001027 BOOST_CHECK_EQUAL(i.hasLink(), false);
1028 BOOST_CHECK_EQUAL(i.hasSelectedDelegation(), false);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001029}
1030
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001031BOOST_AUTO_TEST_CASE(DecodeFromStream)
Alexander Afanasyev6835ad82014-02-12 10:07:20 -08001032{
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001033 boost::iostreams::stream<boost::iostreams::array_source> is(
1034 reinterpret_cast<const char *>(Interest1), sizeof(Interest1));
Junxiao Shib332e782014-03-31 14:23:46 -07001035
Alexander Afanasyev9c578182014-05-14 17:28:28 -07001036 Block interestBlock = Block::fromStream(is);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -08001037
1038 ndn::Interest i;
1039 BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
1040
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001041 BOOST_CHECK_EQUAL(i.getName().toUri(), "/local/ndn/prefix");
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001042 BOOST_CHECK_EQUAL(i.getInterestLifetime(), time::milliseconds(1000));
1043 BOOST_CHECK_EQUAL(i.getMinSuffixComponents(), 1);
1044 BOOST_CHECK_EQUAL(i.getMaxSuffixComponents(), 1);
1045 BOOST_CHECK_EQUAL(i.getChildSelector(), 1);
1046 BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
1047 BOOST_CHECK_EQUAL(i.getExclude().toUri(), "alex,xxxx,*,yyyy");
1048 BOOST_CHECK_EQUAL(i.getNonce(), 1U);
Alexander Afanasyevcac08382015-09-02 14:52:40 -07001049 BOOST_CHECK_EQUAL(i.hasLink(), false);
1050 BOOST_CHECK_EQUAL(i.hasSelectedDelegation(), false);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -08001051}
1052
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001053BOOST_AUTO_TEST_CASE(Encode)
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001054{
1055 ndn::Interest i(ndn::Name("/local/ndn/prefix"));
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -07001056 i.setInterestLifetime(time::milliseconds(1000));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001057 i.setMinSuffixComponents(1);
1058 i.setMaxSuffixComponents(1);
Junxiao Shib332e782014-03-31 14:23:46 -07001059 i.setPublisherPublicKeyLocator(KeyLocator("ndn:/test/key/locator"));
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001060 i.setChildSelector(1);
1061 i.setMustBeFresh(false);
Alexander Afanasyevc348f832014-02-17 16:35:17 -08001062 Exclude exclude;
1063 exclude
Alexander Afanasyev52eb20d2014-02-06 18:25:54 -08001064 .excludeOne(name::Component("alex"))
1065 .excludeRange(name::Component("xxxx"), name::Component("yyyy"));
Alexander Afanasyevc348f832014-02-17 16:35:17 -08001066 i.setExclude(exclude);
Alexander Afanasyev840139f2013-12-28 15:02:50 -08001067 i.setNonce(1);
Alexander Afanasyev5fa9e9a2013-12-24 19:45:07 -08001068
Alexander Afanasyeve881e932014-06-08 14:47:03 +03001069 BOOST_CHECK_EQUAL(i.hasWire(), false);
Eric Newberryb555b002017-05-17 00:30:44 -07001070 const Block& wire = i.wireEncode();
Alexander Afanasyeve881e932014-06-08 14:47:03 +03001071 BOOST_CHECK_EQUAL(i.hasWire(), true);
Alexander Afanasyev809805d2014-02-17 17:20:33 -08001072
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07001073 BOOST_CHECK_EQUAL_COLLECTIONS(Interest1, Interest1 + sizeof(Interest1),
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001074 wire.begin(), wire.end());
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001075
Alexander Afanasyeve881e932014-06-08 14:47:03 +03001076 const uint8_t* originalWire = wire.wire();
1077 i.setNonce(2);
1078 BOOST_CHECK_EQUAL(i.hasWire(), true);
1079 BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire());
1080 BOOST_CHECK_EQUAL(i.hasWire(), true);
1081
1082 BOOST_CHECK_EQUAL_COLLECTIONS(Interest2, Interest2 + sizeof(Interest2),
1083 wire.begin(), wire.end());
Alexander Afanasyeva0c5f832014-06-19 13:27:56 -07001084
1085 std::ostringstream strStream;
1086 BOOST_CHECK_NO_THROW(strStream << i);
1087
1088 BOOST_CHECK_EQUAL(strStream.str(),
1089 "/local/ndn/prefix?"
1090 "ndn.MinSuffixComponents=1&ndn.MaxSuffixComponents=1&"
Alexander Afanasyev117f5ef2015-06-03 15:07:24 -07001091 "ndn.ChildSelector=1&"
Alexander Afanasyeva0c5f832014-06-19 13:27:56 -07001092 "ndn.InterestLifetime=1000&"
1093 "ndn.Nonce=2&ndn.Exclude=alex,xxxx,*,yyyy");
Alexander Afanasyevc3932172014-07-10 18:53:56 -07001094
1095 i.refreshNonce();
1096 BOOST_CHECK_EQUAL(i.hasWire(), true);
1097 BOOST_CHECK_EQUAL(originalWire, i.wireEncode().wire());
1098 BOOST_CHECK_NE(i.getNonce(), 2);
Alexander Afanasyeve881e932014-06-08 14:47:03 +03001099}
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -08001100
Alexander Afanasyevcac08382015-09-02 14:52:40 -07001101BOOST_AUTO_TEST_CASE(DecodeEncode) // this test case to ensure that wireDecode resets all the fields
1102{
1103 Interest i1;
1104 i1.setName("/test");
1105 i1.setMinSuffixComponents(100);
1106 i1.setNonce(10);
1107 i1.setInterestLifetime(time::seconds(10));
1108 i1.setLink(Block(LINK, sizeof(LINK)));
1109 i1.setSelectedDelegation(0);
1110
1111 Interest i2(i1.wireEncode());
1112
1113 BOOST_CHECK_EQUAL(i2.getName().toUri(), "/test");
1114 BOOST_CHECK_EQUAL(i2.getInterestLifetime(), time::seconds(10));
1115 BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), 100);
1116 BOOST_CHECK_EQUAL(i2.getNonce(), 10);
1117 BOOST_CHECK_EQUAL(i2.hasLink(), true);
1118 BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), true);
1119
1120 i2.wireDecode(Interest().wireEncode());
1121
1122 BOOST_CHECK_EQUAL(i2.getName().toUri(), "/");
1123 BOOST_CHECK_EQUAL(i2.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
1124 BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), -1);
1125 BOOST_WARN_NE(i2.getNonce(), 10);
1126 BOOST_CHECK_EQUAL(i2.hasLink(), false);
1127 BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), false);
1128}
1129
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001130BOOST_AUTO_TEST_CASE(MatchesData)
1131{
1132 Interest interest;
1133 interest.setName("ndn:/A")
1134 .setMinSuffixComponents(2)
1135 .setMaxSuffixComponents(2)
1136 .setPublisherPublicKeyLocator(KeyLocator("ndn:/B"))
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001137 .setExclude(Exclude().excludeAfter(name::Component("J")));
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001138
1139 Data data("ndn:/A/D");
Yingdi Yu4a557052014-07-09 16:40:37 -07001140 SignatureSha256WithRsa signature(KeyLocator("ndn:/B"));
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001141 data.setSignature(signature);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001142 data.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001143 BOOST_CHECK_EQUAL(interest.matchesData(data), true);
1144
1145 Data data1 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001146 data1.setName("ndn:/A"); // violates MinSuffixComponents
1147 data1.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001148 BOOST_CHECK_EQUAL(interest.matchesData(data1), false);
1149
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001150 Interest interest1 = interest;
1151 interest1.setMinSuffixComponents(1);
1152 BOOST_CHECK_EQUAL(interest1.matchesData(data1), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001153
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001154 Data data2 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001155 data2.setName("ndn:/A/E/F"); // violates MaxSuffixComponents
1156 data2.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001157 BOOST_CHECK_EQUAL(interest.matchesData(data2), false);
1158
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001159 Interest interest2 = interest;
1160 interest2.setMaxSuffixComponents(3);
1161 BOOST_CHECK_EQUAL(interest2.matchesData(data2), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001162
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001163 Data data3 = data;
Yingdi Yu4a557052014-07-09 16:40:37 -07001164 SignatureSha256WithRsa signature3(KeyLocator("ndn:/G")); // violates PublisherPublicKeyLocator
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001165 data3.setSignature(signature3);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001166 data3.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001167 BOOST_CHECK_EQUAL(interest.matchesData(data3), false);
1168
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001169 Interest interest3 = interest;
1170 interest3.setPublisherPublicKeyLocator(KeyLocator("ndn:/G"));
1171 BOOST_CHECK_EQUAL(interest3.matchesData(data3), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001172
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001173 Data data4 = data;
Yingdi Yubf6a2812014-06-17 15:32:11 -07001174 DigestSha256 signature4; // violates PublisherPublicKeyLocator
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001175 data4.setSignature(signature4);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001176 data4.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001177 BOOST_CHECK_EQUAL(interest.matchesData(data4), false);
1178
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001179 Interest interest4 = interest;
1180 interest4.setPublisherPublicKeyLocator(KeyLocator());
1181 BOOST_CHECK_EQUAL(interest4.matchesData(data4), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001182
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001183 Data data5 = data;
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001184 data5.setName("ndn:/A/J"); // violates Exclude
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001185 data5.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001186 BOOST_CHECK_EQUAL(interest.matchesData(data5), false);
1187
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001188 Interest interest5 = interest;
1189 interest5.setExclude(Exclude().excludeAfter(name::Component("K")));
1190 BOOST_CHECK_EQUAL(interest5.matchesData(data5), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001191
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001192 Data data6 = data;
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001193 data6.setName("ndn:/H/I"); // violates Name
1194 data6.wireEncode();
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001195 BOOST_CHECK_EQUAL(interest.matchesData(data6), false);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001196
1197 Data data7 = data;
1198 data7.setName("ndn:/A/B");
1199 data7.wireEncode();
1200
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001201 Interest interest7("/A/B/sha256digest=D548DECEFC4B880720DC9257A8D815E9DF4465E63742EE55C29133055DAA67C2");
1202 BOOST_CHECK_EQUAL(interest7.matchesData(data7), true);
Alexander Afanasyev3b703102014-06-13 17:01:14 -07001203
Junxiao Shidf4b24e2016-07-14 21:41:43 +00001204 Interest interest7b("/A/B/sha256digest=0000000000000000000000000000000000000000000000000000000000000000");
1205 BOOST_CHECK_EQUAL(interest7b.matchesData(data7), false); // violates implicit digest
Junxiao Shiaf8eeea2014-03-31 20:10:56 -07001206}
1207
Alexander Afanasyev1013fd02017-01-03 13:19:03 -08001208BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(MatchesInterest, 1)
1209BOOST_AUTO_TEST_CASE(MatchesInterest)
1210{
1211 Interest interest;
1212 interest
1213 .setName("ndn:/A")
1214 .setMinSuffixComponents(2)
1215 .setMaxSuffixComponents(2)
1216 .setPublisherPublicKeyLocator(KeyLocator("ndn:/B"))
1217 .setExclude(Exclude().excludeAfter(name::Component("J")))
1218 .setNonce(10)
1219 .setInterestLifetime(time::seconds(5));
1220
1221 Link link("/A/LINK", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
1222 m_keyChain.sign(link);
1223 interest.setLink(link.wireEncode());
1224
1225 Interest other;
1226 BOOST_CHECK_EQUAL(interest.matchesInterest(other), false);
1227
1228 other.setName(interest.getName());
1229 BOOST_CHECK_EQUAL(interest.matchesInterest(other), false);
1230
1231 // TODO: will match until #3162 implemented
1232 other.setSelectors(interest.getSelectors());
1233 BOOST_CHECK_EQUAL(interest.matchesInterest(other), false);
1234
1235 other.setLink(interest.getLink().wireEncode());
1236 BOOST_CHECK_EQUAL(interest.matchesInterest(other), true);
1237
1238 other.setNonce(200);
1239 BOOST_CHECK_EQUAL(interest.matchesInterest(other), true);
1240
1241 other.setInterestLifetime(time::hours(5));
1242 BOOST_CHECK_EQUAL(interest.matchesInterest(other), true);
1243
1244 other.setSelectedDelegation(0);
1245 BOOST_CHECK_EQUAL(interest.matchesInterest(other), true);
1246}
1247
Alexander Afanasyev90164962014-03-06 08:29:59 +00001248BOOST_AUTO_TEST_CASE(InterestFilterMatching)
1249{
1250 BOOST_CHECK_EQUAL(InterestFilter("/a").doesMatch("/a/b"), true);
1251 BOOST_CHECK_EQUAL(InterestFilter("/a/b").doesMatch("/a/b"), true);
1252 BOOST_CHECK_EQUAL(InterestFilter("/a/b/c").doesMatch("/a/b"), false);
1253
1254 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b"), true);
1255 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b"), false);
1256
1257 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<b>").doesMatch("/a/b/c/b"), false);
1258 BOOST_CHECK_EQUAL(InterestFilter("/a/b", "<>*<b>").doesMatch("/a/b/c/b"), true);
1259
1260 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b>").doesMatch("/a/b/c/d"), false);
1261 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b/c/d"), true);
1262 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>*").doesMatch("/a/b"), true);
1263 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b"), false);
1264 BOOST_CHECK_EQUAL(InterestFilter("/a", "<b><>+").doesMatch("/a/b/c"), true);
1265}
1266
Davide Pesaventoeee3e822016-11-26 19:19:34 +01001267BOOST_AUTO_TEST_SUITE_END() // TestInterest
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -08001268
Alexander Afanasyev90164962014-03-06 08:29:59 +00001269} // namespace tests
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -08001270} // namespace ndn