|
| 1 | +package oidc.endpoints; |
| 2 | + |
| 3 | +import com.github.tomakehurst.wiremock.junit.WireMockRule; |
| 4 | +import com.nimbusds.oauth2.sdk.GrantType; |
| 5 | +import io.restassured.response.Response; |
| 6 | +import oidc.AbstractIntegrationTest; |
| 7 | +import org.apache.http.HttpStatus; |
| 8 | +import org.junit.ClassRule; |
| 9 | +import org.junit.Test; |
| 10 | +import org.springframework.boot.test.context.SpringBootTest; |
| 11 | + |
| 12 | +import java.io.IOException; |
| 13 | +import java.util.HashMap; |
| 14 | +import java.util.Map; |
| 15 | +import java.util.UUID; |
| 16 | + |
| 17 | +import static com.github.tomakehurst.wiremock.client.WireMock.*; |
| 18 | +import static io.restassured.RestAssured.given; |
| 19 | +import static org.junit.Assert.assertEquals; |
| 20 | + |
| 21 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, |
| 22 | + properties = { |
| 23 | + "cron.node-cron-job-responsible=false", |
| 24 | + "eduid.uri=http://localhost:8099/attribute-manipulation", |
| 25 | + "features.enforce-eduid-resource-server-linked-account=false" |
| 26 | + |
| 27 | + }) |
| 28 | +public class IntrospectEndpointDisabledEduIDEnforcementTest extends AbstractIntegrationTest { |
| 29 | + |
| 30 | + @ClassRule |
| 31 | + public static WireMockRule wireMockRule = new WireMockRule(8099); |
| 32 | + |
| 33 | + @Test |
| 34 | + public void introspectionEduIdEmptyPseudonymisation() throws IOException { |
| 35 | + Map<String, String> queryParams = new HashMap<>(); |
| 36 | + queryParams.put("scope", "openid"); |
| 37 | + queryParams.put("client_id", "mock-sp"); |
| 38 | + queryParams.put("response_type", "code"); |
| 39 | + queryParams.put("redirect_uri", openIDClient("mock-sp").getRedirectUrls().get(0)); |
| 40 | + |
| 41 | + Response response = given().redirects().follow(false) |
| 42 | + .when() |
| 43 | + .header("Content-type", "application/json") |
| 44 | + .queryParams(queryParams) |
| 45 | + .get("oidc/authorize?user=eduid"); |
| 46 | + |
| 47 | + String code = getCode(response); |
| 48 | + Map<String, Object> body = doToken(code, "mock-sp", "secret", GrantType.AUTHORIZATION_CODE); |
| 49 | + String accessToken = (String) body.get("access_token"); |
| 50 | + |
| 51 | + stubFor(get(urlPathMatching("/attribute-manipulation")).willReturn(aResponse() |
| 52 | + .withHeader("Content-Type", "application/json") |
| 53 | + .withBody(objectMapper.writeValueAsString(Map.of())))); |
| 54 | + Map<String, Object> results = given() |
| 55 | + .when() |
| 56 | + .header("Content-type", "application/x-www-form-urlencoded") |
| 57 | + .auth() |
| 58 | + .preemptive() |
| 59 | + .basic("resource-server-playground-client", "secret") |
| 60 | + .formParam("token", accessToken) |
| 61 | + .post("oidc/introspect") |
| 62 | + .as(mapTypeRef); |
| 63 | + //See src/main/resources/data/eduid.json |
| 64 | + assertEquals("3415570f-be91-4ba8-b9ba-e479d18094d5", results.get("eduid")); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + public void introspectionEduIdValidPseudonymisation() throws IOException { |
| 69 | + Map<String, String> queryParams = new HashMap<>(); |
| 70 | + queryParams.put("scope", "openid"); |
| 71 | + queryParams.put("client_id", "mock-sp"); |
| 72 | + queryParams.put("response_type", "code"); |
| 73 | + queryParams.put("redirect_uri", openIDClient("mock-sp").getRedirectUrls().get(0)); |
| 74 | + |
| 75 | + Response response = given().redirects().follow(false) |
| 76 | + .when() |
| 77 | + .header("Content-type", "application/json") |
| 78 | + .queryParams(queryParams) |
| 79 | + .get("oidc/authorize?user=eduid"); |
| 80 | + |
| 81 | + String code = getCode(response); |
| 82 | + Map<String, Object> body = doToken(code, "mock-sp", "secret", GrantType.AUTHORIZATION_CODE); |
| 83 | + String accessToken = (String) body.get("access_token"); |
| 84 | + |
| 85 | + Map<Object, Object> pseudonymiseResults = Map.of("eduid", UUID.randomUUID().toString()); |
| 86 | + stubFor(get(urlPathMatching("/attribute-manipulation")).willReturn(aResponse() |
| 87 | + .withHeader("Content-Type", "application/json") |
| 88 | + .withBody(objectMapper.writeValueAsString(pseudonymiseResults)))); |
| 89 | + |
| 90 | + Map<String, Object> results = given() |
| 91 | + .when() |
| 92 | + .header("Content-type", "application/x-www-form-urlencoded") |
| 93 | + .auth() |
| 94 | + .preemptive() |
| 95 | + .basic("resource-server-playground-client", "secret") |
| 96 | + .formParam("token", accessToken) |
| 97 | + .post("oidc/introspect") |
| 98 | + .as(mapTypeRef); |
| 99 | + //Replaced pseudo eduID |
| 100 | + assertEquals(pseudonymiseResults.get("eduid"), results.get("eduid")); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void introspectionEduIdErrorPseudonymisation() throws IOException { |
| 105 | + Map<String, String> queryParams = new HashMap<>(); |
| 106 | + queryParams.put("scope", "openid"); |
| 107 | + queryParams.put("client_id", "mock-sp"); |
| 108 | + queryParams.put("response_type", "code"); |
| 109 | + queryParams.put("redirect_uri", openIDClient("mock-sp").getRedirectUrls().get(0)); |
| 110 | + |
| 111 | + Response response = given().redirects().follow(false) |
| 112 | + .when() |
| 113 | + .header("Content-type", "application/json") |
| 114 | + .queryParams(queryParams) |
| 115 | + .get("oidc/authorize?user=eduid"); |
| 116 | + |
| 117 | + String code = getCode(response); |
| 118 | + Map<String, Object> body = doToken(code, "mock-sp", "secret", GrantType.AUTHORIZATION_CODE); |
| 119 | + String accessToken = (String) body.get("access_token"); |
| 120 | + |
| 121 | + stubFor(get(urlPathMatching("/attribute-manipulation")) |
| 122 | + .willReturn(aResponse() |
| 123 | + .withHeader("Content-Type", "application/json") |
| 124 | + .withStatus(HttpStatus.SC_BAD_REQUEST))); |
| 125 | + |
| 126 | + Map<String, Object> results = given() |
| 127 | + .when() |
| 128 | + .header("Content-type", "application/x-www-form-urlencoded") |
| 129 | + .auth() |
| 130 | + .preemptive() |
| 131 | + .basic("resource-server-playground-client", "secret") |
| 132 | + .formParam("token", accessToken) |
| 133 | + .post("oidc/introspect") |
| 134 | + .as(mapTypeRef); |
| 135 | + //See src/main/resources/data/eduid.json |
| 136 | + assertEquals("3415570f-be91-4ba8-b9ba-e479d18094d5", results.get("eduid")); |
| 137 | + } |
| 138 | + |
| 139 | + @Test |
| 140 | + public void introspectionEduIdRSNotLinkedPseudonymisation() throws IOException { |
| 141 | + Map<String, String> queryParams = new HashMap<>(); |
| 142 | + queryParams.put("scope", "openid"); |
| 143 | + queryParams.put("client_id", "mock-sp"); |
| 144 | + queryParams.put("response_type", "code"); |
| 145 | + queryParams.put("redirect_uri", openIDClient("mock-sp").getRedirectUrls().get(0)); |
| 146 | + |
| 147 | + Response response = given().redirects().follow(false) |
| 148 | + .when() |
| 149 | + .header("Content-type", "application/json") |
| 150 | + .queryParams(queryParams) |
| 151 | + .get("oidc/authorize?user=eduid"); |
| 152 | + |
| 153 | + String code = getCode(response); |
| 154 | + Map<String, Object> body = doToken(code, "mock-sp", "secret", GrantType.AUTHORIZATION_CODE); |
| 155 | + String accessToken = (String) body.get("access_token"); |
| 156 | + |
| 157 | + Map<Object, Object> pseudonymiseResults = Map.of( |
| 158 | + "eduid", UUID.randomUUID().toString(), |
| 159 | + "eduperson_principal_name", "some-eppn" |
| 160 | + ); |
| 161 | + stubFor(get(urlPathMatching("/attribute-manipulation")).willReturn(aResponse() |
| 162 | + .withHeader("Content-Type", "application/json") |
| 163 | + .withBody(objectMapper.writeValueAsString(pseudonymiseResults)))); |
| 164 | + |
| 165 | + Map<String, Object> results = given() |
| 166 | + .when() |
| 167 | + .header("Content-type", "application/x-www-form-urlencoded") |
| 168 | + .auth() |
| 169 | + .preemptive() |
| 170 | + .basic("resource-server-playground-client", "secret") |
| 171 | + .formParam("token", accessToken) |
| 172 | + .post("oidc/introspect") |
| 173 | + .as(mapTypeRef); |
| 174 | + //See the pseudonymiseResults with an eduperson_principal_name |
| 175 | + assertEquals(pseudonymiseResults.get("eduid"), results.get("eduid")); |
| 176 | + assertEquals(pseudonymiseResults.get("eduperson_principal_name"), results.get("eduperson_principal_name")); |
| 177 | + } |
| 178 | + |
| 179 | + |
| 180 | +} |
0 commit comments