1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2020 SURFnet B.V. |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupGateway\Behat; |
20
|
|
|
|
21
|
|
|
use Behat\Behat\Context\Context; |
22
|
|
|
use Behat\Behat\Hook\Scope\BeforeFeatureScope; |
23
|
|
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope; |
24
|
|
|
use Behat\Behat\Tester\Exception\PendingException; |
25
|
|
|
use Surfnet\StepupGateway\Behat\Service\FixtureService; |
26
|
|
|
|
27
|
|
|
class FeatureContext implements Context |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var FixtureService |
31
|
|
|
*/ |
32
|
|
|
private $fixtureService; |
33
|
|
|
|
34
|
|
|
private $whitelistedInstitutions = []; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var MinkContext |
38
|
|
|
*/ |
39
|
|
|
private $minkContext; |
40
|
|
|
|
41
|
|
|
public function __construct(FixtureService $fixtureService) |
42
|
|
|
{ |
43
|
|
|
$this->fixtureService = $fixtureService; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @BeforeFeature |
48
|
|
|
*/ |
49
|
|
|
public static function setupDatabase(BeforeFeatureScope $scope) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
// Generate test databases |
52
|
|
|
echo "Preparing test schemas\n"; |
53
|
|
|
shell_exec("/var/www/app/console doctrine:schema:drop --env=test --force"); |
54
|
|
|
shell_exec("/var/www/app/console doctrine:schema:create --env=test"); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @BeforeScenario |
59
|
|
|
*/ |
60
|
|
|
public function gatherContexts(BeforeScenarioScope $scope) |
61
|
|
|
{ |
62
|
|
|
$environment = $scope->getEnvironment(); |
63
|
|
|
$this->minkContext = $environment->getContext(MinkContext::class); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Given /^a user from ([^"]*) identified by ([^"]*) with a vetted ([^"]*) token$/ |
68
|
|
|
*/ |
69
|
|
|
public function aUserIdentifiedByWithAVettedToken($institution, $nameId, $tokenType) |
70
|
|
|
{ |
71
|
|
|
switch (strtolower($tokenType)) { |
72
|
|
|
case "yubikey": |
73
|
|
|
$tokenInformation = $this->fixtureService->registerYubikeyToken($nameId, $institution); |
|
|
|
|
74
|
|
|
break; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @Then I should see the Yubikey OTP screen |
80
|
|
|
*/ |
81
|
|
|
public function iShouldSeeTheYubikeyOtpScreen() |
82
|
|
|
{ |
83
|
|
|
$this->minkContext->assertPageContainsText('Log in with YubiKey'); |
84
|
|
|
$this->minkContext->assertPageContainsText('Your YubiKey-code'); |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @When I enter the OTP |
90
|
|
|
*/ |
91
|
|
|
public function iEnterTheOtp() |
92
|
|
|
{ |
93
|
|
|
$this->minkContext->fillField('gateway_verify_yubikey_otp_otp', 'bogus-otp-we-use-a-mock-yubikey-service'); |
94
|
|
|
$this->minkContext->pressButton('gateway_verify_yubikey_otp_submit'); |
95
|
|
|
$this->minkContext->pressButton('Submit'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @Given /^a whitelisted institution ([^"]*)$/ |
100
|
|
|
*/ |
101
|
|
|
public function aWhitelistedInstitution($institution) |
102
|
|
|
{ |
103
|
|
|
$this->whitelistedInstitutions[] = $this->fixtureService->whitelist($institution)['institution']; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.