migrate from CAS to Oauth2-JWT Auth (#197)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/197 Reviewed-by: Marc Sandlus <marc.sandlus@hostsharing.net>
This commit is contained in:
co-authored by
Michael Hoennig
parent
bc06001ce9
commit
d7a78d0a79
@@ -384,6 +384,7 @@ public class ArchitectureTest {
|
||||
classes().that(belongToProductionClasses()
|
||||
.and(are(annotatedWith(RestController.class))))
|
||||
.should(havePreAuthorizeWithValue("isAuthenticated()"))
|
||||
.orShould().beAnnotatedWith(NoSecurityRequirement.class)
|
||||
.because("Every REST controller should require authentication by default, use @PreAuthorize(...) to override this at the endpoint method level.");
|
||||
|
||||
private static ArchCondition<JavaClass> havePreAuthorizeWithValue(String expectedValue) {
|
||||
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
package net.hostsharing.hsadminng.config;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import net.hostsharing.hsadminng.test.LogbackLogPattern;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.logging.LogLevel;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.get;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
||||
import static java.util.Map.entry;
|
||||
import static net.hostsharing.hsadminng.config.HttpHeadersBuilder.headers;
|
||||
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TestPropertySource(properties = {
|
||||
"server.port=0",
|
||||
"hsadminng.cas.server=http://localhost:8088",
|
||||
|
||||
"logging.level.root=DEBUG"
|
||||
})
|
||||
@ActiveProfiles({"wiremock", "realCasAuthenticator"}) // IMPORTANT: To test prod config, do NOT use test profile!
|
||||
@Tag("generalIntegrationTest")
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class CasAuthenticationFilterIntegrationTest {
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private int serverPort;
|
||||
|
||||
@Value("${hsadminng.cas.service}")
|
||||
private String serviceUrl;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
private WireMockServer wireMockServer;
|
||||
|
||||
@Test
|
||||
public void shouldAcceptRequestWithValidCasTicket(final CapturedOutput capturedOutput) {
|
||||
// given
|
||||
final var username = "test-user-" + randomAlphanumeric(4);
|
||||
wireMockServer.stubFor(get(urlEqualTo("/cas/p3/serviceValidate?service=" + serviceUrl + "&ticket=ST-valid"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(200)
|
||||
.withBody("""
|
||||
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
|
||||
<cas:authenticationSuccess>
|
||||
<cas:user>%{username}</cas:user>
|
||||
</cas:authenticationSuccess>
|
||||
</cas:serviceResponse>
|
||||
""".replace("%{username}", username)
|
||||
)));
|
||||
|
||||
// when
|
||||
final var result = restTemplate.exchange(
|
||||
"http://localhost:" + this.serverPort + "/api/pong",
|
||||
HttpMethod.GET,
|
||||
new HttpEntity<>(null, headers(entry("Authorization", "ST-valid"))),
|
||||
String.class
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).startsWith("ponged " + username);
|
||||
// HOWTO assert log messages
|
||||
assertThat(capturedOutput.getOut()).containsPattern(
|
||||
LogbackLogPattern.of(LogLevel.DEBUG, RealCasAuthenticator.class, "CAS-user: " + username));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectRequestWithInvalidCasTicket() {
|
||||
// given
|
||||
wireMockServer.stubFor(get(urlEqualTo("/cas/p3/serviceValidate?service=" + serviceUrl + "&ticket=invalid"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(200)
|
||||
.withBody("""
|
||||
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
|
||||
<cas:authenticationFailure code="INVALID_REQUEST"></cas:authenticationFailure>
|
||||
</cas:serviceResponse>
|
||||
""")));
|
||||
|
||||
// when
|
||||
final var result = restTemplate.exchange(
|
||||
"http://localhost:" + this.serverPort + "/api/ping",
|
||||
HttpMethod.GET,
|
||||
new HttpEntity<>(null, headers(entry("Authorization", "invalid"))),
|
||||
String.class
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
+3
-4
@@ -10,12 +10,11 @@ import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
|
||||
@Tag("generalIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Tag("generalIntegrationTest")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class CustomActuatorEndpointAcceptanceTest {
|
||||
|
||||
@LocalManagementPort
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package net.hostsharing.hsadminng.config;
|
||||
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
@TestConfiguration
|
||||
public class DisableSecurityConfig {
|
||||
|
||||
@Bean
|
||||
@Profile("test")
|
||||
public SecurityFilterChain securityFilterChain(final HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
|
||||
.csrf(AbstractHttpConfigurer::disable);
|
||||
return http.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Profile("test")
|
||||
public CasAuthenticator fakeAuthenticator() {
|
||||
return new FakeCasAuthenticator();
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package net.hostsharing.hsadminng.config;
|
||||
|
||||
import lombok.val;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static net.hostsharing.hsadminng.config.HttpHeadersBuilder.headers;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Tag("generalIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = HsadminNgApplication.class)
|
||||
@TestPropertySource(properties = {
|
||||
"server.port=0",
|
||||
"logging.level.root=DEBUG"
|
||||
})
|
||||
@ActiveProfiles("fake-jwt")
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class JwtAuthenticationFilterIntegrationTest {
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private int serverPort;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Test
|
||||
public void shouldAcceptRequestWithValidJwt() {
|
||||
// given
|
||||
val givenSubject = "some-subject";
|
||||
val bearer = bearer(givenSubject);
|
||||
|
||||
// when
|
||||
final var result = restTemplate.exchange(
|
||||
"http://localhost:" + this.serverPort + "/api/pong",
|
||||
HttpMethod.GET,
|
||||
new HttpEntity<>(null, headers(entry("Authorization", bearer))),
|
||||
String.class
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).startsWith("ponged " + givenSubject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectRequestWithInvalidJwt() {
|
||||
// given
|
||||
val givenInvalidBearer = "Bearer invalid";
|
||||
|
||||
// when
|
||||
final var result = restTemplate.exchange(
|
||||
"http://localhost:" + this.serverPort + "/api/pong",
|
||||
HttpMethod.GET,
|
||||
new HttpEntity<>(null, headers(entry("Authorization", givenInvalidBearer))),
|
||||
String.class
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
-6
@@ -7,11 +7,8 @@ import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -29,9 +26,6 @@ class MessageTranslatorIntegrationTest {
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
|
||||
@MockitoBean
|
||||
private Context contextMock; // avoiding dependency issues
|
||||
|
||||
@AllArgsConstructor
|
||||
enum TestCases {
|
||||
ENGLISH_KNOWN(Locale.ENGLISH, "test.ponged-{0}--in-your-language",
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.hostsharing.hsadminng.config;
|
||||
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
|
||||
@TestConfiguration
|
||||
// @EnableMethodSecurity breaks RestTests, endpoints won't be reachable anymore, all return 404
|
||||
// that's the reason why this class even exists in the first place
|
||||
@Profile("test")
|
||||
public class WebSecurityConfigForWebMvcTests extends BaseWebSecurityConfig {
|
||||
|
||||
}
|
||||
+34
-131
@@ -1,12 +1,9 @@
|
||||
package net.hostsharing.hsadminng.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import lombok.val;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -18,134 +15,57 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.get;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.post;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TestPropertySource(properties = {"management.port=0", "server.port=0", "hsadminng.cas.server=http://localhost:8088"})
|
||||
@ActiveProfiles({"wiremock", "realCasAuthenticator"}) // IMPORTANT: To test prod config, do NOT use test profile!
|
||||
@Tag("generalIntegrationTest")
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TestPropertySource(properties = { "management.port=0", "server.port=0" })
|
||||
@ActiveProfiles("fake-jwt") // IMPORTANT: In this test, want to test the prod config, do NOT use test profile!
|
||||
class WebSecurityConfigIntegrationTest {
|
||||
|
||||
public static final String GIVEN_FAKE_SUBJECT = "fake-user-name";
|
||||
@Value("${local.server.port}")
|
||||
private int serverPort;
|
||||
|
||||
@Value("${local.management.port}")
|
||||
private int managementPort;
|
||||
|
||||
@Value("${hsadminng.cas.service}")
|
||||
private String serviceUrl;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
private WireMockServer wireMockServer;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
wireMockServer.stubFor(get(anyUrl())
|
||||
.willReturn(aResponse()
|
||||
.withStatus(200)
|
||||
.withBody("""
|
||||
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
|
||||
<cas:authenticationFailure/>
|
||||
</cas:serviceResponse>
|
||||
""")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessToApiWithValidServiceTicketSouldBePermitted() {
|
||||
// given
|
||||
givenCasTicketValidationResponse("ST-fake-cas-ticket", "fake-user-name");
|
||||
|
||||
// http request
|
||||
final var result = restTemplate.exchange(
|
||||
"http://localhost:" + this.serverPort + "/api/pong",
|
||||
HttpMethod.GET,
|
||||
httpHeaders(entry("Authorization", "Bearer ST-fake-cas-ticket")),
|
||||
String.class
|
||||
);
|
||||
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).startsWith("ponged fake-user-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessToApiWithValidTicketGrantingTicketShouldBePermitted() {
|
||||
// given
|
||||
givenCasServiceTicketForTicketGrantingTicket("TGT-fake-cas-ticket", "ST-fake-cas-ticket");
|
||||
givenCasTicketValidationResponse("ST-fake-cas-ticket", "fake-user-name");
|
||||
|
||||
// http request
|
||||
final var result = restTemplate.exchange(
|
||||
"http://localhost:" + this.serverPort + "/api/pong",
|
||||
HttpMethod.GET,
|
||||
httpHeaders(entry("Authorization", "Bearer TGT-fake-cas-ticket")),
|
||||
String.class
|
||||
);
|
||||
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).startsWith("ponged fake-user-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessToOpenApiWithInvalidTicketGrantingTicketShouldBePermitted() {
|
||||
// given
|
||||
givenCasServiceTicketForTicketGrantingTicket("TGT-fake-cas-ticket", "ST-fake-cas-ticket");
|
||||
givenCasTicketValidationResponse("ST-fake-cas-ticket", "fake-user-name");
|
||||
|
||||
// http request
|
||||
final var result = restTemplate.exchange(
|
||||
"http://localhost:" + this.serverPort + "/api/ping",
|
||||
HttpMethod.GET,
|
||||
httpHeaders(entry("Authorization", "Bearer TGT-WRONG-cas-ticket")),
|
||||
String.class
|
||||
);
|
||||
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessToOpenApiWithoutTokenShouldBePermitted() {
|
||||
final var result = this.restTemplate.getForEntity(
|
||||
"http://localhost:" + this.serverPort + "/api/ping", String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessToProtectedApiWithValidTokenShouldBePermitted() {
|
||||
// given
|
||||
givenCasTicketValidationResponse("ST-fake-cas-ticket", "fake-user-name");
|
||||
|
||||
void accessToApiWithValidJwtShouldBePermitted() {
|
||||
// when
|
||||
final var result = restTemplate.exchange(
|
||||
"http://localhost:" + this.serverPort + "/api/pong",
|
||||
val result = restTemplate.exchange(
|
||||
serverUrl("/api/pong"),
|
||||
HttpMethod.GET,
|
||||
httpHeaders(entry("Authorization", "Bearer ST-fake-cas-ticket")),
|
||||
httpHeaders(entry("Authorization", bearer(GIVEN_FAKE_SUBJECT))),
|
||||
String.class
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).startsWith("ponged " + GIVEN_FAKE_SUBJECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessToOpenApiWithoutTokenShouldBePermitted() {
|
||||
val result = this.restTemplate.getForEntity(
|
||||
serverUrl("/api/ping"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessToProtectedApiWithInvalidTokenShouldBeDenied() {
|
||||
// given
|
||||
givenCasTicketValidationResponse("ST-fake-cas-ticket", "fake-user-name");
|
||||
|
||||
// when
|
||||
final var result = restTemplate.exchange(
|
||||
"http://localhost:" + this.serverPort + "/api/pong",
|
||||
val result = restTemplate.exchange(
|
||||
serverUrl("/api/pong"),
|
||||
HttpMethod.GET,
|
||||
httpHeaders(entry("Authorization", "Bearer ST-WRONG-cas-ticket")),
|
||||
httpHeaders(entry("Authorization", "Bearer INVALID-JWT")),
|
||||
String.class
|
||||
);
|
||||
|
||||
@@ -155,59 +75,42 @@ class WebSecurityConfigIntegrationTest {
|
||||
|
||||
@Test
|
||||
void accessToActuatorShouldBePermitted() {
|
||||
final var result = this.restTemplate.getForEntity(
|
||||
val result = this.restTemplate.getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/actuator", Map.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessToSwaggerUiShouldBePermitted() {
|
||||
final var result = this.restTemplate.getForEntity(
|
||||
"http://localhost:" + this.serverPort + "/swagger-ui/index.html", String.class);
|
||||
val result = this.restTemplate.getForEntity(
|
||||
serverUrl("/swagger-ui/index.html"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessToApiDocsEndpointShouldBePermitted() {
|
||||
final var result = this.restTemplate.getForEntity(
|
||||
"http://localhost:" + this.serverPort + "/v3/api-docs/swagger-config", String.class);
|
||||
val result = this.restTemplate.getForEntity(
|
||||
serverUrl("/v3/api-docs/swagger-config"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).contains("\"configUrl\":\"/v3/api-docs/swagger-config\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessToActuatorEndpointShouldBePermitted() {
|
||||
final var result = this.restTemplate.getForEntity(
|
||||
val result = this.restTemplate.getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/actuator/health", Map.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody().get("status")).isEqualTo("UP");
|
||||
}
|
||||
|
||||
private void givenCasServiceTicketForTicketGrantingTicket(final String ticketGrantingTicket, final String serviceTicket) {
|
||||
wireMockServer.stubFor(post(urlEqualTo("/cas/v1/tickets/" + ticketGrantingTicket))
|
||||
.withFormParam("service", equalTo(serviceUrl))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(201)
|
||||
.withBody(serviceTicket)));
|
||||
}
|
||||
|
||||
private void givenCasTicketValidationResponse(final String casToken, final String userName) {
|
||||
wireMockServer.stubFor(get(urlEqualTo("/cas/p3/serviceValidate?service=" + serviceUrl + "&ticket=" + casToken))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(200)
|
||||
.withBody("""
|
||||
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
|
||||
<cas:authenticationSuccess>
|
||||
<cas:user>${userName}</cas:user>
|
||||
</cas:authenticationSuccess>
|
||||
</cas:serviceResponse>
|
||||
""".replace("${userName}", userName))));
|
||||
private @NotNull String serverUrl(final String path) {
|
||||
return "http://localhost:" + this.serverPort + path;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private HttpEntity<?> httpHeaders(final Map.Entry<String, String>... headerValues) {
|
||||
final var headers = new HttpHeaders();
|
||||
for ( Map.Entry<String, String> headerValue: headerValues ) {
|
||||
val headers = new HttpHeaders();
|
||||
for (Map.Entry<String, String> headerValue : headerValues) {
|
||||
headers.add(headerValue.getKey(), headerValue.getValue());
|
||||
}
|
||||
return new HttpEntity<>(headers);
|
||||
|
||||
+7
-5
@@ -1,9 +1,8 @@
|
||||
package net.hostsharing.hsadminng.errors;
|
||||
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
@@ -21,9 +20,12 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(controllers = RestResponseEntityExceptionHandlerRestTest.TestController.class)
|
||||
@Import({JsonObjectMapperConfiguration.class, MessageTranslator.class, DisableSecurityConfig.class, RestResponseEntityExceptionHandler.class, RestResponseEntityExceptionHandlerRestTest.TestConfig.class})
|
||||
@Tag("generalIntegrationTest")
|
||||
@ActiveProfiles("test")
|
||||
@Import({ JsonObjectMapperConfiguration.class,
|
||||
MessageTranslator.class,
|
||||
RestResponseEntityExceptionHandler.class,
|
||||
RestResponseEntityExceptionHandlerRestTest.TestConfig.class,
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class RestResponseEntityExceptionHandlerRestTest {
|
||||
|
||||
@TestConfiguration
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.accounts;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.accounts;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
|
||||
+12
-7
@@ -1,6 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.accounts;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -13,12 +14,13 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -37,8 +39,11 @@ import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.SynchronizationType;
|
||||
|
||||
@WebMvcTest(HsCredentialsContextsController.class)
|
||||
@Import({ StrictMapper.class, JsonObjectMapperConfiguration.class, DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
@Import({ StrictMapper.class,
|
||||
MessageTranslator.class,
|
||||
JsonObjectMapperConfiguration.class,
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class HsCredentialsContextsControllerRestTest {
|
||||
|
||||
@Autowired
|
||||
@@ -85,7 +90,7 @@ class HsCredentialsContextsControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/accounts/contexts")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
|
||||
@@ -105,7 +110,7 @@ class HsCredentialsContextsControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/accounts/contexts")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("Bearer superuser-alex@hostsharing.net"))
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
|
||||
@@ -147,7 +152,7 @@ class HsCredentialsContextsControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/accounts/contexts")
|
||||
.header("Authorization", "Bearer drew@hostsharing.org")
|
||||
.header("Authorization", bearer("drew@hostsharing.org"))
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
|
||||
|
||||
+14
-16
@@ -3,9 +3,7 @@ package net.hostsharing.hsadminng.hs.accounts;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import lombok.val;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.accounts.HsCredentialsEntity.HsCredentialsEntityBuilder;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||
@@ -31,6 +29,7 @@ import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.LEGAL_PERSON;
|
||||
import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.NATURAL_PERSON;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
@@ -41,18 +40,17 @@ import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
@Tag("generalIntegrationTest")
|
||||
@Transactional
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Tag("generalIntegrationTest")
|
||||
@ActiveProfiles("fake-jwt")
|
||||
// too complex database interaction for just a RestTest, thus a fully integrated test
|
||||
class HsCredentialsControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@LocalServerPort
|
||||
private Integer port;
|
||||
Integer port;
|
||||
|
||||
@Autowired
|
||||
Context context;
|
||||
@@ -93,7 +91,7 @@ class HsCredentialsControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/accounts/current")
|
||||
@@ -120,7 +118,7 @@ class HsCredentialsControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer " + credentialsEntity.getSubject().getName())
|
||||
.header("Authorization", bearer(credentialsEntity.getSubject().getName()))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/accounts/credentials/" + credentialsEntity.getUuid())
|
||||
@@ -188,7 +186,7 @@ class HsCredentialsControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -228,7 +226,7 @@ class HsCredentialsControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -268,7 +266,7 @@ class HsCredentialsControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -314,7 +312,7 @@ class HsCredentialsControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -350,7 +348,7 @@ class HsCredentialsControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -388,7 +386,7 @@ class HsCredentialsControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.post("http://localhost/api/hs/accounts/credentials/" + credentialsEntity.getUuid() + "/used")
|
||||
|
||||
+1
-2
@@ -1,9 +1,8 @@
|
||||
package net.hostsharing.hsadminng.hs.accounts;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||
|
||||
+9
-31
@@ -1,43 +1,19 @@
|
||||
package net.hostsharing.hsadminng.hs.accounts.scenarios;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.hs.scenarios.Produces;
|
||||
import net.hostsharing.hsadminng.hs.scenarios.Requires;
|
||||
import net.hostsharing.hsadminng.hs.scenarios.ScenarioTest;
|
||||
import net.hostsharing.hsadminng.mapper.Array;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.test.IgnoreOnFailureExtension;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.ClassOrderer;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestClassOrder;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
@Tag("scenarioTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class },
|
||||
properties = {
|
||||
"spring.datasource.url=${HSADMINNG_POSTGRES_JDBC_URL:jdbc:tc:postgresql:15.5-bookworm:///scenariosTC}",
|
||||
"spring.datasource.username=${HSADMINNG_POSTGRES_ADMIN_USERNAME:ADMIN}",
|
||||
"spring.datasource.password=${HSADMINNG_POSTGRES_ADMIN_PASSWORD:password}",
|
||||
"hsadminng.superuser=${HSADMINNG_SUPERUSER:superuser-alex@hostsharing.net}"
|
||||
}
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@TestClassOrder(ClassOrderer.OrderAnnotation.class)
|
||||
@ExtendWith(IgnoreOnFailureExtension.class)
|
||||
class CredentialsScenarioTests extends ScenarioTest {
|
||||
|
||||
@SneakyThrows
|
||||
@@ -105,9 +81,10 @@ class CredentialsScenarioTests extends ScenarioTest {
|
||||
.given("smsNumber", "+49123456789")
|
||||
.given("globalUid", 21011)
|
||||
.given("globalGid", 21011)
|
||||
.given("contexts", Array.of(
|
||||
Pair.of("HSADMIN", "prod")
|
||||
))
|
||||
.given(
|
||||
"contexts", Array.of(
|
||||
Pair.of("HSADMIN", "prod")
|
||||
))
|
||||
.given("onboardingToken", "fake-unboarding-token")
|
||||
.doRun()
|
||||
.keep();
|
||||
@@ -126,10 +103,11 @@ class CredentialsScenarioTests extends ScenarioTest {
|
||||
.given("emailAddress", "susan.firby@example.org")
|
||||
.given("phonePassword", "securePass987")
|
||||
.given("smsNumber", "+49987654321")
|
||||
.given("contexts", Array.of(
|
||||
Pair.of("HSADMIN", "prod"),
|
||||
Pair.of("SSH", "internal")
|
||||
))
|
||||
.given(
|
||||
"contexts", Array.of(
|
||||
Pair.of("HSADMIN", "prod"),
|
||||
Pair.of("SSH", "internal")
|
||||
))
|
||||
.doRun();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.hostsharing.hsadminng.hs.scenarios.UseCase;
|
||||
|
||||
|
||||
import static io.restassured.http.ContentType.JSON;
|
||||
import static net.hostsharing.hsadminng.hs.scenarios.ScenarioTest.bearerTemplate;
|
||||
import static net.hostsharing.hsadminng.hs.scenarios.ScenarioTest.resolve;
|
||||
import static net.hostsharing.hsadminng.hs.scenarios.TemplateResolver.Resolver.DROP_COMMENTS;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -33,7 +34,7 @@ public class CurrentLoginUser extends UseCase<CurrentLoginUser> {
|
||||
"Current Login User", () ->
|
||||
httpGet(
|
||||
"/api/hs/accounts/current", req -> req
|
||||
.header("Authorization", resolve("Bearer %{subjectName}", DROP_COMMENTS))
|
||||
.header("Authorization", bearerTemplate("%{subjectName}"))
|
||||
)
|
||||
.expecting(OK).expecting(JSON).expectObject()
|
||||
.extractValue("subject.name", "returnedSubjectName")
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.hostsharing.hsadminng.hs.scenarios.UseCase;
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.http.ContentType.JSON;
|
||||
import static net.hostsharing.hsadminng.hs.scenarios.ScenarioTest.bearerTemplate;
|
||||
import static net.hostsharing.hsadminng.hs.scenarios.ScenarioTest.resolve;
|
||||
import static net.hostsharing.hsadminng.hs.scenarios.ScenarioTest.resolveJsonArray;
|
||||
import static net.hostsharing.hsadminng.hs.scenarios.TemplateResolver.Resolver.DROP_COMMENTS;
|
||||
@@ -27,7 +28,7 @@ public class FetchRbacContext extends UseCase<FetchRbacContext> {
|
||||
"RBAC Context", () ->
|
||||
httpGet(
|
||||
"/api/rbac/context", req -> req
|
||||
.header("Authorization", resolve("Bearer %{subjectName}", DROP_COMMENTS))
|
||||
.header("Authorization", bearerTemplate("%{subjectName}"))
|
||||
.header("assumed-roles", resolve("%{assumedRoles}", DROP_COMMENTS))
|
||||
)
|
||||
.expecting(OK).expecting(JSON).expectObject()
|
||||
|
||||
+16
-17
@@ -12,7 +12,6 @@ import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.hosting.asset.validators.Dns;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.ClassOrderer;
|
||||
@@ -36,6 +35,7 @@ import java.util.UUID;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.MANAGED_WEBSPACE;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.UNIX_USER;
|
||||
@@ -43,14 +43,13 @@ import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.matchesRegex;
|
||||
|
||||
@Tag("bookingIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class}
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
@TestClassOrder(ClassOrderer.OrderAnnotation.class) // fail early on fetching problems
|
||||
@Tag("bookingIntegrationTest")
|
||||
@Transactional
|
||||
class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -87,7 +86,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/booking/items?projectUuid=" + givenProject.getUuid())
|
||||
@@ -151,7 +150,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -201,7 +200,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -271,7 +270,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -361,7 +360,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -454,7 +453,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/booking/items/" + givenBookingItemUuid)
|
||||
@@ -488,7 +487,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/booking/items/" + givenBookingItemUuid)
|
||||
@@ -506,7 +505,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "hs_booking.project#D-1000313-D-1000313defaultproject:ADMIN")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -550,7 +549,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -605,7 +604,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/booking/items/" + givenBookingItem.getUuid())
|
||||
@@ -624,7 +623,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/booking/items/" + givenBookingItem.getUuid())
|
||||
|
||||
+12
-9
@@ -3,25 +3,25 @@ package net.hostsharing.hsadminng.hs.booking.item;
|
||||
import io.hypersistence.utils.hibernate.type.range.Range;
|
||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import net.hostsharing.hsadminng.hs.booking.generated.api.v1.model.HsBookingItemInsertResource;
|
||||
import net.hostsharing.hsadminng.hs.booking.generated.api.v1.model.HsBookingItemResource;
|
||||
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealRepository;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
@@ -32,20 +32,24 @@ import java.time.LocalDate;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.matchesRegex;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsBookingItemController.class)
|
||||
@Import({StrictMapper.class, JsonObjectMapperConfiguration.class, DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
@Import({StrictMapper.class,
|
||||
JsonObjectMapperConfiguration.class,
|
||||
MessageTranslator.class,
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class HsBookingItemControllerRestTest {
|
||||
|
||||
@Autowired
|
||||
@@ -77,7 +81,6 @@ class HsBookingItemControllerRestTest {
|
||||
public EntityManager entityManager() {
|
||||
return mock(EntityManager.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
@@ -107,7 +110,7 @@ class HsBookingItemControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/booking/items")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
@@ -158,7 +161,7 @@ class HsBookingItemControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/booking/items")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.booking.item;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.range.Range;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||
|
||||
+12
-13
@@ -6,7 +6,6 @@ import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -20,17 +19,17 @@ import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.matchesRegex;
|
||||
|
||||
@Tag("bookingIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
classes = HsadminNgApplication.class)
|
||||
@Transactional
|
||||
@Tag("bookingIntegrationTest")
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -62,7 +61,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/booking/projects?debitorUuid=" + givenDebitor.getUuid())
|
||||
@@ -93,7 +92,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -133,7 +132,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/booking/projects/" + givenBookingProjectUuid)
|
||||
@@ -156,7 +155,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/booking/projects/" + givenBookingProjectUuid)
|
||||
@@ -172,7 +171,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer person-TuckerJack@example.com")
|
||||
.header("Authorization", bearer("person-TuckerJack@example.com"))
|
||||
.header("assumed-roles", "hs_booking.project#D-1000313-D-1000313defaultproject:AGENT")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -198,7 +197,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -237,7 +236,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/booking/projects/" + givenBookingProject.getUuid())
|
||||
@@ -255,7 +254,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/booking/projects/" + givenBookingProject.getUuid())
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.booking.project;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorRepository;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.role.RawRbacRoleRepository;
|
||||
|
||||
+117
-115
@@ -14,7 +14,6 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.ClassOrderer;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@@ -34,6 +33,7 @@ import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.EMAIL_ALIAS;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE;
|
||||
@@ -43,14 +43,13 @@ import static net.hostsharing.hsadminng.test.JsonMatcher.strictlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.matchesRegex;
|
||||
|
||||
@Tag("hostingIntegrationTest")
|
||||
@Transactional
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
@TestClassOrder(ClassOrderer.OrderAnnotation.class) // fail early on fetching problems
|
||||
@Tag("hostingIntegrationTest")
|
||||
class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -89,12 +88,12 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.findAny().orElseThrow();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.given()
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.when()
|
||||
.get("http://localhost/api/hs/hosting/assets?projectUuid=" + givenProject.getUuid() + "&type=MANAGED_WEBSPACE")
|
||||
.then().log().all().assertThat()
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", lenientlyEquals("""
|
||||
@@ -107,7 +106,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}
|
||||
]
|
||||
"""));
|
||||
// @formatter:on
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,15 +117,15 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("assumed-roles", "hs_hosting.asset#fir01:AGENT")
|
||||
.port(port)
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "hs_hosting.asset#fir01:AGENT")
|
||||
.port(port)
|
||||
.when()
|
||||
. get("http://localhost/api/hs/hosting/assets?type=" + EMAIL_ALIAS)
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", lenientlyEquals("""
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", lenientlyEquals("""
|
||||
[
|
||||
{
|
||||
"type": "EMAIL_ALIAS",
|
||||
@@ -154,7 +153,8 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
void globalAdmin_canAddBookedAsset() {
|
||||
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenBookingItem = newBookingItem("D-1000111 default project",
|
||||
final var givenBookingItem = newBookingItem(
|
||||
"D-1000111 default project",
|
||||
HsBookingItemType.MANAGED_WEBSPACE, "separate ManagedWebspace BI",
|
||||
Map.ofEntries(
|
||||
entry("SSD", 50),
|
||||
@@ -166,9 +166,9 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"bookingItem.uuid": "%s",
|
||||
"type": "MANAGED_WEBSPACE",
|
||||
@@ -178,13 +178,13 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
"config": {}
|
||||
}
|
||||
""".formatted(givenBookingItem.getUuid(), givenParentAsset.getUuid()))
|
||||
.port(port)
|
||||
.port(port)
|
||||
.when()
|
||||
.post("http://localhost/api/hs/hosting/assets")
|
||||
.post("http://localhost/api/hs/hosting/assets")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(201)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
.statusCode(201)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"type": "MANAGED_WEBSPACE",
|
||||
"identifier": "fir10",
|
||||
@@ -194,9 +194,9 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}
|
||||
}
|
||||
"""
|
||||
.replace("{lastUnixUserId}", expectedUnixUserId.toString())
|
||||
))
|
||||
.header("Location", matchesRegex("http://localhost:[1-9][0-9]*/api/hs/hosting/assets/[^/]*"))
|
||||
.replace("{lastUnixUserId}", expectedUnixUserId.toString())
|
||||
))
|
||||
.header("Location", matchesRegex("http://localhost:[1-9][0-9]*/api/hs/hosting/assets/[^/]*"))
|
||||
.extract().header("Location"); // @formatter:on
|
||||
|
||||
// the new asset can be accessed under the generated UUID
|
||||
@@ -206,7 +206,8 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
toCleanup(HsHostingAssetRbacEntity.class, newWebspaceUuid);
|
||||
|
||||
// and a default user got created
|
||||
final var webspaceUnixUser = em.createQuery("SELECT ha FROM HsHostingAssetRealEntity ha WHERE ha.parentAsset.uuid=:webspaceUUID")
|
||||
final var webspaceUnixUser = em.createQuery(
|
||||
"SELECT ha FROM HsHostingAssetRealEntity ha WHERE ha.parentAsset.uuid=:webspaceUUID")
|
||||
.setParameter("webspaceUUID", newWebspaceUuid)
|
||||
.getSingleResult();
|
||||
assertThat(webspaceUnixUser).isNotNull().extracting(Object::toString)
|
||||
@@ -227,10 +228,10 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("assumed-roles", "hs_hosting.asset#vm1011:ADMIN")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "hs_hosting.asset#vm1011:ADMIN")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"parentAsset.uuid": "%s",
|
||||
"type": "UNIX_USER",
|
||||
@@ -239,13 +240,13 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
"config": {}
|
||||
}
|
||||
""".formatted(givenParentAsset.getUuid()))
|
||||
.port(port)
|
||||
.port(port)
|
||||
.when()
|
||||
.post("http://localhost/api/hs/hosting/assets")
|
||||
.post("http://localhost/api/hs/hosting/assets")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(201)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
.statusCode(201)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"type": "UNIX_USER",
|
||||
"identifier": "fir01-temp",
|
||||
@@ -253,7 +254,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
"config": {}
|
||||
}
|
||||
"""))
|
||||
.header("Location", matchesRegex("http://localhost:[1-9][0-9]*/api/hs/hosting/assets/[^/]*"))
|
||||
.header("Location", matchesRegex("http://localhost:[1-9][0-9]*/api/hs/hosting/assets/[^/]*"))
|
||||
.extract().header("Location"); // @formatter:on
|
||||
|
||||
// finally, the new asset can be accessed under the generated UUID
|
||||
@@ -270,18 +271,18 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
final var givenProject = realProjectRepo.findByCaption("D-1000111 default project").stream()
|
||||
.findAny().orElseThrow();
|
||||
final var bookingItem = givenSomeTemporaryBookingItem(() ->
|
||||
HsBookingItemRealEntity.builder()
|
||||
.project(givenProject)
|
||||
.type(HsBookingItemType.DOMAIN_SETUP)
|
||||
.caption("some temp domain setup booking item")
|
||||
.resources(Map.ofEntries(
|
||||
entry("domainName", "example.com")))
|
||||
.build()
|
||||
HsBookingItemRealEntity.builder()
|
||||
.project(givenProject)
|
||||
.type(HsBookingItemType.DOMAIN_SETUP)
|
||||
.caption("some temp domain setup booking item")
|
||||
.resources(Map.ofEntries(
|
||||
entry("domainName", "example.com")))
|
||||
.build()
|
||||
);
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -327,9 +328,9 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"bookingItem.uuid": "%s",
|
||||
"type": "MANAGED_SERVER",
|
||||
@@ -338,13 +339,13 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
"config": { "monit_max_ssd_usage": 0, "monit_max_cpu_usage": 101, "extra": 42 }
|
||||
}
|
||||
""".formatted(givenBookingItem.getUuid()))
|
||||
.port(port)
|
||||
.port(port)
|
||||
.when()
|
||||
.post("http://localhost/api/hs/hosting/assets")
|
||||
.post("http://localhost/api/hs/hosting/assets")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(400)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
.statusCode(400)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"statusPhrase": "Bad Request",
|
||||
"message": "ERROR: [400] [
|
||||
@@ -364,12 +365,13 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
assertThat(givenHostingAsset.getBookingItem().getResources().get("Multi"))
|
||||
.as("precondition failed")
|
||||
.isEqualTo(1);
|
||||
final var preExistingUnixUserCount = realAssetRepo.findAllByCriteria(null, givenHostingAsset.getUuid(), UNIX_USER).size();
|
||||
final var preExistingUnixUserCount = realAssetRepo.findAllByCriteria(null, givenHostingAsset.getUuid(), UNIX_USER)
|
||||
.size();
|
||||
final var UNIX_USER_PER_MULTI_OPTION = 25;
|
||||
|
||||
jpaAttempt.transacted(() -> {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
for (int n = 0; n < UNIX_USER_PER_MULTI_OPTION-preExistingUnixUserCount; ++n) {
|
||||
for (int n = 0; n < UNIX_USER_PER_MULTI_OPTION - preExistingUnixUserCount; ++n) {
|
||||
toCleanup(realAssetRepo.save(
|
||||
HsHostingAssetRealEntity.builder()
|
||||
.type(UNIX_USER)
|
||||
@@ -382,9 +384,9 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"parentAsset.uuid": "%s",
|
||||
"type": "UNIX_USER",
|
||||
@@ -393,13 +395,13 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
"config": { }
|
||||
}
|
||||
""".formatted(givenHostingAsset.getUuid()))
|
||||
.port(port)
|
||||
.port(port)
|
||||
.when()
|
||||
.post("http://localhost/api/hs/hosting/assets")
|
||||
.post("http://localhost/api/hs/hosting/assets")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(400)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
.statusCode(400)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"statusPhrase": "Bad Request",
|
||||
"message": "ERROR: [400] ['D-1000111:D-1000111 default project:separate ManagedWebspace.resources.Multi=1 allows at maximum 25 unix users, but 26 found]"
|
||||
@@ -420,12 +422,12 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.findAny().orElseThrow().getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.given()
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.when()
|
||||
.get("http://localhost/api/hs/hosting/assets/" + givenAssetUuid)
|
||||
.then().log().all().assertThat()
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", lenientlyEquals("""
|
||||
@@ -445,12 +447,12 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.findAny().orElseThrow();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.given()
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.when()
|
||||
.get("http://localhost/api/hs/hosting/assets/" + givenAssetUuid)
|
||||
.then().log().body().assertThat()
|
||||
.then().log().body().assertThat()
|
||||
.statusCode(404); // @formatter:on
|
||||
}
|
||||
|
||||
@@ -462,13 +464,13 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.findAny().orElseThrow().getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer person-TuckerJack@example.com")
|
||||
.given()
|
||||
.header("Authorization", bearer("person-TuckerJack@example.com"))
|
||||
.header("assumed-roles", "hs_booking.project#D-1000313-D-1000313defaultproject:AGENT")
|
||||
.port(port)
|
||||
.when()
|
||||
.when()
|
||||
.get("http://localhost/api/hs/hosting/assets/" + givenAssetUuid)
|
||||
.then().log().all().assertThat()
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", lenientlyEquals("""
|
||||
@@ -507,8 +509,8 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
final var alarmContactUuid = givenContact().getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.given()
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -521,9 +523,9 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}
|
||||
""".formatted(alarmContactUuid))
|
||||
.port(port)
|
||||
.when()
|
||||
.when()
|
||||
.patch("http://localhost/api/hs/hosting/assets/" + givenAsset.getUuid())
|
||||
.then().log().all().assertThat()
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
@@ -545,7 +547,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}
|
||||
}
|
||||
"""));
|
||||
// @formatter:on
|
||||
// @formatter:on
|
||||
|
||||
// finally, the asset is actually updated
|
||||
em.clear();
|
||||
@@ -556,13 +558,13 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.isEqualTo("contact-admin@secondcontact.example.com");
|
||||
assertThat(asset.getConfig().toString())
|
||||
.isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
"monit_max_cpu_usage": 90,
|
||||
"monit_max_ram_usage": 70,
|
||||
"monit_max_ssd_usage": 85,
|
||||
"monit_min_free_ssd": 5
|
||||
}
|
||||
""");
|
||||
{
|
||||
"monit_max_cpu_usage": 90,
|
||||
"monit_max_ram_usage": 70,
|
||||
"monit_max_ssd_usage": 85,
|
||||
"monit_min_free_ssd": 5
|
||||
}
|
||||
""");
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@@ -581,10 +583,10 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
//.header("assumed-roles", "hs_hosting.asset#vm2001:ADMIN")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
//.header("assumed-roles", "hs_hosting.asset#vm2001:ADMIN")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"caption" : "some patched test-unix-user",
|
||||
"config": {
|
||||
@@ -594,13 +596,13 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}
|
||||
}
|
||||
""")
|
||||
.port(port)
|
||||
.port(port)
|
||||
.when()
|
||||
.patch("http://localhost/api/hs/hosting/assets/" + givenAsset.getUuid())
|
||||
.patch("http://localhost/api/hs/hosting/assets/" + givenAsset.getUuid())
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
.statusCode(200)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"type": "UNIX_USER",
|
||||
"identifier": "fir01-temp",
|
||||
@@ -628,12 +630,12 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
.matches(asset -> {
|
||||
assertThat(asset.getCaption()).isEqualTo("some patched test-unix-user");
|
||||
assertThat(asset.getConfig().toString()).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
"password": "$6$Jr5w/Y8zo8pCkqg7$/rePRbvey3R6Sz/02YTlTQcRt5qdBPTj2h5.hz.rB8NfIoND8pFOjeB7orYcPs9JNf3JDxPP2V.6MQlE5BwAY/",
|
||||
"shell": "/bin/bash",
|
||||
"totpKey": "0x1234567890abcdef0123456789abcdef"
|
||||
}
|
||||
""");
|
||||
{
|
||||
"password": "$6$Jr5w/Y8zo8pCkqg7$/rePRbvey3R6Sz/02YTlTQcRt5qdBPTj2h5.hz.rB8NfIoND8pFOjeB7orYcPs9JNf3JDxPP2V.6MQlE5BwAY/",
|
||||
"shell": "/bin/bash",
|
||||
"totpKey": "0x1234567890abcdef0123456789abcdef"
|
||||
}
|
||||
""");
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@@ -663,12 +665,12 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
))
|
||||
.build());
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.given()
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/hosting/assets/" + givenAsset.getUuid())
|
||||
.then().log().body().assertThat()
|
||||
.then().log().body().assertThat()
|
||||
.statusCode(204); // @formatter:on
|
||||
|
||||
// then the given assets is gone
|
||||
@@ -695,12 +697,12 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
))
|
||||
.build());
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.given()
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/hosting/assets/" + givenAsset.getUuid())
|
||||
.then().log().all().assertThat()
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(404); // @formatter:on
|
||||
|
||||
// then the given asset is still there
|
||||
@@ -739,7 +741,8 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var project = realProjectRepo.findByCaption(projectCaption).getFirst();
|
||||
final var resources = switch (bookingItemType) {
|
||||
case MANAGED_SERVER -> Map.<String, Object>ofEntries(entry("CPU", 1),
|
||||
case MANAGED_SERVER -> Map.<String, Object>ofEntries(
|
||||
entry("CPU", 1),
|
||||
entry("RAM", 20),
|
||||
entry("SSD", 25),
|
||||
entry("Traffic", 250));
|
||||
@@ -783,9 +786,8 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}).returnedValue();
|
||||
}
|
||||
|
||||
|
||||
private Integer nextUnixUserId() {
|
||||
final Object result = em.createNativeQuery("SELECT nextval('hs_hosting.asset_unixuser_system_id_seq')", Integer.class)
|
||||
final Object result = em.createNativeQuery("select nextval('hs_hosting.asset_unixuser_system_id_seq')", Integer.class)
|
||||
.getSingleResult();
|
||||
return (Integer) result + 1;
|
||||
}
|
||||
|
||||
+11
-7
@@ -7,12 +7,12 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import lombok.SneakyThrows;
|
||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRealRepository;
|
||||
import net.hostsharing.hsadminng.mapper.Array;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -38,6 +38,7 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.CLOUD_SERVER_BOOKING_ITEM_REAL_ENTITY;
|
||||
import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.MANAGED_SERVER_BOOKING_ITEM_REAL_ENTITY;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY;
|
||||
@@ -49,13 +50,16 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsHostingAssetController.class)
|
||||
@Import({ StrictMapper.class, JsonObjectMapperConfiguration.class, DisableSecurityConfig.class, MessageTranslator.class })
|
||||
@ActiveProfiles("test")
|
||||
@Import({ StrictMapper.class,
|
||||
JsonObjectMapperConfiguration.class,
|
||||
MessageTranslator.class,
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
public class HsHostingAssetControllerRestTest {
|
||||
|
||||
@Autowired
|
||||
@@ -592,7 +596,7 @@ public class HsHostingAssetControllerRestTest {
|
||||
// when
|
||||
final var result = mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/hosting/assets?type="+testCase.name())
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
@@ -662,7 +666,7 @@ public class HsHostingAssetControllerRestTest {
|
||||
// when
|
||||
final var result = mockMvc.perform(MockMvcRequestBuilders
|
||||
.patch("/api/hs/hosting/assets/" + givenDomainHttpSetupUuid)
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
|
||||
+3
-6
@@ -2,8 +2,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -12,12 +10,11 @@ import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
|
||||
@Tag("hostingIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Tag("hostingIntegrationTest")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class HsHostingAssetPropsControllerAcceptanceTest {
|
||||
|
||||
@LocalServerPort
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ class DomainSetupHostingAssetFactoryUnitTest {
|
||||
private EntityManagerWrapper emw = emwFake;
|
||||
|
||||
@Spy
|
||||
private ObjectMapper jsonMapper = new JsonObjectMapperConfiguration().customObjectMapper().build();
|
||||
private ObjectMapper jsonMapper = new JsonObjectMapperConfiguration().customObjectMapper();
|
||||
|
||||
@Spy
|
||||
private StrictMapper StrictMapper = new StrictMapper(emw);
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ class HsBookingItemCreatedListenerUnitTest {
|
||||
private EntityManagerWrapper emw = emwFake;
|
||||
|
||||
@Spy
|
||||
private ObjectMapper jsonMapper = new JsonObjectMapperConfiguration().customObjectMapper().build();
|
||||
private ObjectMapper jsonMapper = new JsonObjectMapperConfiguration().customObjectMapper();
|
||||
|
||||
@Spy
|
||||
private StrictMapper StrictMapper = new StrictMapper(emw);
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ class ManagedWebspaceHostingAssetFactoryUnitTest {
|
||||
private EntityManagerWrapper emw = emwFake;
|
||||
|
||||
@Spy
|
||||
private ObjectMapper jsonMapper = new JsonObjectMapperConfiguration().customObjectMapper().build();
|
||||
private ObjectMapper jsonMapper = new JsonObjectMapperConfiguration().customObjectMapper();
|
||||
|
||||
@Spy
|
||||
private StrictMapper StrictMapper = new StrictMapper(emw);
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.migration;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.SneakyThrows;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hash.HashGenerator;
|
||||
import net.hostsharing.hsadminng.hash.HashGenerator.Algorithm;
|
||||
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity;
|
||||
|
||||
+21
-17
@@ -3,13 +3,17 @@ package net.hostsharing.hsadminng.hs.office.bankaccount;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.json.JSONException;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
@@ -20,19 +24,19 @@ import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
@Tag("officeIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -58,7 +62,7 @@ class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/bankaccounts")
|
||||
@@ -124,7 +128,7 @@ class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -163,7 +167,7 @@ class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/bankaccounts/" + givenBankAccountUuid)
|
||||
@@ -184,7 +188,7 @@ class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/bankaccounts/" + givenBankAccountUuid)
|
||||
@@ -200,7 +204,7 @@ class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer bankaccount-admin@firstbankaccount.example.com")
|
||||
.header("Authorization", bearer("bankaccount-admin@firstbankaccount.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/bankaccounts/" + givenBankAccountUuid)
|
||||
@@ -228,7 +232,7 @@ class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -266,7 +270,7 @@ class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/bankaccounts/" + givenBankAccount.getUuid())
|
||||
@@ -283,7 +287,7 @@ class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-test-user@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-test-user@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/bankaccounts/" + givenBankAccount.getUuid())
|
||||
@@ -304,7 +308,7 @@ class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/bankaccounts/" + givenBankAccount.getUuid())
|
||||
|
||||
+9
-7
@@ -1,27 +1,29 @@
|
||||
package net.hostsharing.hsadminng.hs.office.bankaccount;
|
||||
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsOfficeBankAccountController.class)
|
||||
@Import({DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
@Import({ MessageTranslator.class,
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class HsOfficeBankAccountControllerRestTest {
|
||||
|
||||
@Autowired
|
||||
@@ -69,7 +71,7 @@ class HsOfficeBankAccountControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/bankaccounts")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
@@ -116,7 +118,7 @@ class HsOfficeBankAccountControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/bankaccounts")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.bankaccount;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.role.RawRbacRoleRepository;
|
||||
|
||||
+16
-17
@@ -3,10 +3,9 @@ package net.hostsharing.hsadminng.hs.office.contact;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.json.JSONException;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -27,6 +26,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -34,13 +34,12 @@ import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
@Tag("officeIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -69,7 +68,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/contacts")
|
||||
@@ -107,7 +106,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -156,7 +155,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/contacts/" + givenContactUuid)
|
||||
@@ -177,7 +176,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/contacts/" + givenContactUuid)
|
||||
@@ -192,7 +191,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer contact-admin@firstcontact.example.com")
|
||||
.header("Authorization", bearer("contact-admin@firstcontact.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/contacts/" + givenContactUuid)
|
||||
@@ -224,7 +223,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -282,7 +281,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -328,7 +327,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/contacts/" + givenContact.getUuid())
|
||||
@@ -348,7 +347,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-test-user@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-test-user@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/contacts/" + givenContact.getUuid())
|
||||
@@ -369,7 +368,7 @@ class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/contacts/" + givenContact.getUuid())
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.contact;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.mapper.Array;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.role.RawRbacRoleRepository;
|
||||
|
||||
+22
-26
@@ -3,13 +3,10 @@ package net.hostsharing.hsadminng.hs.office.coopassets;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.config.MessagesResourceConfig;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@@ -27,6 +24,7 @@ import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType.DEPOSIT;
|
||||
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
@@ -34,14 +32,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@Tag("officeIntegrationTest")
|
||||
@Transactional
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class,
|
||||
MessagesResourceConfig.class, MessageTranslator.class}
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
@Tag("officeIntegrationTest")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -70,14 +66,14 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/coopassetstransactions")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", hasSize(3*6)); // @formatter:on
|
||||
.body("", hasSize(3 * 6)); // @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +84,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/coopassetstransactions?membershipUuid="+givenMembership.getUuid())
|
||||
@@ -211,7 +207,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/coopassetstransactions?membershipUuid="
|
||||
@@ -244,7 +240,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -290,18 +286,18 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
// TODO.impl: introduce something like transactedAsSuperuser / transactedAs("...", ...)
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
return coopAssetsTransactionRepo.save(HsOfficeCoopAssetsTransactionEntity.builder()
|
||||
.transactionType(DEPOSIT)
|
||||
.valueDate(LocalDate.of(2022, 10, 20))
|
||||
.membership(givenMembership)
|
||||
.assetValue(new BigDecimal("256.00"))
|
||||
.reference("test ref")
|
||||
.transactionType(DEPOSIT)
|
||||
.valueDate(LocalDate.of(2022, 10, 20))
|
||||
.membership(givenMembership)
|
||||
.assetValue(new BigDecimal("256.00"))
|
||||
.reference("test ref")
|
||||
.build());
|
||||
}).assertSuccessful().assertNotNull().returnedValue();
|
||||
}).assertSuccessful().assertNotNull().returnedValue();
|
||||
toCleanup(HsOfficeCoopAssetsTransactionEntity.class, givenTransaction.getUuid());
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -357,7 +353,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -398,7 +394,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
LocalDate.of(2010, 3, 15)).get(0).getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given().header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.given().header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/coopassetstransactions/" + givenCoopAssetTransactionUuid)
|
||||
@@ -421,7 +417,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
LocalDate.of(2010, 3, 15)).get(0).getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given().header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.given().header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/coopassetstransactions/" + givenCoopAssetTransactionUuid)
|
||||
@@ -439,7 +435,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer person-FirstGmbH@example.com")
|
||||
.header("Authorization", bearer("person-FirstGmbH@example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/coopassetstransactions/" + givenCoopAssetTransactionUuid)
|
||||
|
||||
+11
-10
@@ -2,15 +2,16 @@ package net.hostsharing.hsadminng.hs.office.coopassets;
|
||||
|
||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRealEntity;
|
||||
import net.hostsharing.hsadminng.config.MessagesResourceConfig;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
|
||||
import net.hostsharing.hsadminng.rbac.test.JsonBuilder;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import net.hostsharing.hsadminng.test.TestUuidGenerator;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -37,6 +38,7 @@ import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsT
|
||||
import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType.DISBURSAL;
|
||||
import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType.REVERSAL;
|
||||
import static net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionType.TRANSFER;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.rbac.test.JsonBuilder.jsonObject;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -54,8 +56,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
MessagesResourceConfig.class,
|
||||
MessageTranslator.class,
|
||||
JsonObjectMapperConfiguration.class,
|
||||
DisableSecurityConfig.class })
|
||||
@ActiveProfiles("test")
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
|
||||
// If you need to run just a single test-case in this data-driven test-method, set SINGLE_TEST_CASE_EXECUTION to true!
|
||||
@@ -662,7 +664,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/coopassetstransactions")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(testCase.givenRequestBody())
|
||||
@@ -838,7 +840,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/coopassetstransactions")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(testCase.givenRequestBody())
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
@@ -857,7 +859,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/coopassetstransactions/" + SOME_REVERTED_TRANSFER_ASSET_TX_ENTITY.getUuid())
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
@@ -873,7 +875,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/coopassetstransactions/" + UNAVAILABLE_UUID)
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
@@ -899,7 +901,7 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/coopassetstransactions")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
@@ -950,5 +952,4 @@ class HsOfficeCoopAssetsTransactionControllerRestTest {
|
||||
private String suffixOf(final String memberNumber) {
|
||||
return memberNumber.substring("M-".length() + 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.coopassets;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||
|
||||
+34
-26
@@ -3,12 +3,10 @@ package net.hostsharing.hsadminng.hs.office.coopshares;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@@ -22,21 +20,22 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = {HsadminNgApplication.class, DisableSecurityConfig.class, MessageTranslator.class, JpaAttempt.class})
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
@Tag("officeIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@Autowired
|
||||
@@ -76,7 +75,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/coopsharestransactions")
|
||||
@@ -94,7 +93,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/coopsharestransactions?membershipUuid=" + givenMembership.getUuid())
|
||||
@@ -158,7 +157,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/coopsharestransactions?membershipUuid=" + givenMembership.getUuid() + "&fromValueDate=2020-01-01&toValueDate=2021-12-31")
|
||||
@@ -191,7 +190,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(ContentType.JSON).body("""
|
||||
{
|
||||
@@ -240,18 +239,18 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased
|
||||
// TODO.impl: introduce something like transactedAsSuperuser / transactedAs("...", ...)
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
return coopSharesTransactionRepo.save(HsOfficeCoopSharesTransactionEntity.builder()
|
||||
.transactionType(HsOfficeCoopSharesTransactionType.SUBSCRIPTION)
|
||||
.valueDate(LocalDate.of(2022, 10, 20))
|
||||
.membership(givenMembership)
|
||||
.shareCount(13)
|
||||
.reference("test ref")
|
||||
.build());
|
||||
.transactionType(HsOfficeCoopSharesTransactionType.SUBSCRIPTION)
|
||||
.valueDate(LocalDate.of(2022, 10, 20))
|
||||
.membership(givenMembership)
|
||||
.shareCount(13)
|
||||
.reference("test ref")
|
||||
.build());
|
||||
}).assertSuccessful().assertNotNull().returnedValue();
|
||||
toCleanup(HsOfficeCoopSharesTransactionEntity.class, givenTransaction.getUuid());
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -294,7 +293,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
// finally, the new coopAssetsTransaction can be accessed under the generated UUID
|
||||
final var newShareTxUuid = UUID.fromString(
|
||||
location.substring(location.lastIndexOf('/') + 1));
|
||||
location.substring(location.lastIndexOf('/') + 1));
|
||||
assertThat(newShareTxUuid).isNotNull();
|
||||
toCleanup(HsOfficeCoopSharesTransactionEntity.class, newShareTxUuid);
|
||||
}
|
||||
@@ -307,7 +306,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -344,11 +343,14 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased
|
||||
@Test
|
||||
void globalAdmin_withoutAssumedRole_canGetArbitraryCoopShareTransaction() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenCoopShareTransactionUuid = coopSharesTransactionRepo.findCoopSharesTransactionByOptionalMembershipUuidAndDateRange(null, LocalDate.of(2010, 3, 15), LocalDate.of(2010, 3, 15)).get(0).getUuid();
|
||||
final var givenCoopShareTransactionUuid = coopSharesTransactionRepo.findCoopSharesTransactionByOptionalMembershipUuidAndDateRange(
|
||||
null,
|
||||
LocalDate.of(2010, 3, 15),
|
||||
LocalDate.of(2010, 3, 15)).get(0).getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/coopsharestransactions/" + givenCoopShareTransactionUuid)
|
||||
@@ -366,11 +368,14 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased
|
||||
@Test
|
||||
void normalUser_canNotGetUnrelatedCoopShareTransaction() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenCoopShareTransactionUuid = coopSharesTransactionRepo.findCoopSharesTransactionByOptionalMembershipUuidAndDateRange(null, LocalDate.of(2010, 3, 15), LocalDate.of(2010, 3, 15)).get(0).getUuid();
|
||||
final var givenCoopShareTransactionUuid = coopSharesTransactionRepo.findCoopSharesTransactionByOptionalMembershipUuidAndDateRange(
|
||||
null,
|
||||
LocalDate.of(2010, 3, 15),
|
||||
LocalDate.of(2010, 3, 15)).get(0).getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.get("http://localhost/api/hs/office/coopsharestransactions/" + givenCoopShareTransactionUuid)
|
||||
.then().log().body()
|
||||
@@ -381,11 +386,14 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased
|
||||
@Test
|
||||
void partnerPersonUser_canGetRelatedCoopShareTransaction() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenCoopShareTransactionUuid = coopSharesTransactionRepo.findCoopSharesTransactionByOptionalMembershipUuidAndDateRange(null, LocalDate.of(2010, 3, 15), LocalDate.of(2010, 3, 15)).get(0).getUuid();
|
||||
final var givenCoopShareTransactionUuid = coopSharesTransactionRepo.findCoopSharesTransactionByOptionalMembershipUuidAndDateRange(
|
||||
null,
|
||||
LocalDate.of(2010, 3, 15),
|
||||
LocalDate.of(2010, 3, 15)).get(0).getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer person-FirstGmbH@example.com")
|
||||
.header("Authorization", bearer("person-FirstGmbH@example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/coopsharestransactions/" + givenCoopShareTransactionUuid)
|
||||
|
||||
+9
-8
@@ -2,11 +2,12 @@ package net.hostsharing.hsadminng.hs.office.coopshares;
|
||||
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.config.MessagesResourceConfig;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
|
||||
import net.hostsharing.hsadminng.rbac.test.JsonBuilder;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -21,6 +22,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.rbac.test.JsonBuilder.jsonObject;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
@@ -28,10 +30,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsOfficeCoopSharesTransactionController.class)
|
||||
@Import({DisableSecurityConfig.class,
|
||||
MessagesResourceConfig.class,
|
||||
MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
@Import({ MessagesResourceConfig.class,
|
||||
MessageTranslator.class,
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class HsOfficeCoopSharesTransactionControllerRestTest {
|
||||
|
||||
@Autowired
|
||||
@@ -126,7 +128,7 @@ class HsOfficeCoopSharesTransactionControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/coopsharestransactions")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(testCase.givenRequestBody())
|
||||
@@ -138,5 +140,4 @@ class HsOfficeCoopSharesTransactionControllerRestTest {
|
||||
.andExpect(jsonPath("statusPhrase", is("Bad Request")))
|
||||
.andExpect(jsonPath("message", containsString(testCase.expectedErrorMessage)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.coopshares;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||
|
||||
+21
-22
@@ -3,16 +3,15 @@ package net.hostsharing.hsadminng.hs.office.debitor;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRbacRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealRepository;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@@ -28,6 +27,7 @@ import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.DEBITOR;
|
||||
import static net.hostsharing.hsadminng.rbac.role.RbacRoleType.ADMIN;
|
||||
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
|
||||
@@ -38,13 +38,12 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@Tag("officeIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles({ "fake-jwt"})
|
||||
@Transactional
|
||||
@Tag("officeIntegrationTest")
|
||||
class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
private static final int LOWEST_TEMP_DEBITOR_SUFFIX = 90;
|
||||
@@ -93,7 +92,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/debitors/" + givenDebitor.getUuid())
|
||||
@@ -120,7 +119,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/debitors/D-1000212")
|
||||
@@ -151,7 +150,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/debitors")
|
||||
@@ -306,7 +305,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/debitors?partnerNumber=P-10002")
|
||||
@@ -351,7 +350,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -396,7 +395,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -447,7 +446,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -482,7 +481,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -513,7 +512,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/debitors/" + givenDebitorUuid)
|
||||
@@ -578,7 +577,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/debitors/" + givenDebitorUuid)
|
||||
@@ -593,7 +592,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer contact-admin@firstcontact.example.com")
|
||||
.header("Authorization", bearer("contact-admin@firstcontact.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/debitors/" + givenDebitorUuid)
|
||||
@@ -623,7 +622,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -705,7 +704,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
// @formatter:on
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", givenDebitor.getDebitorRel().getContact().roleId(ADMIN) )
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -734,7 +733,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/debitors/" + givenDebitor.getUuid())
|
||||
@@ -753,7 +752,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer contact-admin@tenthcontact.example.com")
|
||||
.header("Authorization", bearer("contact-admin@tenthcontact.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/debitors/" + givenDebitor.getUuid())
|
||||
@@ -772,7 +771,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/debitors/" + givenDebitor.getUuid())
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.debitor;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRealRepository;
|
||||
|
||||
+21
-20
@@ -4,11 +4,10 @@ import io.hypersistence.utils.hibernate.type.range.Range;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRealRepository;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.json.JSONException;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@@ -25,20 +24,22 @@ import jakarta.persistence.PersistenceContext;
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipStatus.ACTIVE;
|
||||
import static net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipStatus.CANCELLED;
|
||||
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@Tag("officeIntegrationTest")
|
||||
@Transactional
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
@Tag("officeIntegrationTest")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
private static final String TEMP_MEMBER_NUMBER_SUFFIX = "90";
|
||||
@@ -72,7 +73,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/memberships")
|
||||
@@ -118,7 +119,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.queryParam("partnerUuid", partner.getUuid() )
|
||||
@@ -146,7 +147,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.queryParam("partnerNumber", "P-10002" )
|
||||
@@ -183,7 +184,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -226,7 +227,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/memberships/" + givenMembershipUuid)
|
||||
@@ -252,7 +253,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/memberships/" + givenMembershipUuid)
|
||||
@@ -267,7 +268,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "hs_office.relation#HostsharingeG-with-PARTNER-ThirdOHG:AGENT")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -299,7 +300,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -343,7 +344,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
// when
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", givenPartnerAdmin)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -378,7 +379,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/memberships/" + givenMembership.getUuid())
|
||||
@@ -396,7 +397,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "hs_office.relation#HostsharingeG-with-PARTNER-FirstGmbH:AGENT")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -415,7 +416,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/memberships/" + givenMembership.getUuid())
|
||||
|
||||
+16
-14
@@ -3,14 +3,15 @@ package net.hostsharing.hsadminng.hs.office.membership;
|
||||
import io.hypersistence.utils.hibernate.type.range.Range;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.config.MessagesResourceConfig;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.coopassets.HsOfficeCoopAssetsTransactionRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRbacEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRealRepository;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -30,6 +31,7 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.hypersistence.utils.hibernate.type.range.Range.localDateRange;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
@@ -42,8 +44,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsOfficeMembershipController.class)
|
||||
@Import({ StrictMapper.class, DisableSecurityConfig.class, MessagesResourceConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
@Import({ StrictMapper.class, MessagesResourceConfig.class, MessageTranslator.class,
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
public class HsOfficeMembershipControllerRestTest {
|
||||
|
||||
private static final HsOfficePartnerRealEntity PARTNER_12345 = HsOfficePartnerRealEntity.builder()
|
||||
@@ -112,7 +115,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/memberships?partnerNumber=P-12345")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
@@ -134,7 +137,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/memberships?partnerNumber=P-12345")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
@@ -199,7 +202,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/memberships/" + givenUuid)
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
@@ -218,7 +221,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/memberships/" + UUID.randomUUID())
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
@@ -236,7 +239,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/memberships/M-1234501")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
@@ -255,7 +258,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/memberships/M-0000000")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
@@ -273,7 +276,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/memberships")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
@@ -303,7 +306,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/memberships")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
@@ -331,7 +334,7 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/memberships")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
@@ -366,5 +369,4 @@ public class HsOfficeMembershipControllerRestTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.office.membership;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.range.Range;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRealRepository;
|
||||
import net.hostsharing.hsadminng.mapper.Array;
|
||||
|
||||
+54
-27
@@ -13,8 +13,10 @@ import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealReposito
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
@@ -23,18 +25,20 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.EX_PARTNER;
|
||||
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
|
||||
@Tag("officeIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Tag("officeIntegrationTest")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
private static final UUID GIVEN_NON_EXISTING_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
@@ -66,7 +70,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/partners")
|
||||
@@ -94,13 +98,19 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
void globalAdmin_withoutAssumedRole_canPostNewPartner() {
|
||||
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenMandantPerson = personRealRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow();
|
||||
final var givenMandantPerson = personRealRepo.findPersonByOptionalNameLike("Hostsharing eG")
|
||||
.stream()
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
final var givenPerson = personRealRepo.findPersonByOptionalNameLike("Winkler").stream().findFirst().orElseThrow();
|
||||
final var givenContact = contactRealRepo.findContactByOptionalCaptionLike("fourth").stream().findFirst().orElseThrow();
|
||||
final var givenContact = contactRealRepo.findContactByOptionalCaptionLike("fourth")
|
||||
.stream()
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -159,7 +169,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -195,7 +205,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -238,7 +248,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/partners/" + givenPartnerUuid)
|
||||
@@ -270,7 +280,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/partners/" + givenPartnerUuid)
|
||||
@@ -285,7 +295,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer contact-admin@firstcontact.example.com")
|
||||
.header("Authorization", bearer("contact-admin@firstcontact.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/partners/" + givenPartnerUuid)
|
||||
@@ -316,7 +326,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -384,7 +394,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -411,7 +421,12 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
// and an ex-partner-relation got created
|
||||
final var newPartnerPersonUuid = givenPartner.getPartnerRel().getHolder().getUuid();
|
||||
assertThat(relationRepo.findRelationRelatedToPersonUuidRelationTypeMarkPersonAndContactData(newPartnerPersonUuid, EX_PARTNER, null, null, null))
|
||||
assertThat(relationRepo.findRelationRelatedToPersonUuidRelationTypeMarkPersonAndContactData(
|
||||
newPartnerPersonUuid,
|
||||
EX_PARTNER,
|
||||
null,
|
||||
null,
|
||||
null))
|
||||
.map(HsOfficeRelation::toShortString)
|
||||
.contains("rel(anchor='NP Winkler, Paul', type=EX_PARTNER, holder='UF Erben Bessler')");
|
||||
}
|
||||
@@ -424,7 +439,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -449,7 +464,9 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
// finally, the partner details and only the partner details are actually updated
|
||||
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isPresent().get()
|
||||
.matches(partner -> {
|
||||
assertThat(partner.getPartnerRel().getContact().getCaption()).isEqualTo(givenPartner.getPartnerRel().getContact().getCaption());
|
||||
assertThat(partner.getPartnerRel().getContact().getCaption()).isEqualTo(givenPartner.getPartnerRel()
|
||||
.getContact()
|
||||
.getCaption());
|
||||
assertThat(partner.getDetails().getRegistrationOffice()).isEqualTo("Temp Registergericht Leer");
|
||||
assertThat(partner.getDetails().getRegistrationNumber()).isEqualTo("333333");
|
||||
assertThat(partner.getDetails().getBirthName()).isEqualTo("Maja Schmidt");
|
||||
@@ -472,7 +489,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/partners/" + givenPartner.getUuid())
|
||||
@@ -492,7 +509,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer contact-admin@fourthcontact.example.com")
|
||||
.header("Authorization", bearer("contact-admin@fourthcontact.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/partners/" + givenPartner.getUuid())
|
||||
@@ -511,7 +528,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/partners/" + givenPartner.getUuid())
|
||||
@@ -528,9 +545,18 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
final String contactName) {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenMandantPerson = personRealRepo.findPersonByOptionalNameLike("Hostsharing eG").stream().findFirst().orElseThrow();
|
||||
final var givenPerson = personRealRepo.findPersonByOptionalNameLike(partnerHolderName).stream().findFirst().orElseThrow();
|
||||
final var givenContact = contactRealRepo.findContactByOptionalCaptionLike(contactName).stream().findFirst().orElseThrow();
|
||||
final var givenMandantPerson = personRealRepo.findPersonByOptionalNameLike("Hostsharing eG")
|
||||
.stream()
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
final var givenPerson = personRealRepo.findPersonByOptionalNameLike(partnerHolderName)
|
||||
.stream()
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
final var givenContact = contactRealRepo.findContactByOptionalCaptionLike(contactName)
|
||||
.stream()
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
|
||||
final var partnerRel = new HsOfficeRelationRealEntity();
|
||||
partnerRel.setType(HsOfficeRelationType.PARTNER);
|
||||
@@ -541,6 +567,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
return partnerRel;
|
||||
}).assertSuccessful().returnedValue();
|
||||
}
|
||||
|
||||
private HsOfficePartnerRbacEntity givenSomeTemporaryPartnerBessler(final Integer partnerNumber) {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
|
||||
+11
-9
@@ -1,8 +1,8 @@
|
||||
package net.hostsharing.hsadminng.hs.office.partner;
|
||||
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactFromResourceConverter;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealEntity;
|
||||
@@ -11,6 +11,7 @@ import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealReposito
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
import net.hostsharing.hsadminng.config.MessagesResourceConfig;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -32,6 +33,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -46,8 +48,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
MessagesResourceConfig.class,
|
||||
MessageTranslator.class,
|
||||
HsOfficeContactFromResourceConverter.class,
|
||||
DisableSecurityConfig.class })
|
||||
@ActiveProfiles("test")
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class HsOfficePartnerControllerRestTest {
|
||||
|
||||
static final UUID GIVEN_MANDANTE_UUID = UUID.randomUUID();
|
||||
@@ -112,7 +114,7 @@ class HsOfficePartnerControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/partners")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("Accept-Language", "de")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
@@ -147,7 +149,7 @@ class HsOfficePartnerControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/hs/office/partners")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
@@ -190,7 +192,7 @@ class HsOfficePartnerControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/partners/P-12345")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
@@ -207,7 +209,7 @@ class HsOfficePartnerControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/partners/P-12345")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
@@ -235,7 +237,7 @@ class HsOfficePartnerControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.delete("/api/hs/office/partners/" + givenPartnerUuid)
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.partner;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRealEntity;
|
||||
|
||||
+18
-17
@@ -3,10 +3,9 @@ package net.hostsharing.hsadminng.hs.office.person;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@@ -22,17 +21,19 @@ import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@Tag("officeIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Tag("officeIntegrationTest")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -61,7 +62,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/persons")
|
||||
@@ -81,7 +82,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -119,7 +120,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/persons/" + givenPersonUuid)
|
||||
@@ -142,7 +143,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/persons/" + givenPersonUuid)
|
||||
@@ -159,7 +160,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer person-ErbenBesslerMelBessler@example.com")
|
||||
.header("Authorization", bearer("person-ErbenBesslerMelBessler@example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/persons/" + givenPersonUuid)
|
||||
@@ -188,7 +189,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -230,7 +231,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -274,7 +275,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/persons/" + givenPerson.getUuid())
|
||||
@@ -293,7 +294,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-test-user@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-test-user@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/persons/" + givenPerson.getUuid())
|
||||
@@ -313,7 +314,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/persons/" + givenPerson.getUuid())
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.person;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.role.RawRbacRoleRepository;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.person;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.mapper.Array;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.role.RawRbacRoleRepository;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.relation;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||
|
||||
+26
-26
@@ -2,14 +2,13 @@ package net.hostsharing.hsadminng.hs.office.relation;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationTypeResource;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -22,19 +21,20 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
@Tag("officeIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
public static final UUID GIVEN_NON_EXISTING_HOLDER_PERSON_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
@@ -68,7 +68,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/relations?personUuid=%s&relationType=%s"
|
||||
@@ -126,7 +126,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/relations?personUuid=%s"
|
||||
@@ -183,7 +183,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/relations?personData=firby&contactData=Contact-Admin@FirstContact.Example.COM")
|
||||
@@ -235,7 +235,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -280,7 +280,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -348,7 +348,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -380,7 +380,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -413,7 +413,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -447,7 +447,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/relations/" + givenRelationUuid)
|
||||
@@ -470,7 +470,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/relations/" + givenRelationUuid)
|
||||
@@ -486,7 +486,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer contact-admin@firstcontact.example.com")
|
||||
.header("Authorization", bearer("contact-admin@firstcontact.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
|
||||
@@ -529,7 +529,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -572,7 +572,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
|
||||
@@ -591,7 +591,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer contact-admin@seventhcontact.example.com")
|
||||
.header("Authorization", bearer("contact-admin@seventhcontact.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
|
||||
@@ -610,7 +610,7 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.relation;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealRepository;
|
||||
import net.hostsharing.hsadminng.lambda.Reducer;
|
||||
|
||||
+2
-25
@@ -1,7 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.scenarios;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRbacEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRbacRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.contact.AddPhoneNumberToContactData;
|
||||
@@ -43,39 +42,16 @@ import net.hostsharing.hsadminng.hs.scenarios.Produces;
|
||||
import net.hostsharing.hsadminng.hs.scenarios.Requires;
|
||||
import net.hostsharing.hsadminng.hs.scenarios.ScenarioTest;
|
||||
import net.hostsharing.hsadminng.lambda.Reducer;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.test.IgnoreOnFailureExtension;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.ClassOrderer;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestClassOrder;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
@Tag("scenarioTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class },
|
||||
properties = {
|
||||
"spring.datasource.url=${HSADMINNG_POSTGRES_JDBC_URL:jdbc:tc:postgresql:15.5-bookworm:///scenariosTC}",
|
||||
"spring.datasource.username=${HSADMINNG_POSTGRES_ADMIN_USERNAME:ADMIN}",
|
||||
"spring.datasource.password=${HSADMINNG_POSTGRES_ADMIN_PASSWORD:password}",
|
||||
"hsadminng.superuser=${HSADMINNG_SUPERUSER:superuser-alex@hostsharing.net}"
|
||||
}
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@TestClassOrder(ClassOrderer.OrderAnnotation.class)
|
||||
@ExtendWith(IgnoreOnFailureExtension.class)
|
||||
class HsOfficeScenarioTests extends ScenarioTest {
|
||||
|
||||
@Autowired
|
||||
@@ -702,7 +678,8 @@ class HsOfficeScenarioTests extends ScenarioTest {
|
||||
|
||||
@Test
|
||||
@Order(6010)
|
||||
@Requires("Debitor: D-3101100 - Michelle Matthieu") // which should also get updated
|
||||
@Requires("Debitor: D-3101100 - Michelle Matthieu")
|
||||
// which should also get updated
|
||||
void shouldReplaceDeceasedPartnerByCommunityOfHeirs() {
|
||||
new ReplaceDeceasedPartnerWithCommunityOfHeirs(scenarioTest)
|
||||
.given("partnerNumber", "P-31011")
|
||||
|
||||
+27
-24
@@ -8,7 +8,6 @@ import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountReposi
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@@ -26,18 +25,20 @@ import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@Tag("officeIntegrationTest")
|
||||
@Transactional
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
@Tag("officeIntegrationTest")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -66,7 +67,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/sepamandates")
|
||||
@@ -107,7 +108,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/sepamandates?iban=DE02120300000000202051")
|
||||
@@ -145,7 +146,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -186,7 +187,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -211,7 +212,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -241,7 +242,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -275,7 +276,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/sepamandates/" + givenSepaMandateUuid)
|
||||
@@ -305,7 +306,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/sepamandates/" + givenSepaMandateUuid)
|
||||
@@ -322,7 +323,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer bankaccount-admin@FirstGmbH.example.com")
|
||||
.header("Authorization", bearer("bankaccount-admin@FirstGmbH.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/sepamandates/" + givenSepaMandateUuid)
|
||||
@@ -354,7 +355,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -383,7 +384,8 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isPresent().get()
|
||||
.matches(mandate -> {
|
||||
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(D-1000111: rel(anchor='LP First GmbH', type=DEBITOR, holder='LP First GmbH'), fir)");
|
||||
assertThat(mandate.getDebitor().toString()).isEqualTo(
|
||||
"debitor(D-1000111: rel(anchor='LP First GmbH', type=DEBITOR, holder='LP First GmbH'), fir)");
|
||||
assertThat(mandate.getBankAccount().toShortString()).isEqualTo("First GmbH");
|
||||
assertThat(mandate.getReference()).isEqualTo("temp ref CAT Z - patched");
|
||||
assertThat(mandate.getValidFrom()).isEqualTo("2020-06-05");
|
||||
@@ -400,7 +402,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -425,7 +427,8 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isPresent().get()
|
||||
.matches(mandate -> {
|
||||
assertThat(mandate.getDebitor().toString())
|
||||
.isEqualTo("debitor(D-1000111: rel(anchor='LP First GmbH', type=DEBITOR, holder='LP First GmbH'), fir)");
|
||||
.isEqualTo(
|
||||
"debitor(D-1000111: rel(anchor='LP First GmbH', type=DEBITOR, holder='LP First GmbH'), fir)");
|
||||
assertThat(mandate.getBankAccount().toShortString()).isEqualTo("First GmbH");
|
||||
assertThat(mandate.getReference()).isEqualTo("temp ref CAT Z");
|
||||
assertThat(mandate.getValidity().asString()).isEqualTo("[2022-11-01,2023-01-01)");
|
||||
@@ -441,7 +444,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -475,7 +478,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/sepamandates/" + givenSepaMandate.getUuid())
|
||||
@@ -493,7 +496,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer bankaccount-admin@FirstGmbH.example.com")
|
||||
.header("Authorization", bearer("bankaccount-admin@FirstGmbH.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/sepamandates/" + givenSepaMandate.getUuid())
|
||||
@@ -511,7 +514,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer selfregistered-user-drew@hostsharing.org")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/sepamandates/" + givenSepaMandate.getUuid())
|
||||
|
||||
+7
-5
@@ -1,15 +1,15 @@
|
||||
package net.hostsharing.hsadminng.hs.office.sepamandate;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.range.Range;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRealEntity;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,6 +24,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
@@ -31,8 +32,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(HsOfficeSepaMandateController.class)
|
||||
@Import({ StrictMapper.class, DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
@Import({ StrictMapper.class, MessageTranslator.class,
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class HsOfficeSepaMandateControllerRestTest {
|
||||
|
||||
@MockitoBean
|
||||
@@ -85,7 +87,7 @@ class HsOfficeSepaMandateControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/hs/office/sepamandates?iban=DE123")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.office.sepamandate;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.range.Range;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
|
||||
@@ -3,17 +3,27 @@ package net.hostsharing.hsadminng.hs.scenarios;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.val;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.hs.scenarios.TemplateResolver.Resolver;
|
||||
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RbacGrantsDiagramService;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.test.IgnoreOnFailureExtension;
|
||||
import org.apache.commons.collections4.SetUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.ClassOrderer;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.TestClassOrder;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
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.ActiveProfiles;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
@@ -29,11 +39,27 @@ import java.util.stream.Stream;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.hs.scenarios.Produces.Aggregator.producedAliases;
|
||||
import static net.hostsharing.hsadminng.hs.scenarios.TemplateResolver.Resolver.DROP_COMMENTS;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Tag("scenarioTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class,
|
||||
RbacGrantsDiagramService.class },
|
||||
properties = {
|
||||
"spring.datasource.url=${HSADMINNG_POSTGRES_JDBC_URL:jdbc:tc:postgresql:15.5-bookworm:///scenariosTC}",
|
||||
"spring.datasource.username=${HSADMINNG_POSTGRES_ADMIN_USERNAME:ADMIN}",
|
||||
"spring.datasource.password=${HSADMINNG_POSTGRES_ADMIN_PASSWORD:password}",
|
||||
"hsadminng.superuser=${HSADMINNG_SUPERUSER:superuser-alex@hostsharing.net}"
|
||||
}
|
||||
)
|
||||
@ActiveProfiles({ "fake-jwt" })
|
||||
@TestClassOrder(ClassOrderer.OrderAnnotation.class)
|
||||
@ExtendWith(IgnoreOnFailureExtension.class)
|
||||
public abstract class ScenarioTest extends ContextBasedTest {
|
||||
|
||||
final static String RUN_AS_USER = "superuser-alex@hostsharing.net"; // TODO.test: use global:AGENT when implemented
|
||||
@@ -60,8 +86,8 @@ public abstract class ScenarioTest extends ContextBasedTest {
|
||||
@Autowired
|
||||
protected JpaAttempt jpaAttempt;
|
||||
|
||||
@SneakyThrows
|
||||
@BeforeEach
|
||||
@SneakyThrows
|
||||
protected void beforeScenario(final TestInfo testInfo) {
|
||||
try {
|
||||
testInfo.getTestMethod().ifPresent(currentTestMethod -> {
|
||||
@@ -82,6 +108,12 @@ public abstract class ScenarioTest extends ContextBasedTest {
|
||||
testReport.close();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String bearerTemplate(final String subjectTemplate) {
|
||||
val subject = resolve(subjectTemplate, DROP_COMMENTS);
|
||||
return bearer(subject);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private void callRequiredProducers(final Method currentTestMethod) {
|
||||
final var testMethodRequires = Optional.of(currentTestMethod)
|
||||
|
||||
@@ -37,6 +37,7 @@ import static java.net.URLEncoder.encode;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static net.hostsharing.hsadminng.hs.scenarios.TemplateResolver.Resolver.DROP_COMMENTS;
|
||||
import static net.hostsharing.hsadminng.hs.scenarios.TemplateResolver.Resolver.KEEP_COMMENTS;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.test.DebuggerDetection.isDebuggerAttached;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
@@ -172,7 +173,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
@SneakyThrows
|
||||
public final HttpResponse httpGet(final String uriPathWithPlaceholders) {
|
||||
return httpGet(uriPathWithPlaceholders,
|
||||
req -> req.header("Authorization", "Bearer " + ScenarioTest.RUN_AS_USER));
|
||||
req -> req.header("Authorization", bearer(ScenarioTest.RUN_AS_USER)));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@@ -183,7 +184,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
.POST(BodyPublishers.ofString(requestBody))
|
||||
.uri(new URI("http://localhost:" + testSuite.port + uriPath))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer " + ScenarioTest.RUN_AS_USER)
|
||||
.header("Authorization", bearer(ScenarioTest.RUN_AS_USER))
|
||||
.timeout(seconds(HTTP_TIMEOUT_SECONDS))
|
||||
.build();
|
||||
final var response = client.send(request, BodyHandlers.ofString());
|
||||
@@ -198,7 +199,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
.method(HttpMethod.PATCH.toString(), BodyPublishers.ofString(requestBody))
|
||||
.uri(new URI("http://localhost:" + testSuite.port + uriPath))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer " + ScenarioTest.RUN_AS_USER)
|
||||
.header("Authorization", bearer(ScenarioTest.RUN_AS_USER))
|
||||
.timeout(seconds(HTTP_TIMEOUT_SECONDS))
|
||||
.build();
|
||||
final var response = client.send(request, BodyHandlers.ofString());
|
||||
@@ -212,7 +213,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
.DELETE()
|
||||
.uri(new URI("http://localhost:" + testSuite.port + uriPath))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer " + ScenarioTest.RUN_AS_USER)
|
||||
.header("Authorization", bearer(ScenarioTest.RUN_AS_USER))
|
||||
.timeout(seconds(HTTP_TIMEOUT_SECONDS))
|
||||
.build();
|
||||
final var response = client.send(request, BodyHandlers.ofString());
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package net.hostsharing.hsadminng.journal;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.rbac.test.cust.TestCustomerEntity;
|
||||
|
||||
@@ -2,9 +2,7 @@ package net.hostsharing.hsadminng.ping;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -13,23 +11,24 @@ 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.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
|
||||
@Tag("generalIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = {
|
||||
HsadminNgApplication.class,
|
||||
DisableSecurityConfig.class,
|
||||
JpaAttempt.class
|
||||
}
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
@TestPropertySource(properties = {
|
||||
"server.port=0",
|
||||
"logging.level.root=DEBUG"
|
||||
})
|
||||
@Transactional
|
||||
@Tag("generalIntegrationTest")
|
||||
class PingControllerAcceptanceTest {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -59,7 +58,7 @@ class PingControllerAcceptanceTest {
|
||||
void pongRepliesWithTranslatedPongResponse(final PongTranslationTestCase testCase) {
|
||||
final var responseBody = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("Accept-Language", testCase.givenLocale)
|
||||
.port(port)
|
||||
.when()
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package net.hostsharing.hsadminng.ping;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.config.MessagesResourceConfig;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -17,6 +18,8 @@ import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
@@ -26,8 +29,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@Import({ MessagesResourceConfig.class,
|
||||
MessageTranslator.class,
|
||||
JsonObjectMapperConfiguration.class,
|
||||
DisableSecurityConfig.class })
|
||||
@ActiveProfiles("test")
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class PingControllerRestTest {
|
||||
|
||||
@Autowired
|
||||
@@ -47,7 +50,7 @@ class PingControllerRestTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(I18nTestCases.class)
|
||||
void pingReturnsPongInEnglish(final I18nTestCases testCase) throws Exception {
|
||||
void pingReturnsPingedInRequestedLanguage(final I18nTestCases testCase) throws Exception {
|
||||
|
||||
// when
|
||||
final var request = mockMvc.perform(MockMvcRequestBuilders
|
||||
@@ -58,7 +61,24 @@ class PingControllerRestTest {
|
||||
|
||||
// then
|
||||
request
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(startsWith(testCase.expectedTranslation)));
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(startsWith(testCase.expectedTranslation)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pongReturnsPongedWithSubject() throws Exception {
|
||||
|
||||
// when
|
||||
final var request = mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/pong")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("Accept-Language", "de")
|
||||
.accept(MediaType.TEXT_PLAIN))
|
||||
.andDo(print());
|
||||
|
||||
// then
|
||||
request
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("superuser-alex@hostsharing.net")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.hostsharing.hsadminng.rbac.context;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.persistence.BaseEntity;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RbacGrantsDiagramService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.hostsharing.hsadminng.rbac.context;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.mapper.Array;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
@@ -21,6 +20,8 @@ import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Tag("generalIntegrationTest")
|
||||
@@ -58,7 +59,26 @@ class ContextIntegrationTests {
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void defineWithCurrentSubjectButWithoutAssumedRoles() {
|
||||
void defineWithCurrentSubjectUuid() {
|
||||
// when
|
||||
final var subjectUuid = uuidOfSubjectName("superuser-alex@hostsharing.net");
|
||||
context.define(subjectUuid.toString());
|
||||
|
||||
// then
|
||||
assertThat(context.fetchCurrentSubject()).
|
||||
isEqualTo("superuser-alex@hostsharing.net");
|
||||
|
||||
assertThat(context.fetchCurrentSubjectUuid()).isNotNull();
|
||||
|
||||
assertThat(context.fetchAssumedRolesNames()).isEmpty();
|
||||
|
||||
assertThat(context.fetchCurrentSubjectOrAssumedRolesUuids())
|
||||
.containsExactly(subjectUuid);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void defineWithCurrentSubjectNameWithoutAssumedRoles() {
|
||||
// when
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
|
||||
@@ -198,4 +218,9 @@ class ContextIntegrationTests {
|
||||
// then
|
||||
assertThat(hsGlobalAdminRole.returnedValue()).isFalse();
|
||||
}
|
||||
|
||||
private UUID uuidOfSubjectName(final String name) {
|
||||
return UUID.fromString(em.createNativeQuery("SELECT uuid FROM rbac.subject WHERE name = :name")
|
||||
.setParameter("name", name).getSingleResult().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.hostsharing.hsadminng.rbac.context;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
+8
-5
@@ -1,8 +1,8 @@
|
||||
package net.hostsharing.hsadminng.rbac.context;
|
||||
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
import net.hostsharing.hsadminng.rbac.role.RbacRoleEntity;
|
||||
@@ -27,6 +27,7 @@ import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -36,8 +37,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(RbacContextController.class)
|
||||
@Import({ StrictMapper.class, DisableSecurityConfig.class, MessageTranslator.class })
|
||||
@ActiveProfiles("test")
|
||||
@Import({ StrictMapper.class,
|
||||
MessageTranslator.class,
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class RbacContextControllerRestTest {
|
||||
|
||||
private static final String GIVEN_SUBJECT_NAME = "superuser-alex@hostsharing.net";
|
||||
@@ -99,7 +102,7 @@ class RbacContextControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/rbac/context")
|
||||
.header("Authorization", "Bearer " + GIVEN_SUBJECT_NAME)
|
||||
.header("Authorization", bearer(GIVEN_SUBJECT_NAME))
|
||||
.header("assumed-roles", rolesToAssume)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
|
||||
+15
-13
@@ -10,7 +10,6 @@ import net.hostsharing.hsadminng.rbac.role.RbacRoleRepository;
|
||||
import net.hostsharing.hsadminng.rbac.subject.RbacSubjectEntity;
|
||||
import net.hostsharing.hsadminng.rbac.subject.RbacSubjectRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
@@ -27,18 +26,21 @@ import jakarta.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional(readOnly = true, propagation = Propagation.NEVER)
|
||||
@Tag("generalIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -66,7 +68,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
|
||||
void globalAdmin_withoutAssumedRole_canViewAllGrants() {
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/grants")
|
||||
@@ -118,7 +120,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
|
||||
void globalAdmin_withAssumedPackageAdminRole_canViewPacketRelatedGrants() {
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.package#yyy00:ADMIN")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -141,7 +143,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
|
||||
void packageAdmin_withoutAssumedRole_canViewPacketRelatedGrants() {
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer pac-admin-yyy00@yyy.example.com")
|
||||
.header("Authorization", bearer("pac-admin-yyy00@yyy.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/grants")
|
||||
@@ -387,7 +389,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
|
||||
|
||||
return RestAssured // @formatter:ff
|
||||
.given()
|
||||
.header("Authorization", "Bearer " + grantingSubject.currentSubject)
|
||||
.header("Authorization", bearer(grantingSubject.currentSubject))
|
||||
.header("assumed-roles", grantingSubject.assumedRole)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -423,7 +425,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
|
||||
|
||||
return RestAssured // @formatter:ff
|
||||
.given()
|
||||
.header("Authorization", "Bearer " + currentSubject.currentSubject)
|
||||
.header("Authorization", bearer(currentSubject.currentSubject))
|
||||
.header("assumed-roles", currentSubject.assumedRole)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -459,7 +461,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
|
||||
|
||||
return RestAssured // @formatter:ff
|
||||
.given()
|
||||
.header("Authorization", "Bearer " + currentSubject.currentSubject)
|
||||
.header("Authorization", bearer(currentSubject.currentSubject))
|
||||
.header("assumed-roles", currentSubject.assumedRole)
|
||||
.port(port)
|
||||
.when()
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.rbac.grant;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
|
||||
import net.hostsharing.hsadminng.rbac.role.RbacRoleRepository;
|
||||
import net.hostsharing.hsadminng.rbac.subject.RbacSubjectEntity;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.rbac.grant;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.grant.RbacGrantsDiagramService.Include;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
|
||||
+12
-10
@@ -2,9 +2,8 @@ package net.hostsharing.hsadminng.rbac.role;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.subject.RbacSubjectRepository;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -12,14 +11,17 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
@Tag("generalIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = {HsadminNgApplication.class, DisableSecurityConfig.class}
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Tag("generalIntegrationTest")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class RbacRoleControllerAcceptanceTest {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -40,7 +42,7 @@ class RbacRoleControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/roles")
|
||||
@@ -65,7 +67,7 @@ class RbacRoleControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.package#yyy00:ADMIN")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -98,7 +100,7 @@ class RbacRoleControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer pac-admin-zzz00@zzz.example.com")
|
||||
.header("Authorization", bearer("pac-admin-zzz00@zzz.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/roles")
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package net.hostsharing.hsadminng.rbac.role;
|
||||
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
@@ -21,7 +21,10 @@ import jakarta.persistence.SynchronizationType;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static net.hostsharing.hsadminng.rbac.role.TestRbacRole.*;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.rbac.role.TestRbacRole.customerXxxAdmin;
|
||||
import static net.hostsharing.hsadminng.rbac.role.TestRbacRole.customerXxxOwner;
|
||||
import static net.hostsharing.hsadminng.rbac.role.TestRbacRole.hostmasterRole;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -30,8 +33,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(RbacRoleController.class)
|
||||
@Import({StrictMapper.class, DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
@Import({ StrictMapper.class,
|
||||
MessageTranslator.class,
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class RbacRoleControllerRestTest {
|
||||
|
||||
@Autowired
|
||||
@@ -67,7 +72,7 @@ class RbacRoleControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.get("/api/rbac/roles")
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
// then
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.rbac.role;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.mapper.Array;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
|
||||
+31
-27
@@ -3,9 +3,8 @@ package net.hostsharing.hsadminng.rbac.subject;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -17,16 +16,21 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
@Tag("generalIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class RbacSubjectControllerAcceptanceTest {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -86,7 +90,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/subjects/" + givenUser.getUuid())
|
||||
@@ -104,7 +108,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.customer#yyy:ADMIN")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -123,7 +127,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer customer-admin@yyy.example.com")
|
||||
.header("Authorization", bearer("customer-admin@yyy.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/subjects/" + givenUser.getUuid())
|
||||
@@ -141,7 +145,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer customer-admin@xxx.example.com")
|
||||
.header("Authorization", bearer("customer-admin@xxx.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/subjects/" + givenUser.getUuid())
|
||||
@@ -160,7 +164,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/subjects")
|
||||
@@ -185,7 +189,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/subjects?name=pac-admin-zzz0")
|
||||
@@ -205,7 +209,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.customer#yyy:ADMIN")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -227,7 +231,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer customer-admin@yyy.example.com")
|
||||
.header("Authorization", bearer("customer-admin@yyy.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/subjects")
|
||||
@@ -248,7 +252,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer pac-admin-xxx01@xxx.example.com")
|
||||
.header("Authorization", bearer("pac-admin-xxx01@xxx.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/subjects")
|
||||
@@ -271,7 +275,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/subjects/" + givenUser.getUuid() + "/permissions")
|
||||
@@ -300,7 +304,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.customer#yyy:ADMIN")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -330,7 +334,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer pac-admin-yyy00@yyy.example.com")
|
||||
.header("Authorization", bearer("pac-admin-yyy00@yyy.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/subjects/" + givenUser.getUuid() + "/permissions")
|
||||
@@ -359,7 +363,7 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer pac-admin-yyy00@yyy.example.com")
|
||||
.header("Authorization", bearer("pac-admin-yyy00@yyy.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac/subjects/" + givenUser.getUuid() + "/permissions")
|
||||
@@ -381,9 +385,9 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
final var givenUser = givenANewUser();
|
||||
|
||||
// @formatter:off
|
||||
final var location = RestAssured
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer " + givenUser.getName())
|
||||
.header("Authorization", bearer(givenUser.getName()))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/rbac/subjects/" + givenUser.getUuid())
|
||||
@@ -402,9 +406,9 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
final var givenUser = givenANewUser();
|
||||
|
||||
// @formatter:off
|
||||
final var location = RestAssured
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer customer-admin@xxx.example.com")
|
||||
.header("Authorization", bearer("customer-admin@xxx.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/rbac/subjects/" + givenUser.getUuid())
|
||||
@@ -424,9 +428,9 @@ class RbacSubjectControllerAcceptanceTest {
|
||||
final var givenUser = givenANewUser();
|
||||
|
||||
// @formatter:off
|
||||
final var location = RestAssured
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/rbac/subjects/" + givenUser.getUuid())
|
||||
|
||||
+10
-5
@@ -1,23 +1,24 @@
|
||||
package net.hostsharing.hsadminng.rbac.subject;
|
||||
|
||||
import net.hostsharing.hsadminng.config.MessageTranslator;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.config.WebSecurityConfigForWebMvcTests;
|
||||
import net.hostsharing.hsadminng.mapper.StrictMapper;
|
||||
import net.hostsharing.hsadminng.persistence.EntityManagerWrapper;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -29,8 +30,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(RbacSubjectController.class)
|
||||
@Import({StrictMapper.class, DisableSecurityConfig.class, MessageTranslator.class})
|
||||
@ActiveProfiles("test")
|
||||
@Import({ StrictMapper.class,
|
||||
MessageTranslator.class,
|
||||
WebSecurityConfigForWebMvcTests.class })
|
||||
@ActiveProfiles({"fake-jwt", "test"})
|
||||
class RbacSubjectControllerRestTest {
|
||||
|
||||
@Autowired
|
||||
@@ -60,6 +63,7 @@ class RbacSubjectControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/rbac/subjects")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
@@ -82,6 +86,7 @@ class RbacSubjectControllerRestTest {
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/api/rbac/subjects")
|
||||
.header("Authorization", bearer("selfregistered-user-drew@hostsharing.org"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.rbac.subject;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
|
||||
import net.hostsharing.hsadminng.mapper.Array;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
|
||||
+13
-14
@@ -3,9 +3,8 @@ package net.hostsharing.hsadminng.rbac.test.cust;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@@ -22,16 +21,16 @@ import jakarta.persistence.PersistenceContext;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@Tag("generalIntegrationTest")
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class, JpaAttempt.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
@Transactional
|
||||
@Tag("generalIntegrationTest")
|
||||
class TestCustomerControllerAcceptanceTest {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -59,7 +58,7 @@ class TestCustomerControllerAcceptanceTest {
|
||||
void globalAdmin_withoutAssumedRoles_canViewAllCustomers_ifNoCriteriaGiven() {
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/test/customers")
|
||||
@@ -77,7 +76,7 @@ class TestCustomerControllerAcceptanceTest {
|
||||
void globalAdmin_withoutAssumedRoles_canViewMatchingCustomers_ifCriteriaGiven() {
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/test/customers?prefix=y")
|
||||
@@ -93,7 +92,7 @@ class TestCustomerControllerAcceptanceTest {
|
||||
void globalAdmin_withoutAssumedCustomerAdminRole_canOnlyViewOwnCustomer() {
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.customer#yyy:ADMIN")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -110,7 +109,7 @@ class TestCustomerControllerAcceptanceTest {
|
||||
void customerAdmin_withoutAssumedRole_canOnlyViewOwnCustomer() {
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer customer-admin@yyy.example.com")
|
||||
.header("Authorization", bearer("customer-admin@yyy.example.com"))
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/test/customers")
|
||||
@@ -131,7 +130,7 @@ class TestCustomerControllerAcceptanceTest {
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -163,7 +162,7 @@ class TestCustomerControllerAcceptanceTest {
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.customer#xxx:ADMIN")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -194,7 +193,7 @@ class TestCustomerControllerAcceptanceTest {
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer customer-admin@yyy.example.com")
|
||||
.header("Authorization", bearer("customer-admin@yyy.example.com"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
@@ -224,7 +223,7 @@ class TestCustomerControllerAcceptanceTest {
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{]") // deliberately invalid JSON
|
||||
.port(port)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.rbac.test.cust;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
|
||||
+12
-13
@@ -3,8 +3,7 @@ package net.hostsharing.hsadminng.rbac.test.pac;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.config.DisableSecurityConfig;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
@@ -19,17 +18,17 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import static net.hostsharing.hsadminng.config.JwtFakeBearer.bearer;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
@Tag("generalIntegrationTest")
|
||||
@Transactional
|
||||
@SpringBootTest(
|
||||
webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, DisableSecurityConfig.class }
|
||||
)
|
||||
@ActiveProfiles("test")
|
||||
@Transactional
|
||||
@Tag("generalIntegrationTest")
|
||||
classes = HsadminNgApplication.class)
|
||||
@ActiveProfiles("fake-jwt")
|
||||
class TestPackageControllerAcceptanceTest {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -48,7 +47,7 @@ class TestPackageControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.customer#xxx:ADMIN")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -70,7 +69,7 @@ class TestPackageControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.customer#xxx:ADMIN")
|
||||
.port(port)
|
||||
.when()
|
||||
@@ -99,7 +98,7 @@ class TestPackageControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.customer#xxx:ADMIN")
|
||||
.contentType(ContentType.JSON)
|
||||
.body(format("""
|
||||
@@ -130,7 +129,7 @@ class TestPackageControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.customer#xxx:ADMIN")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
@@ -160,7 +159,7 @@ class TestPackageControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.customer#xxx:ADMIN")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{}")
|
||||
@@ -180,7 +179,7 @@ class TestPackageControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
return UUID.fromString(RestAssured
|
||||
.given()
|
||||
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
|
||||
.header("Authorization", bearer("superuser-alex@hostsharing.net"))
|
||||
.header("assumed-roles", "rbactest.customer#xxx:ADMIN")
|
||||
.port(port)
|
||||
.when()
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.rbac.test.pac;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.Context;
|
||||
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
|
||||
@@ -46,12 +46,9 @@ logging:
|
||||
# just for the case there are problems with Testcontainers/Docker integration
|
||||
# org.testcontainers: DEBUG
|
||||
# com.github.dockerjava: DEBUG
|
||||
# org.springframework.security: DEBUG
|
||||
|
||||
testcontainers:
|
||||
network:
|
||||
mode: host
|
||||
|
||||
hsadminng:
|
||||
cas:
|
||||
server: http://localhost:8088/cas # mocked via WireMock
|
||||
service: http://localhost:8080/api # must match service used in WireMock mock response
|
||||
|
||||
Reference in New Issue
Block a user