diff --git a/provisioning-mock/src/main/java/provisioning/api/GraphController.java b/provisioning-mock/src/main/java/provisioning/api/GraphController.java index 9a7f22ef..91c7b702 100644 --- a/provisioning-mock/src/main/java/provisioning/api/GraphController.java +++ b/provisioning-mock/src/main/java/provisioning/api/GraphController.java @@ -16,6 +16,7 @@ import provisioning.model.ResourceType; import provisioning.repository.ProvisioningRepository; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -53,11 +54,13 @@ public ResponseEntity> createUser(@RequestBody Map parts = List.of(inviteRedirectUrl.split("/")); + String manageId = parts.get(parts.size() - 2); + String userId = parts.get(parts.size() - 1); String id = UUID.randomUUID().toString(); return ResponseEntity.ok(Map.of( "invitedUser", Map.of("id", id), - "inviteRedeemUrl", this.mockServerBaseUrl + "/graph/accept/" + sub, + "inviteRedeemUrl", String.format("%s/graph/accept/%s/%s", this.mockServerBaseUrl, manageId, userId), "id", id)); } @@ -76,6 +79,21 @@ public ResponseEntity> getUser() { return ResponseEntity.ok(Map.of("id", UUID.randomUUID().toString())); } + @DeleteMapping("/users") + public ResponseEntity deleteUser() { + LOG.info("/graph/users DELETE "); + + provisioningRepository.save(new Provisioning( + ProvisioningType.graph, + objectMapper.valueToTree(null), + HttpMethod.DELETE, + ResourceType.USERS, + "/graph/users" + )); + + return ResponseEntity.status(201).build(); + } + @PatchMapping("/users") public ResponseEntity> updateUser(@RequestBody Map user) { LOG.info("/graph/users PATCH " + user); @@ -91,11 +109,11 @@ public ResponseEntity> updateUser(@RequestBody Map result = given() + .when() + .accept(ContentType.JSON) + .contentType(ContentType.JSON) + .body(Map.of("inviteRedirectUrl", "http://localhost/api/v1/invitations/ms-accept-return/1/2")) + .post("/graph/users") + .as(new TypeRef<>() { + }); + assertNotNull(result.get("id")); + assertNotNull(((Map) result.get("invitedUser")).get("id")); + assertEquals("http://localhost:8081/graph/accept/1/2", result.get("inviteRedeemUrl")); + + assertEquals(1, provisioningRepository.count()); + } + + @Test + void getUser() { + Map result = given() + .when() + .accept(ContentType.JSON) + .contentType(ContentType.JSON) + .get("/graph/users") + .as(new TypeRef<>() { + }); + assertNotNull(result.get("id")); + assertEquals(1, provisioningRepository.count()); + } + + @Test + void updateUser() { + Map result = given() + .when() + .accept(ContentType.JSON) + .contentType(ContentType.JSON) + .body(Map.of("id", UUID.randomUUID().toString())) + .patch("/graph/users") + .as(new TypeRef<>() { + }); + assertNotNull(result.get("id")); + + assertEquals(1, provisioningRepository.count()); + } + + @Test + void deleteUser() { + given() + .when() + .accept(ContentType.JSON) + .contentType(ContentType.JSON) + .delete("/graph/users") + .then() + .statusCode(201); + + assertEquals(1, provisioningRepository.count()); + } + + @Test + void accept() { + given() + .redirects() + .follow(false) + .when() + .accept(ContentType.JSON) + .contentType(ContentType.JSON) + .get("/graph/accept/1/2") + .then() + .header("Location", "http://localhost:8080/api/v1/users/ms-accept-return/1/2"); + } +} \ No newline at end of file diff --git a/provisioning-mock/src/test/java/provisioning/SCIMControllerTest.java b/provisioning-mock/src/test/java/provisioning/api/SCIMControllerTest.java similarity index 72% rename from provisioning-mock/src/test/java/provisioning/SCIMControllerTest.java rename to provisioning-mock/src/test/java/provisioning/api/SCIMControllerTest.java index 61882160..4a830fa7 100644 --- a/provisioning-mock/src/test/java/provisioning/SCIMControllerTest.java +++ b/provisioning-mock/src/test/java/provisioning/api/SCIMControllerTest.java @@ -1,15 +1,7 @@ -package provisioning; +package provisioning.api; -import io.restassured.RestAssured; import io.restassured.http.ContentType; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import provisioning.repository.ProvisioningRepository; import java.util.Map; import java.util.UUID; @@ -18,21 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -@ExtendWith(SpringExtension.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class SCIMControllerTest { - - @LocalServerPort - protected int port; - - @Autowired - protected ProvisioningRepository provisioningRepository; - - @BeforeEach - protected void beforeEach() { - RestAssured.port = port; - provisioningRepository.deleteAllInBatch(); - } +class SCIMControllerTest extends AbstractTest { @Test void user() { diff --git a/server/src/main/java/access/provision/Provisioning.java b/server/src/main/java/access/provision/Provisioning.java index e19bead6..c76841b2 100644 --- a/server/src/main/java/access/provision/Provisioning.java +++ b/server/src/main/java/access/provision/Provisioning.java @@ -60,7 +60,6 @@ private void invariant() { assert scimPassword != null : "scimPassword is null"; } case graph -> { - assert graphUrl != null: "graphUrl is null"; assert graphClientId != null: "graphClientId is null"; assert graphSecret != null: "graphSecret is null"; } diff --git a/server/src/main/java/access/provision/graph/GraphClient.java b/server/src/main/java/access/provision/graph/GraphClient.java index a46d4391..e2266b7c 100644 --- a/server/src/main/java/access/provision/graph/GraphClient.java +++ b/server/src/main/java/access/provision/graph/GraphClient.java @@ -16,6 +16,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.http.HttpStatus; import org.springframework.util.ReflectionUtils; +import org.springframework.util.StringUtils; import java.lang.reflect.Field; @@ -121,7 +122,7 @@ private GraphServiceClient getRequestGraphServiceClient(Provisioning pr private static void replaceGraphUrl(String graphUrl, BaseRequest buildRequest) { //hack to enable testing - if (graphUrl.startsWith("http://") || graphUrl.contains("mock")) { + if (StringUtils.hasText(graphUrl) && (graphUrl.startsWith("http://") || graphUrl.contains("mock"))) { Field field = ReflectionUtils.findField(BaseRequest.class, "requestUrl"); ReflectionUtils.makeAccessible(field); ReflectionUtils.setField(field, buildRequest, graphUrl); diff --git a/server/src/test/java/access/provision/ProvisioningTest.java b/server/src/test/java/access/provision/ProvisioningTest.java index 7e7c1760..a7182b28 100644 --- a/server/src/test/java/access/provision/ProvisioningTest.java +++ b/server/src/test/java/access/provision/ProvisioningTest.java @@ -30,9 +30,8 @@ void provisioningEva() { @Test void provisioningGraph() { this.assertInvariant(this.provisioningMap(ProvisioningType.graph)); - this.assertInvariant(this.provisioningMap(ProvisioningType.graph, "graph_url")); - this.assertInvariant(this.provisioningMap(ProvisioningType.graph, "graph_url", "graph_client_id")); - this.provisioningMap(ProvisioningType.graph, "graph_url", "graph_client_id", "graph_secret"); + this.assertInvariant(this.provisioningMap(ProvisioningType.graph,"graph_client_id")); + this.provisioningMap(ProvisioningType.graph, "graph_client_id", "graph_secret"); } private void assertInvariant(Map provider) {