1
0

defineContext now requires an existing user name or null to create a new user

This commit is contained in:
Michael Hoennig
2022-08-31 16:26:31 +02:00
parent 8731f4a7b2
commit a06feff42e
8 changed files with 28 additions and 27 deletions

View File

@@ -69,16 +69,16 @@ class ContextIntegrationTests {
}
@Test
void defineWithUnknownCurrentUserButWithAssumedRoles() {
void defineWithUnknownCurrentUser() {
// when
final var result = jpaAttempt.transacted(() ->
context.define("unknown@example.org", "test_package#yyy00.admin")
context.define("unknown@example.org")
);
// then
result.assertExceptionWithRootCauseMessage(
javax.persistence.PersistenceException.class,
"ERROR: [403] undefined has no permission to assume role test_package#yyy00.admin");
"[401] user unknown@example.org given in `defineContext(...)` does not exist");
}
@Test

View File

@@ -492,7 +492,7 @@ class RbacGrantControllerAcceptanceTest extends ContextBasedTest {
RbacUserEntity createRBacUser() {
return jpaAttempt.transacted(() -> {
final String newUserName = "test-user-" + RandomStringUtils.randomAlphabetic(8) + "@example.com";
context(newUserName, null);
context(null);
return rbacUserRepository.create(new RbacUserEntity(UUID.randomUUID(), newUserName));
}).returnedValue();
}

View File

@@ -300,7 +300,7 @@ class RbacGrantRepositoryIntegrationTest extends ContextBasedTest {
private RbacUserEntity createNewUserTransacted() {
return jpaAttempt.transacted(() -> {
final var newUserName = "test-user-" + System.currentTimeMillis() + "@example.com";
context(newUserName);
context(null);
return rbacUserRepository.create(new RbacUserEntity(null, newUserName));
}).assumeSuccessful().returnedValue();
}

View File

@@ -138,8 +138,8 @@ class RbacRoleRepositoryIntegrationTest {
}
@Test
void unknownUser_withoutAssumedRole_cannotViewAnyRbacRoles() {
context.define("unknown@example.org");
void anonymousUser_withoutAssumedRole_cannotViewAnyRbacRoles() {
context.define(null);
final var result = attempt(
em,
@@ -147,7 +147,7 @@ class RbacRoleRepositoryIntegrationTest {
result.assertExceptionWithRootCauseMessage(
JpaSystemException.class,
"[401] currentSubjectsUuids () cannot be determined, unknown user name \"unknown@example.org\"");
"[401] currentSubjectsUuids cannot be determined, please call `defineContext(...)` with a valid user");
}
}

View File

@@ -51,21 +51,21 @@ class RbacUserControllerAcceptanceTest {
// @formatter:off
final var location = RestAssured
.given()
.contentType(ContentType.JSON)
.body("""
{
"name": "new-user@example.com"
}
""")
.port(port)
.contentType(ContentType.JSON)
.body("""
{
"name": "new-user@example.com"
}
""")
.port(port)
.when()
.post("http://localhost/api/rbac-users")
.post("http://localhost/api/rbac-users")
.then().assertThat()
.statusCode(201)
.contentType(ContentType.JSON)
.body("name", is("new-user@example.com"))
.header("Location", startsWith("http://localhost"))
.extract().header("Location");
.statusCode(201)
.contentType(ContentType.JSON)
.body("name", is("new-user@example.com"))
.header("Location", startsWith("http://localhost"))
.extract().header("Location");
// @formatter:on
// finally, the user can view its own record

View File

@@ -47,7 +47,7 @@ class RbacUserRepositoryIntegrationTest extends ContextBasedTest {
public void anyoneCanCreateTheirOwnUser() {
// given
final var givenNewUserName = "test-user-" + System.currentTimeMillis() + "@example.com";
context(givenNewUserName, null);
context(null);
// when
final var result = rbacUserRepository.create(