diff --git a/src/main/java/org/eclipsefoundation/git/eca/resource/ValidationResource.java b/src/main/java/org/eclipsefoundation/git/eca/resource/ValidationResource.java index 7c55f68c51a1af3184a80c8c19c6cf01e751f1dd..ded0d81983eed156a35ff75aafda69f7efc54059 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/resource/ValidationResource.java +++ b/src/main/java/org/eclipsefoundation/git/eca/resource/ValidationResource.java @@ -13,6 +13,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; @@ -43,6 +44,7 @@ import org.eclipsefoundation.git.eca.namespace.ProviderType; import org.eclipsefoundation.git.eca.service.ProjectsService; import org.eclipsefoundation.git.eca.service.UserService; import org.eclipsefoundation.git.eca.service.ValidationService; +import org.jboss.resteasy.annotations.jaxrs.QueryParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,7 +56,7 @@ import io.quarkus.qute.Template; * commits passed to this endpoint. Should be as system agnostic as possible to allow for any service to request * validation with less reliance on services external to the Eclipse foundation. * - * @author Martin Lowe + * @author Martin Lowe, Zachary Sabourin */ @Path("/eca") @Consumes({ MediaType.APPLICATION_JSON }) @@ -159,6 +161,23 @@ public class ValidationResource { membershipTemplateWeb.data("statuses", statuses, "repoUrl", statuses.get(0).getRepoUrl()).render()) .build(); } + + @GET + @Path("/lookup") + public Response getUserStatus(@QueryParam("email") String email) { + + EclipseUser user = users.getUser(email); + + if (Objects.isNull(user)) { + return Response.status(404).build(); + } + + if(!user.getECA().getSigned()) { + return Response.status(403).build(); + } + + return Response.ok().build(); + } /** * Check if there are any issues with the validation request, returning error messages if there are issues with the diff --git a/src/test/java/org/eclipsefoundation/git/eca/resource/ValidationResourceTest.java b/src/test/java/org/eclipsefoundation/git/eca/resource/ValidationResourceTest.java index ee7500e71120b8d7aa27831f61511b194ebd7472..56e28dfe97351d448deed49eb5bebba18879aae3 100644 --- a/src/test/java/org/eclipsefoundation/git/eca/resource/ValidationResourceTest.java +++ b/src/test/java/org/eclipsefoundation/git/eca/resource/ValidationResourceTest.java @@ -49,6 +49,7 @@ import io.restassured.http.ContentType; @QuarkusTest class ValidationResourceTest { public static final String ECA_BASE_URL = "/eca"; + public static final String LOOKUP_URL = ECA_BASE_URL + "/lookup"; @Inject CachingService cs; @@ -983,4 +984,34 @@ class ValidationResourceTest { is(true), "errorCount", is(0), "commits." + c1.getHash() + ".messages[0].code", not(APIStatusCode.SUCCESS_SKIPPED.getValue())); } + + /* + * + * USER LOOKUP TESTS + * + */ + + @Test + void validateUserLookup_userNotFound() { + String userEmail = "dummy@fake.co"; + + // User should not exist - status 404 + given().contentType(ContentType.JSON).when().get(LOOKUP_URL + "?email=" + userEmail).then().statusCode(404); + } + + @Test + void validateUserLookup_userNoECA() { + String userEmail = "newbie@important.co"; + + // User exists but no ECA - status 403 + given().contentType(ContentType.JSON).when().get(LOOKUP_URL + "?email=" + userEmail).then().statusCode(403); + } + + @Test + void validateUserLookup_userSuccess() { + String userEmail = "slom@eclipse-foundation.org"; + + // User exists with ECA - status 200 + given().contentType(ContentType.JSON).when().get(LOOKUP_URL + "?email=" + userEmail).then().statusCode(200); + } }