@@ -46,11 +46,17 @@ public function setup_the_middleware()
46
46
$ this ->cache = new \Illuminate \Cache \Repository (new ArrayStore ());
47
47
$ this ->configurations = Mockery::mock (Configurations::class);
48
48
$ this ->configurations ->shouldReceive ('get ' )
49
- ->with ('signed-requests.cache-prefix ' )
49
+ ->with ('signed-requests.default. cache-prefix ' )
50
50
->andReturn ('prefix ' );
51
51
$ this ->configurations ->shouldReceive ('get ' )
52
- ->with ('signed-requests.request-replay.tolerance ' )
52
+ ->with ('signed-requests.default. request-replay.tolerance ' )
53
53
->andReturn (60 );
54
+ $ this ->configurations ->shouldReceive ('get ' )
55
+ ->with ('signed-requests ' )
56
+ ->andReturn ([
57
+ 'default ' => [],
58
+ 'custom ' => []
59
+ ]);
54
60
$ this ->middleware = new VerifySignature ($ this ->configurations , $ this ->cache );
55
61
}
56
62
@@ -69,19 +75,19 @@ public function it_can_be_constructed()
69
75
public function it_throws_an_invalid_signature_exception_if_the_request_is_not_valid ()
70
76
{
71
77
$ this ->configurations ->shouldReceive ('get ' )
72
- ->with ('signed-requests.headers.signature ' )
78
+ ->with ('signed-requests.default. headers.signature ' )
73
79
->andReturn ('HTTP_SIGNATURE ' );
74
80
75
81
$ this ->configurations ->shouldReceive ('get ' )
76
- ->with ('signed-requests.headers.algorithm ' )
82
+ ->with ('signed-requests.default. headers.algorithm ' )
77
83
->andReturn ('HTTP_ALGORITHM ' );
78
84
79
85
$ this ->configurations ->shouldReceive ('get ' )
80
- ->with ('signed-requests.key ' )
86
+ ->with ('signed-requests.default. key ' )
81
87
->andReturn ('key ' );
82
88
83
89
$ this ->configurations ->shouldReceive ('get ' )
84
- ->with ('signed-requests.request-replay.allow ' )
90
+ ->with ('signed-requests.default. request-replay.allow ' )
85
91
->andReturn (true );
86
92
87
93
$ request = new Request ();
@@ -98,19 +104,19 @@ public function it_should_call_our_callback_if_the_request_is_valid()
98
104
$ id = (string ) Uuid::uuid4 ();
99
105
100
106
$ this ->configurations ->shouldReceive ('get ' )
101
- ->with ('signed-requests.headers.signature ' )
107
+ ->with ('signed-requests.default. headers.signature ' )
102
108
->andReturn ('signature ' );
103
109
104
110
$ this ->configurations ->shouldReceive ('get ' )
105
- ->with ('signed-requests.headers.algorithm ' )
111
+ ->with ('signed-requests.default. headers.algorithm ' )
106
112
->andReturn ('algorithm ' );
107
113
108
114
$ this ->configurations ->shouldReceive ('get ' )
109
- ->with ('signed-requests.key ' )
115
+ ->with ('signed-requests.default. key ' )
110
116
->andReturn ('key ' );
111
117
112
118
$ this ->configurations ->shouldReceive ('get ' )
113
- ->with ('signed-requests.request-replay.allow ' )
119
+ ->with ('signed-requests.default. request-replay.allow ' )
114
120
->andReturn (true );
115
121
116
122
$ query = [];
@@ -135,31 +141,31 @@ public function it_should_call_our_callback_if_the_request_is_valid()
135
141
/**
136
142
* @test
137
143
*/
138
- public function it_should_prefix_the_configuration_keys_if_a_prefix_is_supplied ()
144
+ public function it_should_set_the_key_when_one_is_passed ()
139
145
{
140
146
$ id = (string ) Uuid::uuid4 ();
141
147
142
148
$ this ->configurations ->shouldReceive ('get ' )
143
- ->with ('prefix- signed-requests.headers.signature ' )
149
+ ->with ('signed-requests.custom .headers.signature ' )
144
150
->andReturn ('signature ' );
145
151
146
152
$ this ->configurations ->shouldReceive ('get ' )
147
- ->with ('prefix- signed-requests.headers.algorithm ' )
153
+ ->with ('signed-requests.custom .headers.algorithm ' )
148
154
->andReturn ('algorithm ' );
149
155
150
156
$ this ->configurations ->shouldReceive ('get ' )
151
- ->with ('prefix- signed-requests.key ' )
157
+ ->with ('signed-requests.custom .key ' )
152
158
->andReturn ('key ' );
153
159
154
160
$ this ->configurations ->shouldReceive ('get ' )
155
- ->with ('prefix- signed-requests.request-replay.allow ' )
161
+ ->with ('signed-requests.custom .request-replay.allow ' )
156
162
->andReturn (true );
157
163
158
164
$ this ->configurations ->shouldReceive ('get ' )
159
- ->with ('prefix- signed-requests.cache-prefix ' )
165
+ ->with ('signed-requests.custom .cache-prefix ' )
160
166
->andReturn ('prefix ' );
161
167
$ this ->configurations ->shouldReceive ('get ' )
162
- ->with ('prefix- signed-requests.request-replay.tolerance ' )
168
+ ->with ('signed-requests.custom .request-replay.tolerance ' )
163
169
->andReturn (60 );
164
170
165
171
$ query = [];
@@ -178,7 +184,34 @@ public function it_should_prefix_the_configuration_keys_if_a_prefix_is_supplied(
178
184
$ this ->middleware ->handle ($ request , function () {
179
185
// This should be called.
180
186
$ this ->assertTrue (true );
181
- }, 'prefix ' );
187
+ }, 'custom ' );
188
+ }
189
+
190
+ /**
191
+ * @test
192
+ * @expectedException \SoapBox\SignedRequests\Exceptions\InvalidConfigurationException
193
+ */
194
+ public function it_should_throw_an_exception_when_it_cannot_find_the_key ()
195
+ {
196
+ $ id = (string ) Uuid::uuid4 ();
197
+
198
+ $ query = [];
199
+ $ request = [];
200
+ $ attributes = [];
201
+ $ cookies = [];
202
+ $ files = [];
203
+ $ server = [
204
+ 'HTTP_X-SIGNED-ID ' => $ id ,
205
+ 'HTTP_ALGORITHM ' => 'sha256 '
206
+ ];
207
+
208
+ $ request = new Request ($ query , $ request , $ attributes , $ cookies , $ files , $ server , 'a ' );
209
+ $ request ->headers ->set ('signature ' , (string ) new Signature (new Payload ($ request ), 'sha256 ' , 'key ' ));
210
+
211
+ $ this ->middleware ->handle ($ request , function () {
212
+ // This should be called.
213
+ $ this ->assertTrue (true );
214
+ }, 'nope ' );
182
215
}
183
216
184
217
/**
@@ -190,19 +223,19 @@ public function it_throws_an_expired_request_exception_if_the_timestamp_on_the_r
190
223
$ id = (string ) Uuid::uuid4 ();
191
224
192
225
$ this ->configurations ->shouldReceive ('get ' )
193
- ->with ('signed-requests.headers.signature ' )
226
+ ->with ('signed-requests.default. headers.signature ' )
194
227
->andReturn ('signature ' );
195
228
196
229
$ this ->configurations ->shouldReceive ('get ' )
197
- ->with ('signed-requests.headers.algorithm ' )
230
+ ->with ('signed-requests.default. headers.algorithm ' )
198
231
->andReturn ('algorithm ' );
199
232
200
233
$ this ->configurations ->shouldReceive ('get ' )
201
- ->with ('signed-requests.key ' )
234
+ ->with ('signed-requests.default. key ' )
202
235
->andReturn ('key ' );
203
236
204
237
$ this ->configurations ->shouldReceive ('get ' )
205
- ->with ('signed-requests.request-replay.allow ' )
238
+ ->with ('signed-requests.default. request-replay.allow ' )
206
239
->andReturn (false );
207
240
208
241
$ query = [];
@@ -231,19 +264,19 @@ public function it_should_call_our_callback_if_the_id_has_not_previously_been_se
231
264
$ id = (string ) Uuid::uuid4 ();
232
265
233
266
$ this ->configurations ->shouldReceive ('get ' )
234
- ->with ('signed-requests.headers.signature ' )
267
+ ->with ('signed-requests.default. headers.signature ' )
235
268
->andReturn ('signature ' );
236
269
237
270
$ this ->configurations ->shouldReceive ('get ' )
238
- ->with ('signed-requests.headers.algorithm ' )
271
+ ->with ('signed-requests.default. headers.algorithm ' )
239
272
->andReturn ('algorithm ' );
240
273
241
274
$ this ->configurations ->shouldReceive ('get ' )
242
- ->with ('signed-requests.key ' )
275
+ ->with ('signed-requests.default. key ' )
243
276
->andReturn ('key ' );
244
277
245
278
$ this ->configurations ->shouldReceive ('get ' )
246
- ->with ('signed-requests.request-replay.allow ' )
279
+ ->with ('signed-requests.default. request-replay.allow ' )
247
280
->andReturn (false );
248
281
249
282
$ query = [];
@@ -275,19 +308,19 @@ public function it_should_throw_an_expired_request_exception_if_the_request_id_h
275
308
$ id = (string ) Uuid::uuid4 ();
276
309
277
310
$ this ->configurations ->shouldReceive ('get ' )
278
- ->with ('signed-requests.headers.signature ' )
311
+ ->with ('signed-requests.default. headers.signature ' )
279
312
->andReturn ('signature ' );
280
313
281
314
$ this ->configurations ->shouldReceive ('get ' )
282
- ->with ('signed-requests.headers.algorithm ' )
315
+ ->with ('signed-requests.default. headers.algorithm ' )
283
316
->andReturn ('algorithm ' );
284
317
285
318
$ this ->configurations ->shouldReceive ('get ' )
286
- ->with ('signed-requests.key ' )
319
+ ->with ('signed-requests.default. key ' )
287
320
->andReturn ('key ' );
288
321
289
322
$ this ->configurations ->shouldReceive ('get ' )
290
- ->with ('signed-requests.request-replay.allow ' )
323
+ ->with ('signed-requests.default. request-replay.allow ' )
291
324
->andReturn (false );
292
325
293
326
$ key = sprintf ('prefix.%s ' , $ id );
@@ -321,19 +354,19 @@ public function it_should_throw_an_expired_request_exception_if_the_same_request
321
354
$ id = (string ) Uuid::uuid4 ();
322
355
323
356
$ this ->configurations ->shouldReceive ('get ' )
324
- ->with ('signed-requests.headers.signature ' )
357
+ ->with ('signed-requests.default. headers.signature ' )
325
358
->andReturn ('signature ' );
326
359
327
360
$ this ->configurations ->shouldReceive ('get ' )
328
- ->with ('signed-requests.headers.algorithm ' )
361
+ ->with ('signed-requests.default. headers.algorithm ' )
329
362
->andReturn ('algorithm ' );
330
363
331
364
$ this ->configurations ->shouldReceive ('get ' )
332
- ->with ('signed-requests.key ' )
365
+ ->with ('signed-requests.default. key ' )
333
366
->andReturn ('key ' );
334
367
335
368
$ this ->configurations ->shouldReceive ('get ' )
336
- ->with ('signed-requests.request-replay.allow ' )
369
+ ->with ('signed-requests.default. request-replay.allow ' )
337
370
->andReturn (false );
338
371
339
372
$ query = [];
@@ -368,19 +401,19 @@ public function it_throws_an_expired_request_exception_if_the_timestamp_on_the_r
368
401
$ id = (string ) Uuid::uuid4 ();
369
402
370
403
$ this ->configurations ->shouldReceive ('get ' )
371
- ->with ('signed-requests.headers.signature ' )
404
+ ->with ('signed-requests.default. headers.signature ' )
372
405
->andReturn ('signature ' );
373
406
374
407
$ this ->configurations ->shouldReceive ('get ' )
375
- ->with ('signed-requests.headers.algorithm ' )
408
+ ->with ('signed-requests.default. headers.algorithm ' )
376
409
->andReturn ('algorithm ' );
377
410
378
411
$ this ->configurations ->shouldReceive ('get ' )
379
- ->with ('signed-requests.key ' )
412
+ ->with ('signed-requests.default. key ' )
380
413
->andReturn ('key ' );
381
414
382
415
$ this ->configurations ->shouldReceive ('get ' )
383
- ->with ('signed-requests.request-replay.allow ' )
416
+ ->with ('signed-requests.default. request-replay.allow ' )
384
417
->andReturn (false );
385
418
386
419
$ query = [];
0 commit comments