iAmOnWithGoodSignatureButIWaitSecondsBeforePerformRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Deprecated Code introduced by
The interface Behat\Behat\Context\SnippetAcceptingContext has been deprecated with message: will be removed in 4.0. Use --snippets-for CLI option instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
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