|
9 | 9 | import access.model.ConnectionStatus; |
10 | 10 | import access.model.EntityType; |
11 | 11 | import access.model.Environment; |
| 12 | +import access.model.ImportEntityRequest; |
| 13 | +import access.model.MigrateApplicationRequest; |
12 | 14 | import access.model.Organization; |
| 15 | +import com.fasterxml.jackson.core.JsonProcessingException; |
13 | 16 | import com.fasterxml.jackson.core.type.TypeReference; |
14 | 17 | import io.restassured.common.mapper.TypeRef; |
15 | 18 | import io.restassured.http.ContentType; |
@@ -239,4 +242,170 @@ void delete() { |
239 | 242 | Optional<Application> optionalApplication = applicationRepository.findById(applicationId); |
240 | 243 | assertFalse(optionalApplication.isPresent()); |
241 | 244 | } |
| 245 | + |
| 246 | + @Test |
| 247 | + void findAll() { |
| 248 | + AccessCookieFilter accessCookieFilter = mockLoginFlow(SUPER_SUB); |
| 249 | + List<Map<String, Object>> applications = given() |
| 250 | + .when() |
| 251 | + .filter(accessCookieFilter.cookieFilter()) |
| 252 | + .header(csrfHeader(accessCookieFilter)) |
| 253 | + .accept(ContentType.JSON) |
| 254 | + .contentType(ContentType.JSON) |
| 255 | + .get("/api/v1/applications/all") |
| 256 | + .as(new TypeRef<>() { |
| 257 | + }); |
| 258 | + |
| 259 | + assertEquals(3, applications.size()); |
| 260 | + } |
| 261 | + |
| 262 | + @Test |
| 263 | + void allLightByOrganization() { |
| 264 | + AccessCookieFilter accessCookieFilter = mockLoginFlow(SUPER_SUB); |
| 265 | + Long organizationId = seedIdentifiers.get(SHARE_LOGICS); |
| 266 | + List<Map<String, Object>> applications = given() |
| 267 | + .when() |
| 268 | + .filter(accessCookieFilter.cookieFilter()) |
| 269 | + .header(csrfHeader(accessCookieFilter)) |
| 270 | + .accept(ContentType.JSON) |
| 271 | + .contentType(ContentType.JSON) |
| 272 | + .pathParam("organizationId", organizationId) |
| 273 | + .get("/api/v1/applications/all/light/{organizationId}") |
| 274 | + .as(new TypeRef<>() { |
| 275 | + }); |
| 276 | + |
| 277 | + assertEquals(2, applications.size()); |
| 278 | + } |
| 279 | + |
| 280 | + @Test |
| 281 | + void identityProvidersByAllowedConnections() throws JsonProcessingException { |
| 282 | + AccessCookieFilter accessCookieFilter = mockLoginFlow(SUPER_SUB); |
| 283 | + Long applicationId = seedIdentifiers.get(BUDDY_CHECK); |
| 284 | + |
| 285 | + List<Connection> connections = List.of( |
| 286 | + connection(EntityType.saml20_sp, "4"), |
| 287 | + connection(EntityType.oidc10_rp, "5") |
| 288 | + ); |
| 289 | + List<Map<String, Object>> identityProviders = localManage.identityProvidersByAllowedConnections(connections); |
| 290 | + String body = objectMapper.writeValueAsString(identityProviders); |
| 291 | + stubFor(post(urlEqualTo("/manage/api/internal/delete-consequences")).willReturn(aResponse() |
| 292 | + .withHeader("Content-Type", "application/json") |
| 293 | + .withBody(body))); |
| 294 | + |
| 295 | + List<Map<String, Object>> providers = given() |
| 296 | + .when() |
| 297 | + .filter(accessCookieFilter.cookieFilter()) |
| 298 | + .header(csrfHeader(accessCookieFilter)) |
| 299 | + .accept(ContentType.JSON) |
| 300 | + .contentType(ContentType.JSON) |
| 301 | + .pathParam("applicationId", applicationId) |
| 302 | + .get("/api/v1/applications/identity-providers-allowed-connections/{applicationId}") |
| 303 | + .as(new TypeRef<>() { |
| 304 | + }); |
| 305 | + |
| 306 | + assertEquals(2, providers.size()); |
| 307 | + } |
| 308 | + |
| 309 | + @Test |
| 310 | + void identityProvidersByAllowedConnectionsTestConnection() { |
| 311 | + AccessCookieFilter accessCookieFilter = mockLoginFlow(SUPER_SUB); |
| 312 | + Long applicationId = seedIdentifiers.get(NITRO_MAP); |
| 313 | + List<Map<String, Object>> providers = given() |
| 314 | + .when() |
| 315 | + .filter(accessCookieFilter.cookieFilter()) |
| 316 | + .header(csrfHeader(accessCookieFilter)) |
| 317 | + .accept(ContentType.JSON) |
| 318 | + .contentType(ContentType.JSON) |
| 319 | + .pathParam("applicationId", applicationId) |
| 320 | + .get("/api/v1/applications/identity-providers-allowed-connections/{applicationId}") |
| 321 | + .as(new TypeRef<>() { |
| 322 | + }); |
| 323 | + |
| 324 | + assertEquals(0, providers.size()); |
| 325 | + } |
| 326 | + |
| 327 | + @Test |
| 328 | + void migrate() { |
| 329 | + AccessCookieFilter accessCookieFilter = mockLoginFlow(SUPER_SUB); |
| 330 | + Application applicationBuddyCheck = applicationRepository.findDetailsById(seedIdentifiers.get(BUDDY_CHECK)).get(); |
| 331 | + assertEquals(SHARE_LOGICS, applicationBuddyCheck.getOrganization().getName()); |
| 332 | + |
| 333 | + MigrateApplicationRequest migrateApplicationRequest = new MigrateApplicationRequest( |
| 334 | + seedIdentifiers.get(BUDDY_CHECK), |
| 335 | + seedIdentifiers.get(FAR_WIND) |
| 336 | + ); |
| 337 | + stubForGetProvider(EntityType.oidc10_rp, MANAGE_IDENTIFIER, Environment.PROD, "5"); |
| 338 | + Connection connectionProd = connectionRepository.findById(seedIdentifiers.get(BUDDY_CHECK_PROD)).get(); |
| 339 | + connectionProd.setManageIdentifier("5"); |
| 340 | + super.stubForSaveProvider(connectionProd); |
| 341 | + |
| 342 | + given() |
| 343 | + .when() |
| 344 | + .filter(accessCookieFilter.cookieFilter()) |
| 345 | + .header(csrfHeader(accessCookieFilter)) |
| 346 | + .accept(ContentType.JSON) |
| 347 | + .contentType(ContentType.JSON) |
| 348 | + .body(migrateApplicationRequest) |
| 349 | + .put("/api/v1/applications/migrate") |
| 350 | + .then() |
| 351 | + .statusCode(HttpStatus.OK.value()); |
| 352 | + |
| 353 | + applicationBuddyCheck = applicationRepository.findDetailsById(seedIdentifiers.get(BUDDY_CHECK)).get(); |
| 354 | + assertEquals(FAR_WIND, applicationBuddyCheck.getOrganization().getName()); |
| 355 | + |
| 356 | + } |
| 357 | + |
| 358 | + @Test |
| 359 | + void importEntity() { |
| 360 | + AccessCookieFilter accessCookieFilter = mockLoginFlow(SUPER_SUB); |
| 361 | + |
| 362 | + Map<String, Object> provider = localManage.providerByManageIdentifier(EntityType.oidc10_rp, "10", Environment.PROD); |
| 363 | + ImportEntityRequest importEntityRequest = new ImportEntityRequest( |
| 364 | + seedIdentifiers.get(FAR_WIND), |
| 365 | + null, |
| 366 | + provider |
| 367 | + ); |
| 368 | + super.stubForSaveProvider(connection(EntityType.oidc10_rp, "5")); |
| 369 | + given() |
| 370 | + .when() |
| 371 | + .filter(accessCookieFilter.cookieFilter()) |
| 372 | + .header(csrfHeader(accessCookieFilter)) |
| 373 | + .accept(ContentType.JSON) |
| 374 | + .contentType(ContentType.JSON) |
| 375 | + .body(importEntityRequest) |
| 376 | + .post("/api/v1/applications/import") |
| 377 | + .then() |
| 378 | + .statusCode(HttpStatus.OK.value()); |
| 379 | + |
| 380 | + Organization organization = organizationRepository.findApplicationsDetailsOrganizationById(seedIdentifiers.get(FAR_WIND)).get(); |
| 381 | + //See src/main/resources/manage/oidc10_rp.json id="10" |
| 382 | + Application application = organization.getApplications().stream() |
| 383 | + .filter(app -> app.getName().equals("OIDC Playground Client")).findFirst().get(); |
| 384 | + assertEquals(1, application.getConnections().size()); |
| 385 | + } |
| 386 | + |
| 387 | + @Test |
| 388 | + void importEntityExistingApplication() { |
| 389 | + AccessCookieFilter accessCookieFilter = mockLoginFlow(SUPER_SUB); |
| 390 | + |
| 391 | + Map<String, Object> provider = localManage.providerByManageIdentifier(EntityType.oidc10_rp, "10", Environment.PROD); |
| 392 | + ImportEntityRequest importEntityRequest = new ImportEntityRequest( |
| 393 | + seedIdentifiers.get(FAR_WIND), |
| 394 | + seedIdentifiers.get(NITRO_MAP), |
| 395 | + provider |
| 396 | + ); |
| 397 | + super.stubForSaveProvider(connection(EntityType.oidc10_rp, "10")); |
| 398 | + given() |
| 399 | + .when() |
| 400 | + .filter(accessCookieFilter.cookieFilter()) |
| 401 | + .header(csrfHeader(accessCookieFilter)) |
| 402 | + .accept(ContentType.JSON) |
| 403 | + .contentType(ContentType.JSON) |
| 404 | + .body(importEntityRequest) |
| 405 | + .post("/api/v1/applications/import") |
| 406 | + .then() |
| 407 | + .statusCode(HttpStatus.OK.value()); |
| 408 | + Application application = applicationRepository.findDetailsById(seedIdentifiers.get(NITRO_MAP)).get(); |
| 409 | + assertEquals(1, application.getConnections().size()); |
| 410 | + } |
242 | 411 | } |
0 commit comments