|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Indigo\Oro\Behat\Context; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Symfony2Extension\Context\KernelAwareContext; |
|
6
|
|
|
use Behat\Symfony2Extension\Context\KernelDictionary; |
|
7
|
|
|
use Oro\Bundle\SearchBundle\Engine\EngineInterface; |
|
8
|
|
|
use Oro\Bundle\TestFrameworkBundle\Test\Client; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Context containing Oro hooks. |
|
12
|
|
|
* |
|
13
|
|
|
* @author Márk Sági-Kazár <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class OroContext implements KernelAwareContext |
|
16
|
|
|
{ |
|
17
|
|
|
use KernelDictionary; |
|
18
|
|
|
|
|
19
|
|
|
/** Default WSSE credentials */ |
|
20
|
|
|
const USER_NAME = 'admin'; |
|
21
|
|
|
const USER_PASSWORD = 'admin_api_key'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var Client |
|
25
|
|
|
*/ |
|
26
|
|
|
private $client; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @BeforeScenario @dbIsolation |
|
30
|
|
|
*/ |
|
31
|
|
|
public function startTransaction() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->getClient()->startTransaction(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @AfterScenario @dbIsolation |
|
38
|
|
|
*/ |
|
39
|
|
|
public function rollbackTransaction() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->getClient()->rollbackTransaction(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @BeforeScenario @dbIsolation&&@dbReindex |
|
46
|
|
|
*/ |
|
47
|
|
|
public function reindex() |
|
48
|
|
|
{ |
|
49
|
|
|
/** @var EngineInterface $searchEngine */ |
|
50
|
|
|
$searchEngine = $this->getContainer()->get('oro_search.search.engine'); |
|
51
|
|
|
|
|
52
|
|
|
$searchEngine->reindex(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @BeforeScenario @wsse |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setWsseHeader() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->getClient()->setServerParameters($this->generateWsseAuthHeader()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Returns the test client. |
|
65
|
|
|
* |
|
66
|
|
|
* @return Client |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getClient() |
|
69
|
|
|
{ |
|
70
|
|
|
if (null === $this->client) { |
|
71
|
|
|
$this->client = $this->getContainer()->get('test.client'); |
|
72
|
|
|
|
|
73
|
|
|
if (false === $this->client instanceof Client) { |
|
74
|
|
|
throw new \RuntimeException('The test client must be an instance of Oro\Bundle\TestFrameworkBundle\Test\Client'); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->client; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Generates WSSE Auth header. |
|
83
|
|
|
* |
|
84
|
|
|
* {@link \Oro\Bundle\TestFrameworkBundle\Test\WebTestCase} |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $userName |
|
87
|
|
|
* @param string $userPassword |
|
88
|
|
|
* @param string|null $nonce |
|
89
|
|
|
* |
|
90
|
|
|
* @return array |
|
91
|
|
|
*/ |
|
92
|
|
|
public function generateWsseAuthHeader( |
|
93
|
|
|
$userName = self::USER_NAME, |
|
94
|
|
|
$userPassword = self::USER_PASSWORD, |
|
95
|
|
|
$nonce = null |
|
96
|
|
|
) { |
|
97
|
|
|
if (null === $nonce) { |
|
98
|
|
|
$nonce = uniqid(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$created = date('c'); |
|
102
|
|
|
$digest = base64_encode(sha1(base64_decode($nonce).$created.$userPassword, true)); |
|
103
|
|
|
$wsseHeader = [ |
|
104
|
|
|
'CONTENT_TYPE' => 'application/json', |
|
105
|
|
|
'HTTP_Authorization' => 'WSSE profile="UsernameToken"', |
|
106
|
|
|
'HTTP_X-WSSE' => sprintf( |
|
107
|
|
|
'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', |
|
108
|
|
|
$userName, |
|
109
|
|
|
$digest, |
|
110
|
|
|
$nonce, |
|
111
|
|
|
$created |
|
112
|
|
|
), |
|
113
|
|
|
]; |
|
114
|
|
|
|
|
115
|
|
|
return $wsseHeader; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|