|
5 | 5 | import access.model.EntityType; |
6 | 6 | import access.model.Environment; |
7 | 7 | import access.security.InstitutionAdmin; |
| 8 | +import com.fasterxml.jackson.core.JsonProcessingException; |
8 | 9 | import com.fasterxml.jackson.core.type.TypeReference; |
9 | 10 | import com.nimbusds.jose.util.IOUtils; |
10 | 11 | import io.restassured.common.mapper.TypeRef; |
@@ -124,6 +125,31 @@ void policyByServiceProvider() { |
124 | 125 | assertEquals(1, policies.size()); |
125 | 126 | } |
126 | 127 |
|
| 128 | + @SneakyThrows |
| 129 | + @Test |
| 130 | + void policyByServiceProviderNotAllowed() { |
| 131 | + Map<String, Object> identityProvider = super.stubForIdentityProviderByEntityId("http://mock-idp"); |
| 132 | + Map<String, Object> attributes = Map.of( |
| 133 | + "sub", INSTITUTION_ADMIN, |
| 134 | + InstitutionAdmin.IDENTITY_PROVIDER, identityProvider); |
| 135 | + AccessCookieFilter accessCookieFilter = mockLoginFlow(attributes); |
| 136 | + |
| 137 | + String serviceProviderEntityId = "nope"; |
| 138 | + //The IdP is fetched to check the allowed entities |
| 139 | + this.stubForGetProvider(EntityType.saml20_idp, "7", Environment.PROD); |
| 140 | + |
| 141 | + given() |
| 142 | + .when() |
| 143 | + .filter(accessCookieFilter.cookieFilter()) |
| 144 | + .header(csrfHeader(accessCookieFilter)) |
| 145 | + .accept(ContentType.JSON) |
| 146 | + .contentType(ContentType.JSON) |
| 147 | + .queryParam("entityId", serviceProviderEntityId) |
| 148 | + .get("/api/v1/manage/policies") |
| 149 | + .then() |
| 150 | + .statusCode(HttpStatus.FORBIDDEN.value()); |
| 151 | + } |
| 152 | + |
127 | 153 | @SneakyThrows |
128 | 154 | @Test |
129 | 155 | void uniqueEntityId() { |
@@ -182,6 +208,25 @@ void arpInfo() { |
182 | 208 | assertTrue(allAttributesPresent); |
183 | 209 | } |
184 | 210 |
|
| 211 | + @Test |
| 212 | + void allowedAttributes() throws JsonProcessingException { |
| 213 | + List<Map<String, Object>> allowedAttributes = localManage.allowedAttributes(); |
| 214 | + String body = objectMapper.writeValueAsString(allowedAttributes); |
| 215 | + stubFor(get("/manage/api/internal/protected/allowed-attributes") |
| 216 | + .willReturn(aResponse().withHeader("Content-Type", "application/json") |
| 217 | + .withBody(body) |
| 218 | + .withStatus(200))); |
| 219 | + |
| 220 | + allowedAttributes = given() |
| 221 | + .when() |
| 222 | + .accept(ContentType.JSON) |
| 223 | + .contentType(ContentType.JSON) |
| 224 | + .get("/api/v1/manage/allowed-attributes") |
| 225 | + .as(new TypeRef<>() { |
| 226 | + }); |
| 227 | + assertEquals(9, allowedAttributes.size()); |
| 228 | + } |
| 229 | + |
185 | 230 | @Test |
186 | 231 | void createPolicy() throws Exception { |
187 | 232 | AccessCookieFilter accessCookieFilter = openIDConnectFlow("/api/v1/users/me", ADMIN_SUB); |
@@ -214,13 +259,13 @@ void uniquePolicyName() throws Exception { |
214 | 259 | .withBody("[]") |
215 | 260 | .withStatus(200))); |
216 | 261 |
|
217 | | - List<Map<String, Object>> policies =given() |
| 262 | + List<Map<String, Object>> policies = given() |
218 | 263 | .when() |
219 | 264 | .filter(accessCookieFilter.cookieFilter()) |
220 | 265 | .header(accessCookieFilter.csrfToken().getHeaderName(), accessCookieFilter.csrfToken().getToken()) |
221 | 266 | .accept(ContentType.JSON) |
222 | 267 | .contentType(ContentType.JSON) |
223 | | - .body(Map.of("name","policyName")) |
| 268 | + .body(Map.of("name", "policyName")) |
224 | 269 | .post("/api/v1/manage/unique-policy-name") |
225 | 270 | .as(new TypeRef<>() { |
226 | 271 | }); |
|
0 commit comments