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 Surfnet\StepupGateway\Behat\Service\FixtureService; |
25
|
|
|
|
26
|
|
|
class FeatureContext implements Context |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var FixtureService |
30
|
|
|
*/ |
31
|
|
|
private $fixtureService; |
32
|
|
|
|
33
|
|
|
private $whitelistedInstitutions = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var MinkContext |
37
|
|
|
*/ |
38
|
|
|
private $minkContext; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
private $currentToken; |
44
|
|
|
|
45
|
|
|
public function __construct(FixtureService $fixtureService) |
46
|
|
|
{ |
47
|
|
|
$this->fixtureService = $fixtureService; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @BeforeFeature |
52
|
|
|
*/ |
53
|
|
|
public static function setupDatabase(BeforeFeatureScope $scope) |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
// Generate test databases |
56
|
|
|
echo "Preparing test schemas\n"; |
57
|
|
|
shell_exec("/var/www/app/console doctrine:schema:drop --env=webtest --force"); |
58
|
|
|
shell_exec("/var/www/app/console doctrine:schema:create --env=webtest"); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @BeforeScenario |
63
|
|
|
*/ |
64
|
|
|
public function gatherContexts(BeforeScenarioScope $scope) |
65
|
|
|
{ |
66
|
|
|
$environment = $scope->getEnvironment(); |
67
|
|
|
$this->minkContext = $environment->getContext(MinkContext::class); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @Given /^a user from ([^"]*) identified by ([^"]*) with a vetted ([^"]*) token$/ |
72
|
|
|
*/ |
73
|
|
|
public function aUserIdentifiedByWithAVettedToken($institution, $nameId, $tokenType) |
74
|
|
|
{ |
75
|
|
|
switch (strtolower($tokenType)) { |
76
|
|
|
case "yubikey": |
77
|
|
|
$this->currentToken = $this->fixtureService->registerYubikeyToken($nameId, $institution); |
78
|
|
|
break; |
79
|
|
|
case "sms": |
80
|
|
|
$this->currentToken = $this->fixtureService->registerSmsToken($nameId, $institution); |
81
|
|
|
break; |
82
|
|
|
case "tiqr": |
83
|
|
|
$this->currentToken = $this->fixtureService->registerTiqrToken($nameId, $institution); |
84
|
|
|
break; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @Then I should see the Yubikey OTP screen |
90
|
|
|
*/ |
91
|
|
|
public function iShouldSeeTheYubikeyOtpScreen() |
92
|
|
|
{ |
93
|
|
|
$this->minkContext->assertPageContainsText('Log in with YubiKey'); |
94
|
|
|
$this->minkContext->assertPageContainsText('Your YubiKey-code'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @Then I should see the SMS verification screen |
99
|
|
|
*/ |
100
|
|
|
public function iShouldSeeTheSMSScreen() |
101
|
|
|
{ |
102
|
|
|
$this->minkContext->assertPageContainsText('Log in with SMS'); |
103
|
|
|
$this->minkContext->assertPageContainsText('Enter the received code on the next page'); |
104
|
|
|
$this->minkContext->pressButton('gateway_send_sms_challenge_send_challenge'); |
105
|
|
|
$this->minkContext->assertPageContainsText('Enter the received SMS-code'); |
106
|
|
|
$this->minkContext->assertPageContainsText('Send again'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @Given /^I should see the Tiqr authentication screen$/ |
111
|
|
|
*/ |
112
|
|
|
public function iShouldSeeTheTiqrAuthenticationScreen() |
113
|
|
|
{ |
114
|
|
|
$this->minkContext->pressButton('Submit'); |
115
|
|
|
$this->minkContext->printLastResponse(); die; |
116
|
|
|
$this->minkContext->assertPageContainsText('Log in with Tiqr'); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @When I enter the OTP |
121
|
|
|
*/ |
122
|
|
|
public function iEnterTheOtp() |
123
|
|
|
{ |
124
|
|
|
$this->minkContext->fillField('gateway_verify_yubikey_otp_otp', 'bogus-otp-we-use-a-mock-yubikey-service'); |
125
|
|
|
$this->minkContext->pressButton('gateway_verify_yubikey_otp_submit'); |
126
|
|
|
$this->minkContext->pressButton('Submit'); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @When I enter the SMS verification code |
131
|
|
|
*/ |
132
|
|
|
public function iEnterTheSmsVerificationCode() |
133
|
|
|
{ |
134
|
|
|
$this->minkContext->fillField('gateway_verify_sms_challenge_challenge', '432543'); |
135
|
|
|
$this->minkContext->pressButton('gateway_verify_sms_challenge_verify_challenge'); |
136
|
|
|
$this->minkContext->pressButton('Submit'); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @When I finish the Tiqr authentication |
142
|
|
|
*/ |
143
|
|
|
public function iFinishGsspAuthentication() |
144
|
|
|
{ |
145
|
|
|
$this->minkContext->pressButton('Submit'); |
146
|
|
|
$this->minkContext->pressButton('Submit'); |
147
|
|
|
$this->minkContext->printLastResponse(); die; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @Given /^a whitelisted institution ([^"]*)$/ |
154
|
|
|
*/ |
155
|
|
|
public function aWhitelistedInstitution($institution) |
156
|
|
|
{ |
157
|
|
|
$this->whitelistedInstitutions[] = $this->fixtureService->whitelist($institution)['institution']; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @Then /^I select my ([^"]*) token on the WAYG$/ |
162
|
|
|
*/ |
163
|
|
|
public function iShouldSelectMyTokenOnTheWAYG($tokenType) |
164
|
|
|
{ |
165
|
|
|
switch (strtolower($tokenType)) { |
166
|
|
|
case "yubikey": |
167
|
|
|
$this->minkContext->pressButton('gateway_choose_second_factor_choose_yubikey'); |
168
|
|
|
break; |
169
|
|
|
case "sms": |
170
|
|
|
$this->minkContext->pressButton('gateway_choose_second_factor_choose_sms'); |
171
|
|
|
break; |
172
|
|
|
case "tiqr": |
173
|
|
|
$this->minkContext->pressButton('gateway_choose_second_factor_choose_tiqr'); |
174
|
|
|
break; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @Then /^I should be on the WAYG$/ |
180
|
|
|
*/ |
181
|
|
|
public function iShouldBeOnTheWAYG() |
182
|
|
|
{ |
183
|
|
|
$this->minkContext->assertPageContainsText('Choose a token for login'); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.