Code Duplication    Length = 21-22 lines in 4 locations

tests/features/bootstrap/ServiceProviderContext.php 4 locations

@@ 154-175 (lines=22) @@
151
    /**
152
     * @When /^([^\']*) starts an SFO authentication$/
153
     */
154
    public function iStartAnSFOAuthentication($nameId)
155
    {
156
        $authnRequest = new AuthnRequest();
157
        // In order to later assert if the response succeeded or failed, set our own dummy ACS location
158
        $authnRequest->setAssertionConsumerServiceURL(SamlEntityRepository::SP_ACS_LOCATION);
159
        $authnRequest->setIssuer($this->currentSfoSp['entityId']);
160
        $authnRequest->setDestination(self::SFO_ENDPOINT_URL);
161
        $authnRequest->setProtocolBinding(Constants::BINDING_HTTP_REDIRECT);
162
        $authnRequest->setNameId($this->buildNameId($nameId));
163
        // Sign with random key, does not mather for now.
164
        // todo: use from services_test.yml
165
        $authnRequest->setSignatureKey(
166
            $this->loadPrivateKey(new PrivateKey('/var/www/ci/certificates/sp.pem', 'default'))
167
        );
168
        $authnRequest->setRequestedAuthnContext(
169
            ['AuthnContextClassRef' => ['http://stepup.example.com/assurance/sfo-level2']]
170
        );
171
        $request = Saml2AuthnRequest::createNew($authnRequest);
172
        $query = $request->buildRequestQuery();
173
174
        $this->getSession()->visit($request->getDestination().'?'.$query);
175
    }
176
177
    /**
178
     * @When /^([^\']*) starts an SFO authentication requiring ([^\']*)$/
@@ 180-201 (lines=22) @@
177
    /**
178
     * @When /^([^\']*) starts an SFO authentication requiring ([^\']*)$/
179
     */
180
    public function iStartAnSFOAuthenticationWithLoaRequirement($nameId, $loa)
181
    {
182
        $authnRequest = new AuthnRequest();
183
        // In order to later assert if the response succeeded or failed, set our own dummy ACS location
184
        $authnRequest->setAssertionConsumerServiceURL(SamlEntityRepository::SP_ACS_LOCATION);
185
        $authnRequest->setIssuer($this->currentSfoSp['entityId']);
186
        $authnRequest->setDestination(self::SFO_ENDPOINT_URL);
187
        $authnRequest->setProtocolBinding(Constants::BINDING_HTTP_REDIRECT);
188
        $authnRequest->setNameId($this->buildNameId($nameId));
189
        // Sign with random key, does not mather for now.
190
        // todo: use from services_test.yml
191
        $authnRequest->setSignatureKey(
192
            $this->loadPrivateKey(new PrivateKey('/var/www/ci/certificates/sp.pem', 'default'))
193
        );
194
        $authnRequest->setRequestedAuthnContext(
195
            ['AuthnContextClassRef' => [$loa]]
196
        );
197
        $request = Saml2AuthnRequest::createNew($authnRequest);
198
        $query = $request->buildRequestQuery();
199
200
        $this->getSession()->visit($request->getDestination().'?'.$query);
201
    }
202
203
    /**
204
     * @When /^([^\']*) starts an authentication$/
@@ 206-226 (lines=21) @@
203
    /**
204
     * @When /^([^\']*) starts an authentication$/
205
     */
206
    public function iStartAnAuthentication($nameId)
207
    {
208
        $authnRequest = new AuthnRequest();
209
        // In order to later assert if the response succeeded or failed, set our own dummy ACS location
210
        $authnRequest->setAssertionConsumerServiceURL(SamlEntityRepository::SP_ACS_LOCATION);
211
        $authnRequest->setIssuer($this->currentSp['entityId']);
212
        $authnRequest->setDestination(self::SSO_ENDPOINT_URL);
213
        $authnRequest->setProtocolBinding(Constants::BINDING_HTTP_REDIRECT);
214
        $authnRequest->setNameId($this->buildNameId($nameId));
215
        // Sign with random key, does not mather for now.
216
        // todo: use from services_test.yml
217
        $authnRequest->setSignatureKey(
218
            $this->loadPrivateKey(new PrivateKey('/var/www/ci/certificates/sp.pem', 'default'))
219
        );
220
        $authnRequest->setRequestedAuthnContext(
221
            ['AuthnContextClassRef' => ['http://stepup.example.com/assurance/level2']]
222
        );
223
        $request = Saml2AuthnRequest::createNew($authnRequest);
224
        $query = $request->buildRequestQuery();
225
        $this->getSession()->visit($request->getDestination().'?'.$query);
226
    }
227
228
    /**
229
     * @When /^([^\']*) starts an authentication requiring ([^\']*)$/
@@ 231-251 (lines=21) @@
228
    /**
229
     * @When /^([^\']*) starts an authentication requiring ([^\']*)$/
230
     */
231
    public function iStartAnSsoAuthenticationWithLoaRequirement($nameId, $loa)
232
    {
233
        $authnRequest = new AuthnRequest();
234
        // In order to later assert if the response succeeded or failed, set our own dummy ACS location
235
        $authnRequest->setAssertionConsumerServiceURL(SamlEntityRepository::SP_ACS_LOCATION);
236
        $authnRequest->setIssuer($this->currentSp['entityId']);
237
        $authnRequest->setDestination(self::SSO_ENDPOINT_URL);
238
        $authnRequest->setProtocolBinding(Constants::BINDING_HTTP_REDIRECT);
239
        $authnRequest->setNameId($this->buildNameId($nameId));
240
        // Sign with random key, does not mather for now.
241
        // todo: use from services_test.yml
242
        $authnRequest->setSignatureKey(
243
            $this->loadPrivateKey(new PrivateKey('/var/www/ci/certificates/sp.pem', 'default'))
244
        );
245
        $authnRequest->setRequestedAuthnContext(
246
            ['AuthnContextClassRef' => [$loa]]
247
        );
248
        $request = Saml2AuthnRequest::createNew($authnRequest);
249
        $query = $request->buildRequestQuery();
250
        $this->getSession()->visit($request->getDestination().'?'.$query);
251
    }
252
253
    /**
254
     * @When /^I authenticate at the IdP as ([^\']*)$/