|
16 | 16 | import org.apache.commons.io.IOUtils; |
17 | 17 | import org.apache.http.client.CookieStore; |
18 | 18 | import org.junit.Test; |
| 19 | +import org.opensaml.saml.saml2.core.StatusCode; |
19 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
20 | 21 | import org.springframework.http.HttpHeaders; |
21 | 22 | import org.springframework.http.HttpMethod; |
@@ -197,6 +198,45 @@ public void accountLinkingAndMfa() throws IOException { |
197 | 198 | assertTrue(samlResponse.contains(ACR.LINKED_INSTITUTION_MFA)); |
198 | 199 | } |
199 | 200 |
|
| 201 | + @Test |
| 202 | + public void accountLinkingAndMfa_RejectMfa() throws IOException { |
| 203 | + String authnContext = readFile("request_authn_context_linked_institution_mfa.xml"); |
| 204 | + Response response = samlAuthnRequestResponseWithLoa(null, "relay", authnContext); |
| 205 | + String authenticationRequestId = extractAuthenticationRequestIdFromAuthnResponse(response); |
| 206 | + |
| 207 | + String location = response.getHeader("Location"); |
| 208 | + assertTrue(location.contains("/login")); |
| 209 | + assertTrue(location.contains("stepup=true")); |
| 210 | + assertTrue(location.contains("mfa=true")); |
| 211 | + |
| 212 | + // Linking institution |
| 213 | + User user = userRepository.findOneUserByEmail("mdoe@example.com"); |
| 214 | + LinkedAccount linkedAccount = linkedAccount("John", "Doe", new Date()); |
| 215 | + user.getLinkedAccounts().add(linkedAccount); |
| 216 | + userRepository.save(user); |
| 217 | + |
| 218 | + ClientAuthenticationRequest clientAuthenticationRequest = new ClientAuthenticationRequest(authenticationRequestId, user, false, "repsonse"); |
| 219 | + ClientAuthenticationResponse authenticationResponse = oneTimeLoginCodeRequest(clientAuthenticationRequest, HttpMethod.PUT); |
| 220 | + |
| 221 | + SamlAuthenticationRequest samlAuthenticationRequest = authenticationRequestRepository |
| 222 | + .findById(authenticationResponse.authenticationRequestId).get(); |
| 223 | + |
| 224 | + Response magicResponse = given().redirects().follow(false) |
| 225 | + .when() |
| 226 | + .queryParam("h", samlAuthenticationRequest.getHash()) |
| 227 | + .cookie(BROWSER_SESSION_COOKIE_NAME, "true") |
| 228 | + .get("/saml/guest-idp/magic"); |
| 229 | + while (magicResponse.statusCode() == 302) { |
| 230 | + String redirectLocation = magicResponse.getHeader("Location"); |
| 231 | + assertNotNull(redirectLocation); |
| 232 | + magicResponse = this.get302Response(magicResponse, Optional.empty(), "?force=true"); |
| 233 | + } |
| 234 | + String samlResponse = samlAuthnResponse(magicResponse, Optional.empty()); |
| 235 | + |
| 236 | + assertTrue(samlResponse.contains(StatusCode.NO_AUTHN_CONTEXT)); |
| 237 | + assertTrue(samlResponse.contains("The requesting service has indicated that a login with the eduID app is required to login.")); |
| 238 | + } |
| 239 | + |
200 | 240 | @Test |
201 | 241 | public void accountLinkingAndMfa_Flow() throws IOException { |
202 | 242 | // Login |
|
0 commit comments