Completed
Push — feature/enable-behat-tests ( 5b7c06...1d2dab )
by Michiel
01:47
created

FeatureContext::iCancelTheAuthentication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
    /**
42
     * @var array
43
     */
44
    private $currentToken;
45
46
    public function __construct(FixtureService $fixtureService)
47
    {
48
        $this->fixtureService = $fixtureService;
49
    }
50
51
    /**
52
     * @BeforeFeature
53
     */
54
    public static function setupDatabase(BeforeFeatureScope $scope)
0 ignored issues
show
Unused Code introduced by
The parameter $scope is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
        // Generate test databases
57
        echo "Preparing test schemas\n";
58
        shell_exec("/var/www/app/console doctrine:schema:drop --env=webtest --force");
59
        shell_exec("/var/www/app/console doctrine:schema:create --env=webtest");
60
    }
61
62
    /**
63
     * @BeforeScenario
64
     */
65
    public function gatherContexts(BeforeScenarioScope $scope)
66
    {
67
        $environment = $scope->getEnvironment();
68
        $this->minkContext = $environment->getContext(MinkContext::class);
69
    }
70
71
    /**
72
     * @Given /^a user from "([^"]*)" identified by "([^"]*)" with a vetted "([^"]*)" token$/
73
     */
74
    public function aUserIdentifiedByWithAVettedToken($institution, $nameId, $tokenType)
75
    {
76
        switch (strtolower($tokenType)) {
77
            case "yubikey":
78
                $this->currentToken = $this->fixtureService->registerYubikeyToken($nameId, $institution);
79
                break;
80
            case "sms":
81
                $this->currentToken = $this->fixtureService->registerSmsToken($nameId, $institution);
82
                break;
83
            case "tiqr":
84
                $this->currentToken = $this->fixtureService->registerTiqrToken($nameId, $institution);
85
                break;
86
        }
87
    }
88
89
    /**
90
     * @Then I should see the Yubikey OTP screen
91
     */
92
    public function iShouldSeeTheYubikeyOtpScreen()
93
    {
94
        $this->minkContext->assertPageContainsText('Log in with YubiKey');
95
        $this->minkContext->assertPageContainsText('Your YubiKey-code');
96
    }
97
98
    /**
99
     * @Then I should see the SMS verification screen
100
     */
101
    public function iShouldSeeTheSMSScreen()
102
    {
103
        $this->minkContext->assertPageContainsText('Log in with SMS');
104
        $this->minkContext->assertPageContainsText('Enter the received code on the next page');
105
        $this->minkContext->pressButton('gateway_send_sms_challenge_send_challenge');
106
        $this->minkContext->assertPageContainsText('Enter the received SMS-code');
107
        $this->minkContext->assertPageContainsText('Send again');
108
    }
109
110
    /**
111
     * @Given /^I should see the Tiqr authentication screen$/
112
     */
113
    public function iShouldSeeTheTiqrAuthenticationScreen()
114
    {
115
        $this->minkContext->pressButton('Submit');
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
    }
148
149
150
151
    /**
152
     * @Given /^a whitelisted institution ([^"]*)$/
153
     */
154
    public function aWhitelistedInstitution($institution)
155
    {
156
        $this->whitelistedInstitutions[] = $this->fixtureService->whitelist($institution)['institution'];
157
    }
158
159
    /**
160
     * @Then /^I select my ([^"]*) token on the WAYG$/
161
     */
162
    public function iShouldSelectMyTokenOnTheWAYG($tokenType)
163
    {
164
        switch (strtolower($tokenType)) {
165
            case "yubikey":
166
                $this->minkContext->pressButton('gateway_choose_second_factor_choose_yubikey');
167
                break;
168
            case "sms":
169
                $this->minkContext->pressButton('gateway_choose_second_factor_choose_sms');
170
                break;
171
            case "tiqr":
172
                $this->minkContext->pressButton('gateway_choose_second_factor_choose_tiqr');
173
                break;
174
        }
175
    }
176
177
    /**
178
     * @Then /^I should be on the WAYG$/
179
     */
180
    public function iShouldBeOnTheWAYG()
181
    {
182
        $this->minkContext->assertPageContainsText('Choose a token for login');
183
    }
184
185
    /**
186
     * @Then /^an error response is posted back to the SP$/
187
     */
188
    public function anErrorResponseIsPostedBackToTheSP()
189
    {
190
        $this->minkContext->pressButton('Submit');
191
    }
192
193
    /**
194
     * @Given /^I cancel the authentication$/
195
     */
196
    public function iCancelTheAuthentication()
197
    {
198
        $this->minkContext->pressButton('Cancel');
199
    }
200
}
201