Skip to content
Snippets Groups Projects
Commit 0c96c2cf authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

fix: Add required role to the endpoint calls

parent 1a95ce67
No related branches found
No related tags found
1 merge request!34feat(oidc): Switch API from Drupal OAuth to use Keycloak in its place
Pipeline #74551 passed
/*********************************************************************
* Copyright (c) 2025 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.openvsx.namespace;
/**
* Shared parameters used in the operation of the API.
*/
public class OpenVSXParameters {
public static final String DEFAULT_ACCESS_ROLE = "openvsx_publisher_agreement";
private OpenVSXParameters() {}
}
...@@ -15,15 +15,16 @@ import java.util.Arrays; ...@@ -15,15 +15,16 @@ import java.util.Arrays;
import org.eclipsefoundation.efservices.services.ProfileService; import org.eclipsefoundation.efservices.services.ProfileService;
import org.eclipsefoundation.http.exception.ApplicationException; import org.eclipsefoundation.http.exception.ApplicationException;
import org.eclipsefoundation.openvsx.namespace.OpenVSXParameters;
import io.quarkus.security.Authenticated;
import io.quarkus.security.identity.SecurityIdentity; import io.quarkus.security.identity.SecurityIdentity;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
@Authenticated
@Path("profile") @Path("profile")
@RolesAllowed(OpenVSXParameters.DEFAULT_ACCESS_ROLE)
public class ProfileResource { public class ProfileResource {
private final ProfileService profile; private final ProfileService profile;
......
...@@ -21,12 +21,13 @@ import org.eclipsefoundation.http.exception.ApplicationException; ...@@ -21,12 +21,13 @@ import org.eclipsefoundation.http.exception.ApplicationException;
import org.eclipsefoundation.openvsx.config.PublisherAgreementConfig; import org.eclipsefoundation.openvsx.config.PublisherAgreementConfig;
import org.eclipsefoundation.openvsx.models.AgreementSigningRequest; import org.eclipsefoundation.openvsx.models.AgreementSigningRequest;
import org.eclipsefoundation.openvsx.models.PublisherAgreementData; import org.eclipsefoundation.openvsx.models.PublisherAgreementData;
import org.eclipsefoundation.openvsx.namespace.OpenVSXParameters;
import org.eclipsefoundation.openvsx.services.FoundationOperationService; import org.eclipsefoundation.openvsx.services.FoundationOperationService;
import org.eclipsefoundation.openvsx.services.PublisherAgreementService; import org.eclipsefoundation.openvsx.services.PublisherAgreementService;
import org.eclipsefoundation.utils.exception.FinalForbiddenException; import org.eclipsefoundation.utils.exception.FinalForbiddenException;
import io.quarkus.security.Authenticated;
import io.quarkus.security.identity.SecurityIdentity; import io.quarkus.security.identity.SecurityIdentity;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.BadRequestException; import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.DELETE; import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
...@@ -41,8 +42,8 @@ import jakarta.ws.rs.core.Response.Status; ...@@ -41,8 +42,8 @@ import jakarta.ws.rs.core.Response.Status;
/** /**
* Resource containing calls for retrieving and signing OpenVSX publisher agreements. * Resource containing calls for retrieving and signing OpenVSX publisher agreements.
*/ */
@Authenticated
@Path("publisher_agreement") @Path("publisher_agreement")
@RolesAllowed(OpenVSXParameters.DEFAULT_ACCESS_ROLE)
public class PublisherAgreementResource { public class PublisherAgreementResource {
private static final String NOT_FOUND_MSG_FORMAT = "Unable to find agreement for user: %s"; private static final String NOT_FOUND_MSG_FORMAT = "Unable to find agreement for user: %s";
......
...@@ -14,8 +14,8 @@ package org.eclipsefoundation.openvsx.resources; ...@@ -14,8 +14,8 @@ package org.eclipsefoundation.openvsx.resources;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import org.eclipsefoundation.openvsx.namespace.OpenVSXParameters;
import org.eclipsefoundation.openvsx.test.helpers.SchemaNamespaceHelper; import org.eclipsefoundation.openvsx.test.helpers.SchemaNamespaceHelper;
import org.eclipsefoundation.testing.helpers.AuthHelper;
import org.eclipsefoundation.testing.helpers.TestCaseHelper; import org.eclipsefoundation.testing.helpers.TestCaseHelper;
import org.eclipsefoundation.testing.models.EndpointTestBuilder; import org.eclipsefoundation.testing.models.EndpointTestBuilder;
import org.eclipsefoundation.testing.models.EndpointTestCase; import org.eclipsefoundation.testing.models.EndpointTestCase;
...@@ -37,19 +37,19 @@ class ProfileResourceTest { ...@@ -37,19 +37,19 @@ class ProfileResourceTest {
* GET CURRENT USER * GET CURRENT USER
*/ */
@Test @Test
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testGetProfile_success() { void testGetProfile_success() {
EndpointTestBuilder.from(GET_CURRENT_SUCCESS).run(); EndpointTestBuilder.from(GET_CURRENT_SUCCESS).run();
} }
@Test @Test
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testGetProfile_success_validateResponseFormat() { void testGetProfile_success_validateResponseFormat() {
EndpointTestBuilder.from(GET_CURRENT_SUCCESS).andCheckFormat().run(); EndpointTestBuilder.from(GET_CURRENT_SUCCESS).andCheckFormat().run();
} }
@Test @Test
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testGetProfile_success_validateSchema() { void testGetProfile_success_validateSchema() {
EndpointTestBuilder.from(GET_CURRENT_SUCCESS).andCheckSchema().run(); EndpointTestBuilder.from(GET_CURRENT_SUCCESS).andCheckSchema().run();
} }
...@@ -70,4 +70,16 @@ class ProfileResourceTest { ...@@ -70,4 +70,16 @@ class ProfileResourceTest {
.build()) .build())
.run(); .run();
} }
@Test
@TestSecurity(user = FAKEUSER_PROFILE, roles = "user")
void testGetProfile_failure_noValidRole() {
EndpointTestBuilder
.from(TestCaseHelper
.prepareTestCase(BASE_URL, new String[] {}, null)
.setStatusCode(403)
.setHeaderParams(Optional.of(Map.of("Authorization", "Bearer token1")))
.build())
.run();
}
} }
...@@ -15,8 +15,8 @@ import java.util.Map; ...@@ -15,8 +15,8 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import org.eclipsefoundation.openvsx.models.AgreementSigningRequest; import org.eclipsefoundation.openvsx.models.AgreementSigningRequest;
import org.eclipsefoundation.openvsx.namespace.OpenVSXParameters;
import org.eclipsefoundation.openvsx.test.helpers.SchemaNamespaceHelper; import org.eclipsefoundation.openvsx.test.helpers.SchemaNamespaceHelper;
import org.eclipsefoundation.testing.helpers.AuthHelper;
import org.eclipsefoundation.testing.helpers.TestCaseHelper; import org.eclipsefoundation.testing.helpers.TestCaseHelper;
import org.eclipsefoundation.testing.models.EndpointTestBuilder; import org.eclipsefoundation.testing.models.EndpointTestBuilder;
import org.eclipsefoundation.testing.models.EndpointTestCase; import org.eclipsefoundation.testing.models.EndpointTestCase;
...@@ -32,248 +32,269 @@ import jakarta.inject.Inject; ...@@ -32,248 +32,269 @@ import jakarta.inject.Inject;
@QuarkusTest @QuarkusTest
class PublisherAgreementResourceTest { class PublisherAgreementResourceTest {
public static final String BASE_URL = "publisher_agreement"; public static final String BASE_URL = "publisher_agreement";
public static final String USER_URL = BASE_URL + "/{efusername}"; public static final String USER_URL = BASE_URL + "/{efusername}";
public static final String FAKEUSER_PROFILE = "fakeuser"; public static final String FAKEUSER_PROFILE = "fakeuser";
public static final String OTHERUSER_PROFILE = "otheruser"; public static final String OTHERUSER_PROFILE = "otheruser";
public static final String NODOC_PROFILE = "nodoc"; public static final String NODOC_PROFILE = "nodoc";
public static final Optional<Map<String, Object>> invalidCreds = Optional.of(Map.of("Authorization", "Bearer token1")); public static final Optional<Map<String, Object>> invalidCreds = Optional.of(Map.of("Authorization", "Bearer token1"));
public static final EndpointTestCase GET_CURRENT_SUCCESS = TestCaseHelper public static final EndpointTestCase GET_CURRENT_SUCCESS = TestCaseHelper
.prepareTestCase(BASE_URL, new String[] {}, SchemaNamespaceHelper.PUBLISHER_AGREEMENT_SCHEMA_PATH) .prepareTestCase(BASE_URL, new String[] {}, SchemaNamespaceHelper.PUBLISHER_AGREEMENT_SCHEMA_PATH)
.build(); .build();
public static final EndpointTestCase GET_CURRENT_NOT_FOUND = TestCaseHelper public static final EndpointTestCase GET_CURRENT_NOT_FOUND = TestCaseHelper
.prepareTestCase(BASE_URL, new String[] {}, SchemaNamespaceHelper.ERROR_SCHEMA_PATH) .prepareTestCase(BASE_URL, new String[] {}, SchemaNamespaceHelper.ERROR_SCHEMA_PATH)
.setStatusCode(404) .setStatusCode(404)
.build(); .build();
public static final EndpointTestCase BAD_CREDS = TestCaseHelper public static final EndpointTestCase BAD_CREDS = TestCaseHelper
.prepareTestCase(BASE_URL, new String[] {}, null) .prepareTestCase(BASE_URL, new String[] {}, null)
.setStatusCode(401) .setStatusCode(401)
.setHeaderParams(invalidCreds) .setHeaderParams(invalidCreds)
.build(); .build();
public static final EndpointTestCase POST_CURRENT_CONFLICT = TestCaseHelper public static final EndpointTestCase POST_CURRENT_CONFLICT = TestCaseHelper
.prepareTestCase(BASE_URL, new String[] {}, null) .prepareTestCase(BASE_URL, new String[] {}, null)
.setStatusCode(409) .setStatusCode(409)
.build(); .build();
public static final EndpointTestCase POST_CURRENT_INVALID_HANDLE = TestCaseHelper public static final EndpointTestCase POST_CURRENT_INVALID_HANDLE = TestCaseHelper
.prepareTestCase(BASE_URL, new String[] {}, SchemaNamespaceHelper.ERROR_SCHEMA_PATH) .prepareTestCase(BASE_URL, new String[] {}, SchemaNamespaceHelper.ERROR_SCHEMA_PATH)
.setStatusCode(400) .setStatusCode(400)
.build(); .build();
public static final EndpointTestCase GET_USER_SUCCESS = TestCaseHelper public static final EndpointTestCase GET_USER_SUCCESS = TestCaseHelper
.prepareTestCase(USER_URL, new String[] { "fakeuser" }, SchemaNamespaceHelper.PUBLISHER_AGREEMENT_SCHEMA_PATH) .prepareTestCase(USER_URL, new String[] { "fakeuser" }, SchemaNamespaceHelper.PUBLISHER_AGREEMENT_SCHEMA_PATH)
.build(); .build();
public static final EndpointTestCase GET_USER_NOT_FOUND = TestCaseHelper public static final EndpointTestCase GET_USER_NOT_FOUND = TestCaseHelper
.prepareTestCase(USER_URL, new String[] { "name" }, SchemaNamespaceHelper.ERROR_SCHEMA_PATH) .prepareTestCase(USER_URL, new String[] { "name" }, SchemaNamespaceHelper.ERROR_SCHEMA_PATH)
.setStatusCode(404) .setStatusCode(404)
.build(); .build();
public static final EndpointTestCase FOR_USER_BAD_CREDS = TestCaseHelper public static final EndpointTestCase FOR_USER_BAD_CREDS = TestCaseHelper
.prepareTestCase(USER_URL, new String[] { "fakeuser" }, SchemaNamespaceHelper.PUBLISHER_AGREEMENT_SCHEMA_PATH) .prepareTestCase(USER_URL, new String[] { "fakeuser" }, SchemaNamespaceHelper.PUBLISHER_AGREEMENT_SCHEMA_PATH)
.setStatusCode(401) .setStatusCode(401)
.setHeaderParams(invalidCreds) .setHeaderParams(invalidCreds)
.build(); .build();
public static final EndpointTestCase REVOKE_SUCCESS = TestCaseHelper public static final EndpointTestCase FOR_USER_BAD_ROLE = TestCaseHelper
.prepareTestCase(USER_URL, new String[] { "fakeuser" }, SchemaNamespaceHelper.PUBLISHER_AGREEMENT_SCHEMA_PATH) .prepareTestCase(USER_URL, new String[] { "fakeuser" }, SchemaNamespaceHelper.PUBLISHER_AGREEMENT_SCHEMA_PATH)
.setStatusCode(204) .setStatusCode(403)
.build(); .setHeaderParams(invalidCreds)
.build();
public static final EndpointTestCase REVOKE_NO_DOC = TestCaseHelper
.prepareTestCase(USER_URL, new String[] { "name" }, SchemaNamespaceHelper.ERROR_SCHEMA_PATH) public static final EndpointTestCase REVOKE_SUCCESS = TestCaseHelper
.setStatusCode(404) .prepareTestCase(USER_URL, new String[] { "fakeuser" }, SchemaNamespaceHelper.PUBLISHER_AGREEMENT_SCHEMA_PATH)
.build(); .setStatusCode(204)
.build();
public static final EndpointTestCase REVOKE_INVALID_USER = TestCaseHelper
.prepareTestCase(USER_URL, new String[] { "other" }, SchemaNamespaceHelper.ERROR_SCHEMA_PATH) public static final EndpointTestCase REVOKE_NO_DOC = TestCaseHelper
.setStatusCode(403) .prepareTestCase(USER_URL, new String[] { "name" }, SchemaNamespaceHelper.ERROR_SCHEMA_PATH)
.setResponseContentType(ContentType.JSON) .setStatusCode(404)
.build(); .build();
@Inject public static final EndpointTestCase REVOKE_INVALID_USER = TestCaseHelper
ObjectMapper mapper; .prepareTestCase(USER_URL, new String[] { "other" }, SchemaNamespaceHelper.ERROR_SCHEMA_PATH)
.setStatusCode(403)
/* .setResponseContentType(ContentType.JSON)
* GET CURRENT USER .build();
*/ public static final EndpointTestCase REVOKE_INVALID_ROLE = TestCaseHelper
@Test .prepareTestCase(USER_URL, new String[] { "fakeuser" }, SchemaNamespaceHelper.ERROR_SCHEMA_PATH)
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) .setStatusCode(403)
void testGet_currentUser_success() { .setResponseContentType(ContentType.JSON)
EndpointTestBuilder.from(GET_CURRENT_SUCCESS).run(); .build();
}
@Inject
@Test ObjectMapper mapper;
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE)
void testGet_currentUser_success_validateResponseFormat() { /*
EndpointTestBuilder.from(GET_CURRENT_SUCCESS).andCheckFormat().run(); * GET CURRENT USER
} */
@Test
@Test @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) void testGet_currentUser_success() {
void testGet_currentUser_success_validateSchema() { EndpointTestBuilder.from(GET_CURRENT_SUCCESS).run();
EndpointTestBuilder.from(GET_CURRENT_SUCCESS).andCheckSchema().run(); }
}
@Test
@Test @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
@TestSecurity(user = OTHERUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) void testGet_currentUser_success_validateResponseFormat() {
void testGet_currentUser_failure_notFound() { EndpointTestBuilder.from(GET_CURRENT_SUCCESS).andCheckFormat().run();
EndpointTestBuilder.from(GET_CURRENT_NOT_FOUND).run(); }
}
@Test
@Test @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
@TestSecurity(user = OTHERUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) void testGet_currentUser_success_validateSchema() {
void testGet_currentUser_failure_notFound_validateResponseFormat() { EndpointTestBuilder.from(GET_CURRENT_SUCCESS).andCheckSchema().run();
EndpointTestBuilder.from(GET_CURRENT_NOT_FOUND).andCheckFormat().run(); }
}
@Test
@Test @TestSecurity(user = OTHERUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
@TestSecurity(user = OTHERUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) void testGet_currentUser_failure_notFound() {
void testGet_currentUser_failure_notFound_validateSchema() { EndpointTestBuilder.from(GET_CURRENT_NOT_FOUND).run();
EndpointTestBuilder.from(GET_CURRENT_NOT_FOUND).andCheckSchema().run(); }
}
@Test
@Test @TestSecurity(user = OTHERUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testGet_currentUser_failure_badCreds() { void testGet_currentUser_failure_notFound_validateResponseFormat() {
EndpointTestBuilder.from(BAD_CREDS).run(); EndpointTestBuilder.from(GET_CURRENT_NOT_FOUND).andCheckFormat().run();
} }
/* @Test
* POST CURRENT USER @TestSecurity(user = OTHERUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
*/ void testGet_currentUser_failure_notFound_validateSchema() {
@Test EndpointTestBuilder.from(GET_CURRENT_NOT_FOUND).andCheckSchema().run();
@TestSecurity(user = NODOC_PROFILE, roles = AuthHelper.DEFAULT_ROLE) }
void testPost_currentUser_success() {
EndpointTestBuilder @Test
.from(TestCaseHelper void testGet_currentUser_failure_badCreds() {
.prepareTestCase(BASE_URL, new String[] {}, SchemaNamespaceHelper.PUBLISHER_AGREEMENT_SCHEMA_PATH) EndpointTestBuilder.from(BAD_CREDS).run();
.build()) }
.doPost(generateSigningSample("nodoc"))
.run(); /*
} * POST CURRENT USER
*/
@Test @Test
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) @TestSecurity(user = NODOC_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testPost_currentUser_conflict() { void testPost_currentUser_success() {
EndpointTestBuilder.from(POST_CURRENT_CONFLICT).doPost(generateSigningSample("fakeuser")).run(); EndpointTestBuilder
} .from(TestCaseHelper.prepareTestCase(BASE_URL, new String[] {}, SchemaNamespaceHelper.PUBLISHER_AGREEMENT_SCHEMA_PATH).build())
.doPost(generateSigningSample("nodoc"))
@Test .run();
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) }
void testPost_currentUser_conflict_validateResponseFormat() {
EndpointTestBuilder.from(POST_CURRENT_CONFLICT).doPost(generateSigningSample("fakeuser")).andCheckFormat().run(); @Test
} @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testPost_currentUser_conflict() {
@Test EndpointTestBuilder.from(POST_CURRENT_CONFLICT).doPost(generateSigningSample("fakeuser")).run();
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) }
void testPost_currentUser_conflict_validateSchema() {
EndpointTestBuilder.from(POST_CURRENT_CONFLICT).doPost(generateSigningSample("fakeuser")).andCheckFormat().run(); @Test
} @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testPost_currentUser_conflict_validateResponseFormat() {
@Test EndpointTestBuilder.from(POST_CURRENT_CONFLICT).doPost(generateSigningSample("fakeuser")).andCheckFormat().run();
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) }
void testPost_currentUser_failure_invalidHandle() {
EndpointTestBuilder.from(POST_CURRENT_INVALID_HANDLE).doPost(generateSigningSample("otheruser")).run(); @Test
} @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testPost_currentUser_conflict_validateSchema() {
@Test EndpointTestBuilder.from(POST_CURRENT_CONFLICT).doPost(generateSigningSample("fakeuser")).andCheckFormat().run();
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) }
void testPost_currentUser_failure_invalidHandle_validateFormat() {
EndpointTestBuilder.from(POST_CURRENT_INVALID_HANDLE).doPost(generateSigningSample("otheruser")).andCheckFormat().run(); @Test
} @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testPost_currentUser_failure_invalidHandle() {
@Test EndpointTestBuilder.from(POST_CURRENT_INVALID_HANDLE).doPost(generateSigningSample("otheruser")).run();
void testPost_currentUser_failure_badCreds() { }
EndpointTestBuilder.from(BAD_CREDS).doPost(generateSigningSample("fakeuser")).run();
} @Test
@TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
/* void testPost_currentUser_failure_invalidHandle_validateFormat() {
* GET FOR USER EndpointTestBuilder.from(POST_CURRENT_INVALID_HANDLE).doPost(generateSigningSample("otheruser")).andCheckFormat().run();
*/ }
@Test
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) @Test
void testGet_getForUser_success() { void testPost_currentUser_failure_badCreds() {
EndpointTestBuilder.from(GET_USER_SUCCESS).run(); EndpointTestBuilder.from(BAD_CREDS).doPost(generateSigningSample("fakeuser")).run();
} }
@Test /*
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) * GET FOR USER
void testGet_geFortUser_success_validateResponseFormat() { */
EndpointTestBuilder.from(GET_USER_SUCCESS).andCheckFormat().run(); @Test
} @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testGet_getForUser_success() {
@Test EndpointTestBuilder.from(GET_USER_SUCCESS).run();
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) }
void testGet_getForUser_success_validateSchema() {
EndpointTestBuilder.from(GET_USER_SUCCESS).andCheckSchema().run(); @Test
} @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testGet_geFortUser_success_validateResponseFormat() {
@Test EndpointTestBuilder.from(GET_USER_SUCCESS).andCheckFormat().run();
@TestSecurity(user = OTHERUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) }
void testGet_getForUser_failure_notFound() {
EndpointTestBuilder.from(GET_USER_NOT_FOUND).run(); @Test
} @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testGet_getForUser_success_validateSchema() {
@Test EndpointTestBuilder.from(GET_USER_SUCCESS).andCheckSchema().run();
@TestSecurity(user = OTHERUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) }
void testGet_getForUser_failure_notFound_validateResponseFormat() {
EndpointTestBuilder.from(GET_USER_NOT_FOUND).andCheckFormat().run(); @Test
} @TestSecurity(user = OTHERUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testGet_getForUser_failure_notFound() {
@Test EndpointTestBuilder.from(GET_USER_NOT_FOUND).run();
@TestSecurity(user = OTHERUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) }
void testGet_getForUser_failure_notFound_validateSchema() {
EndpointTestBuilder.from(GET_USER_NOT_FOUND).andCheckSchema().run(); @Test
} @TestSecurity(user = OTHERUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testGet_getForUser_failure_notFound_validateResponseFormat() {
@Test EndpointTestBuilder.from(GET_USER_NOT_FOUND).andCheckFormat().run();
void testGet_getForUser_failure_badCreds() { }
EndpointTestBuilder.from(FOR_USER_BAD_CREDS).run();
} @Test
@TestSecurity(user = OTHERUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
/* void testGet_getForUser_failure_notFound_validateSchema() {
* DELETE FOR USER EndpointTestBuilder.from(GET_USER_NOT_FOUND).andCheckSchema().run();
*/ }
@Test
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) @Test
void testDelete_deleteForUser_success() { void testGet_getForUser_failure_badCreds() {
EndpointTestBuilder.from(REVOKE_SUCCESS).doDelete(null).run(); EndpointTestBuilder.from(FOR_USER_BAD_CREDS).run();
} }
@Test @Test
@TestSecurity(user = FAKEUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) @TestSecurity(user = OTHERUSER_PROFILE, roles = "profile")
void testDelete_deleteForUser_failure_invalidUser() { void testGet_getForUser_failure_noValidRole() {
EndpointTestBuilder.from(REVOKE_INVALID_USER).doDelete(null).run(); EndpointTestBuilder.from(FOR_USER_BAD_ROLE).run();
} }
@Test /*
@TestSecurity(user = OTHERUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) * DELETE FOR USER
void testDelete_deleteForUser_failure_noDoc() { */
EndpointTestBuilder.from(REVOKE_NO_DOC).doDelete(null).run(); @Test
} @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testDelete_deleteForUser_success() {
@Test EndpointTestBuilder.from(REVOKE_SUCCESS).doDelete(null).run();
@TestSecurity(user = OTHERUSER_PROFILE, roles = AuthHelper.DEFAULT_ROLE) }
void testDelete_deleteForUser_failure_noDoc_validateSchema() {
EndpointTestBuilder.from(REVOKE_NO_DOC).doDelete(null).andCheckSchema().run(); @Test
} @TestSecurity(user = FAKEUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testDelete_deleteForUser_failure_invalidUser() {
@Test EndpointTestBuilder.from(REVOKE_INVALID_USER).doDelete(null).run();
void testDelete_deleteForUser_failure_badCreds() { }
EndpointTestBuilder.from(FOR_USER_BAD_CREDS).run();
} @Test
@TestSecurity(user = FAKEUSER_PROFILE, roles = "role")
private String generateSigningSample(String ghHandle) { void testDelete_deleteForUser_failure_invalidRole() {
try { EndpointTestBuilder.from(REVOKE_INVALID_ROLE).doDelete(null).run();
return mapper.writeValueAsString(new AgreementSigningRequest("1", ghHandle)); }
} catch (JsonProcessingException e) {
throw new RuntimeException(e); @Test
} @TestSecurity(user = OTHERUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testDelete_deleteForUser_failure_noDoc() {
EndpointTestBuilder.from(REVOKE_NO_DOC).doDelete(null).run();
}
@Test
@TestSecurity(user = OTHERUSER_PROFILE, roles = OpenVSXParameters.DEFAULT_ACCESS_ROLE)
void testDelete_deleteForUser_failure_noDoc_validateSchema() {
EndpointTestBuilder.from(REVOKE_NO_DOC).doDelete(null).andCheckSchema().run();
}
@Test
void testDelete_deleteForUser_failure_badCreds() {
EndpointTestBuilder.from(FOR_USER_BAD_CREDS).run();
}
private String generateSigningSample(String ghHandle) {
try {
return mapper.writeValueAsString(new AgreementSigningRequest("1", ghHandle));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
} }
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment