|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Behat\Behat\Context\Context; |
|
4
|
|
|
use Behat\Behat\Context\SnippetAcceptingContext; |
|
5
|
|
|
use Behat\Gherkin\Node\PyStringNode; |
|
6
|
|
|
use Behat\Gherkin\Node\TableNode; |
|
7
|
|
|
use Behat\MinkExtension\Context\RawMinkContext; |
|
8
|
|
|
|
|
9
|
|
|
use Rezzza\SecurityBundle\Security\Firewall\SignatureConfig; |
|
10
|
|
|
use Rezzza\SecurityBundle\Security\Firewall\SignedRequest; |
|
11
|
|
|
|
|
12
|
|
|
class FeatureContext extends RawMinkContext implements Context, SnippetAcceptingContext |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
private $signatureConfig; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct(SignatureConfig $signatureConfig) |
|
17
|
|
|
{ |
|
18
|
|
|
$this->signatureConfig = $signatureConfig; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @When I am on :url with good signature |
|
23
|
|
|
*/ |
|
24
|
|
|
public function iAmOnWithGoodSignature($url) |
|
25
|
|
|
{ |
|
26
|
|
|
$timestamp = time(); |
|
27
|
|
|
$signature = $this->buildSignature($url, $timestamp); |
|
28
|
|
|
$urlSigned = $this->buildUrlSigned($url, $signature, $timestamp); |
|
29
|
|
|
|
|
30
|
|
|
$this->visitPath($urlSigned); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @When I am on :url with good signature but I wait :seconds seconds before perform request |
|
35
|
|
|
*/ |
|
36
|
|
|
public function iAmOnWithGoodSignatureButIWaitSecondsBeforePerformRequest($url, $seconds) |
|
37
|
|
|
{ |
|
38
|
|
|
$timestamp = time(); |
|
39
|
|
|
$signature = $this->buildSignature($url, $timestamp); |
|
40
|
|
|
$url = $this->buildUrlSigned($url, $signature, $timestamp); |
|
41
|
|
|
|
|
42
|
|
|
sleep($seconds); |
|
43
|
|
|
|
|
44
|
|
|
$this->visitPath($url); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @When I am on :url with wrong signature |
|
49
|
|
|
*/ |
|
50
|
|
|
public function iAmOnWithWrongSignature($url) |
|
51
|
|
|
{ |
|
52
|
|
|
$urlSigned = $this->buildUrlSigned($url, 'peutimporte', time()); |
|
53
|
|
|
|
|
54
|
|
|
$this->visitPath($urlSigned); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function buildUrlSigned($url, $signature, $timestamp) |
|
58
|
|
|
{ |
|
59
|
|
|
return sprintf('%s?_signature=%s&_signature_ttl=%s', $url, $signature, $timestamp); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
private function buildSignature($url, $timestamp) |
|
63
|
|
|
{ |
|
64
|
|
|
$signedRequest = new SignedRequest('GET', 'security-bundle.vlr.localtest', $url, '', $timestamp); |
|
65
|
|
|
|
|
66
|
|
|
return $signedRequest->buildSignature($this->signatureConfig); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.