Completed
Push — bugfix/saml-error-response-0-t... ( b34353...3f23cd )
by Michiel
01:50
created

FeatureContext   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 184
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 22
lcom 2
cbo 3
dl 0
loc 184
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setupDatabase() 0 7 1
A gatherContexts() 0 5 1
A aUserIdentifiedByWithAVettedToken() 0 14 4
A aUserIdentifiedBy() 0 4 1
A iShouldSeeTheYubikeyOtpScreen() 0 5 1
A iShouldSeeTheSMSScreen() 0 8 1
A iShouldSeeTheTiqrAuthenticationScreen() 0 6 1
A iEnterTheOtp() 0 6 1
A iEnterTheSmsVerificationCode() 0 6 1
A iFinishGsspAuthentication() 0 6 1
A aWhitelistedInstitution() 0 4 1
A iShouldSelectMyTokenOnTheWAYG() 0 14 4
A iShouldBeOnTheWAYG() 0 4 1
A anErrorResponseIsPostedBackToTheSP() 0 4 1
A iCancelTheAuthentication() 0 4 1
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
     * @Given /^a user from "([^"]*)" identified by "([^"]*)"$/
91
     */
92
    public function aUserIdentifiedBy($institution, $nameId)
0 ignored issues
show
Unused Code introduced by
The parameter $institution 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...
Unused Code introduced by
The parameter $nameId 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...
93
    {
94
        // For now, do nothing, this user is not known to Gateway, but might exist.
95
    }
96
97
    /**
98
     * @Then I should see the Yubikey OTP screen
99
     */
100
    public function iShouldSeeTheYubikeyOtpScreen()
101
    {
102
        $this->minkContext->assertPageContainsText('Log in with YubiKey');
103
        $this->minkContext->assertPageContainsText('Your YubiKey-code');
104
    }
105
106
    /**
107
     * @Then I should see the SMS verification screen
108
     */
109
    public function iShouldSeeTheSMSScreen()
110
    {
111
        $this->minkContext->assertPageContainsText('Log in with SMS');
112
        $this->minkContext->assertPageContainsText('Enter the received code on the next page');
113
        $this->minkContext->pressButton('gateway_send_sms_challenge_send_challenge');
114
        $this->minkContext->assertPageContainsText('Enter the received SMS-code');
115
        $this->minkContext->assertPageContainsText('Send again');
116
    }
117
118
    /**
119
     * @Given /^I should see the Tiqr authentication screen$/
120
     */
121
    public function iShouldSeeTheTiqrAuthenticationScreen()
122
    {
123
        $this->minkContext->pressButton('Submit');
124
        $this->minkContext->printLastResponse(); die;
125
        $this->minkContext->assertPageContainsText('Log in with Tiqr');
0 ignored issues
show
Unused Code introduced by
$this->minkContext->asse...xt('Log in with Tiqr'); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
126
    }
127
128
    /**
129
     * @When I enter the OTP
130
     */
131
    public function iEnterTheOtp()
132
    {
133
        $this->minkContext->fillField('gateway_verify_yubikey_otp_otp', 'bogus-otp-we-use-a-mock-yubikey-service');
134
        $this->minkContext->pressButton('gateway_verify_yubikey_otp_submit');
135
        $this->minkContext->pressButton('Submit');
136
    }
137
138
    /**
139
     * @When I enter the SMS verification code
140
     */
141
    public function iEnterTheSmsVerificationCode()
142
    {
143
        $this->minkContext->fillField('gateway_verify_sms_challenge_challenge', '432543');
144
        $this->minkContext->pressButton('gateway_verify_sms_challenge_verify_challenge');
145
        $this->minkContext->pressButton('Submit');
146
    }
147
148
149
    /**
150
     * @When I finish the Tiqr authentication
151
     */
152
    public function iFinishGsspAuthentication()
153
    {
154
        $this->minkContext->pressButton('Submit');
155
        $this->minkContext->pressButton('Submit');
156
        $this->minkContext->printLastResponse(); die;
157
    }
158
159
160
161
    /**
162
     * @Given /^a whitelisted institution ([^"]*)$/
163
     */
164
    public function aWhitelistedInstitution($institution)
165
    {
166
        $this->whitelistedInstitutions[] = $this->fixtureService->whitelist($institution)['institution'];
167
    }
168
169
    /**
170
     * @Then /^I select my ([^"]*) token on the WAYG$/
171
     */
172
    public function iShouldSelectMyTokenOnTheWAYG($tokenType)
173
    {
174
        switch (strtolower($tokenType)) {
175
            case "yubikey":
176
                $this->minkContext->pressButton('gateway_choose_second_factor_choose_yubikey');
177
                break;
178
            case "sms":
179
                $this->minkContext->pressButton('gateway_choose_second_factor_choose_sms');
180
                break;
181
            case "tiqr":
182
                $this->minkContext->pressButton('gateway_choose_second_factor_choose_tiqr');
183
                break;
184
        }
185
    }
186
187
    /**
188
     * @Then /^I should be on the WAYG$/
189
     */
190
    public function iShouldBeOnTheWAYG()
191
    {
192
        $this->minkContext->assertPageContainsText('Choose a token for login');
193
    }
194
195
    /**
196
     * @Then /^an error response is posted back to the SP$/
197
     */
198
    public function anErrorResponseIsPostedBackToTheSP()
199
    {
200
        $this->minkContext->pressButton('Submit');
201
    }
202
203
    /**
204
     * @Given /^I cancel the authentication$/
205
     */
206
    public function iCancelTheAuthentication()
207
    {
208
        $this->minkContext->pressButton('Cancel');
209
    }
210
}
211