Arsnael commented on a change in pull request #678:
URL: https://github.com/apache/james-project/pull/678#discussion_r721009899
##########
File path:
server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/UserRoutesTest.java
##########
@@ -573,6 +581,38 @@ void
puttingWithDomainPartInUsernameTwoTimesShouldNotBeAllowed() {
assertThat(users).containsExactly(ImmutableMap.of("username",
USERNAME_WITH_DOMAIN.asString()));
}
+ @Test
+ void putShouldFailWhenConflictWithAlias(RecipientRewriteTable
recipientRewriteTable) throws Exception {
+
recipientRewriteTable.addAliasMapping(MappingSource.fromUser(USERNAME_WITH_DOMAIN),
+ OTHER_USERNAME_WITH_DOMAIN.asString());
+
+ given()
+ .body("{\"password\":\"password\"}")
+ .when()
+ .put(USERNAME_WITH_DOMAIN.asString())
+ .then()
+ .statusCode(HttpStatus.CONFLICT_409)
+ .body("statusCode", is(HttpStatus.CONFLICT_409))
+ .body("type",
is(ErrorResponder.ErrorType.WRONG_STATE.getType()))
+ .body("message", is("'username@domain' already have associated
mappings: alias:other@domain"));
+ }
+
+ @Test
+ void putShouldFailWhenConflictWithGroup(RecipientRewriteTable
recipientRewriteTable) throws Exception {
+
recipientRewriteTable.addGroupMapping(MappingSource.fromUser(USERNAME_WITH_DOMAIN),
+ OTHER_USERNAME_WITH_DOMAIN.asString());
+
+ given()
+ .body("{\"password\":\"password\"}")
+ .when()
+ .put(USERNAME_WITH_DOMAIN.asString())
+ .then()
+ .statusCode(HttpStatus.CONFLICT_409)
+ .body("statusCode", is(HttpStatus.CONFLICT_409))
+ .body("type",
is(ErrorResponder.ErrorType.WRONG_STATE.getType()))
+ .body("message", is("'username@domain' already have associated
mappings: group:other@domain"));
+ }
+
Review comment:
Where is the test for:
```
GIVEN a user [email protected]
WHEN I create the user [email protected]
THEN it fails
```
?
##########
File path:
server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/GroupsRoutesTest.java
##########
@@ -319,6 +324,26 @@ void putShouldDetectLoops() {
.containsEntry("message", "Creation of redirection of
[email protected] to group:[email protected] would lead to a loop, operation not
performed");
}
+ @Test
+ void putShouldNotConflictWithAlias() throws Exception {
+
memoryRecipientRewriteTable.addAliasMapping(MappingSource.fromUser(Username.of(GROUP1)),
USER_A);
+
+ Map<String, Object> errors = when()
+ .put(GROUP1 + SEPARATOR + USER_A)
+ .then()
+ .contentType(ContentType.JSON)
+ .statusCode(HttpStatus.CONFLICT_409)
+ .extract()
+ .body()
+ .jsonPath()
+ .getMap(".");
+
+ assertThat(errors)
+ .containsEntry("statusCode", HttpStatus.CONFLICT_409)
+ .containsEntry("type", "WrongState")
+ .containsEntry("message", "'[email protected]' already have
associated mappings: alias:[email protected]");
+ }
+
Review comment:
Where are tests for:
```
GIVEN a group [email protected]
WHEN I create the user [email protected]
THEN it fails
```
```
GIVEN a group [email protected]
WHEN I create the group [email protected]
THEN it fails
```
?
##########
File path:
server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AliasRoutesTest.java
##########
@@ -178,6 +185,26 @@ void putShouldDetectConflicts() {
.containsEntry("message", "Creation of redirection of
[email protected] to alias:[email protected] would lead to a loop, operation not
performed");
}
+ @Test
+ void putShouldDetectConflictsWithGroups() throws Exception {
+
memoryRecipientRewriteTable.addGroupMapping(MappingSource.fromUser(Username.of(ALICE_ALIAS)),
BOB);
+
+ Map<String, Object> errors = when()
+ .put(ALICE + SEPARATOR + "sources" + SEPARATOR +
ALICE_ALIAS)
+ .then()
+ .contentType(ContentType.JSON)
+ .statusCode(HttpStatus.BAD_REQUEST_400)
+ .extract()
+ .body()
+ .jsonPath()
+ .getMap(".");
+
+ assertThat(errors)
+ .containsEntry("statusCode", HttpStatus.BAD_REQUEST_400)
+ .containsEntry("type", "InvalidArgument")
+ .containsEntry("message", "'[email protected]' already have
associated mappings: group:[email protected]");
+ }
+
Review comment:
Where are the tests for:
```
GIVEN a user [email protected]
WHEN I create the alias [email protected]
THEN it fails
```
```
GIVEN an alias [email protected]
WHEN I create the alias [email protected]
THEN it fails
```
?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]