Skip to content

Commit

Permalink
changed TopicValidator on backend side
Browse files Browse the repository at this point in the history
  • Loading branch information
Diewa committed Jan 31, 2025
1 parent f562677 commit 1b9a044
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public void ensureUpdatedTopicIsValid(Topic updated, Topic previous, RequestUser
checkOwner(updated);
checkTopicLabels(updated);

if ((previous.isFallbackToRemoteDatacenterEnabled()
!= updated.isFallbackToRemoteDatacenterEnabled())
if (previous.isFallbackToRemoteDatacenterEnabled()
&& !updated.isFallbackToRemoteDatacenterEnabled()
&& !modifiedBy.isAdmin()) {
throw new TopicValidationException(
"User is not allowed to update fallback to remote datacenter for this topic");
"User is not allowed to disable fallback to remote datacenter for this topic");
}

if (!previous.getChaos().equals(updated.getChaos()) && !modifiedBy.isAdmin()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ public void shouldAllowAdminUserCreateTopicWithNonDefaultFallbackToRemoteDatacen
}

@Test
public void shouldNotAllowNonAdminUserToChangeFallbackToRemoteDatacenter() {
public void shouldNotAllowNonAdminUserToDisableFallbackToRemoteDatacenter() {
// given
Topic topic =
hermes
Expand All @@ -840,11 +840,32 @@ public void shouldNotAllowNonAdminUserToChangeFallbackToRemoteDatacenter() {
// then
response.expectStatus().isBadRequest();
assertThat(response.expectBody(String.class).returnResult().getResponseBody())
.contains("User is not allowed to update fallback to remote datacenter for this topic");
.contains("User is not allowed to disable fallback to remote datacenter for this topic");
}

@Test
public void shouldAllowAdminUserToChangeFallbackToRemoteDatacenter() {
public void shouldAllowNonAdminUserToEnableFallbackToRemoteDatacenter() {
// given
Topic topic =
hermes
.initHelper()
.createTopic(topicWithRandomName().build());
TestSecurityProvider.setUserIsAdmin(false);
PatchData patchData =
PatchData.from(ImmutableMap.of("fallbackToRemoteDatacenterEnabled", false));

// when
WebTestClient.ResponseSpec response =
hermes.api().updateTopic(topic.getQualifiedName(), patchData);

// then
response.expectStatus().isBadRequest();
assertThat(response.expectBody(String.class).returnResult().getResponseBody())
.contains("User is not allowed to disable fallback to remote datacenter for this topic");
}

@Test
public void shouldAllowAdminUserToDisableFallbackToRemoteDatacenter() {
// given
Topic topic =
hermes
Expand Down

0 comments on commit 1b9a044

Please sign in to comment.