diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RemoteConfigController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RemoteConfigController.java index 2277e6515..3a454243d 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RemoteConfigController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RemoteConfigController.java @@ -40,6 +40,8 @@ public class RemoteConfigController { private final List configAuthTokens; private final Map globalConfig; + private static final String GLOBAL_CONFIG_PREFIX = "global."; + public RemoteConfigController(RemoteConfigsManager remoteConfigsManager, List configAuthTokens, Map globalConfig) { this.remoteConfigsManager = remoteConfigsManager; this.configAuthTokens = configAuthTokens; @@ -54,7 +56,7 @@ public class RemoteConfigController { try { MessageDigest digest = MessageDigest.getInstance("SHA1"); - final Stream globalConfigStream = globalConfig.entrySet().stream().map(entry -> new UserRemoteConfig("g." + entry.getKey(), true, entry.getValue())); + final Stream globalConfigStream = globalConfig.entrySet().stream().map(entry -> new UserRemoteConfig(GLOBAL_CONFIG_PREFIX + entry.getKey(), true, entry.getValue())); return new UserRemoteConfigList(Stream.concat(remoteConfigsManager.getAll().stream().map(config -> { final byte[] hashKey = config.getHashKey() != null ? config.getHashKey().getBytes(StandardCharsets.UTF_8) : config.getName().getBytes(StandardCharsets.UTF_8); boolean inBucket = isInBucket(digest, account.getUuid(), hashKey, config.getPercentage(), config.getUuids()); @@ -74,7 +76,7 @@ public class RemoteConfigController { throw new WebApplicationException(Response.Status.UNAUTHORIZED); } - if (config.getName().startsWith("g.")) { + if (config.getName().startsWith(GLOBAL_CONFIG_PREFIX)) { throw new WebApplicationException(Response.Status.FORBIDDEN); } @@ -89,7 +91,7 @@ public class RemoteConfigController { throw new WebApplicationException(Response.Status.UNAUTHORIZED); } - if (name.startsWith("g.")) { + if (name.startsWith(GLOBAL_CONFIG_PREFIX)) { throw new WebApplicationException(Response.Status.FORBIDDEN); } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/RemoteConfigControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/RemoteConfigControllerTest.java index 608c5f087..506e22031 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/RemoteConfigControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/RemoteConfigControllerTest.java @@ -100,7 +100,7 @@ public class RemoteConfigControllerTest { assertThat(configuration.getConfig().get(7).getName()).isEqualTo("linked.config.0"); assertThat(configuration.getConfig().get(8).getName()).isEqualTo("linked.config.1"); assertThat(configuration.getConfig().get(9).getName()).isEqualTo("unlinked.config"); - assertThat(configuration.getConfig().get(10).getName()).isEqualTo("g.maxGroupSize"); + assertThat(configuration.getConfig().get(10).getName()).isEqualTo("global.maxGroupSize"); } @Test @@ -134,7 +134,7 @@ public class RemoteConfigControllerTest { assertThat(configuration.getConfig().get(7).getName()).isEqualTo("linked.config.0"); assertThat(configuration.getConfig().get(8).getName()).isEqualTo("linked.config.1"); assertThat(configuration.getConfig().get(9).getName()).isEqualTo("unlinked.config"); - assertThat(configuration.getConfig().get(10).getName()).isEqualTo("g.maxGroupSize"); + assertThat(configuration.getConfig().get(10).getName()).isEqualTo("global.maxGroupSize"); } @Test @@ -305,7 +305,7 @@ public class RemoteConfigControllerTest { .target("/v1/config") .request() .header("Config-Token", "foo") - .put(Entity.entity(new RemoteConfig("g.maxGroupSize", 88, Set.of(), "FALSE", "TRUE", null), MediaType.APPLICATION_JSON_TYPE)); + .put(Entity.entity(new RemoteConfig("global.maxGroupSize", 88, Set.of(), "FALSE", "TRUE", null), MediaType.APPLICATION_JSON_TYPE)); assertThat(response.getStatus()).isEqualTo(403); verifyNoMoreInteractions(remoteConfigsManager); } @@ -340,7 +340,7 @@ public class RemoteConfigControllerTest { @Test public void testDeleteGlobalConfig() { Response response = resources.getJerseyTest() - .target("/v1/config/g.maxGroupSize") + .target("/v1/config/global.maxGroupSize") .request() .header("Config-Token", "foo") .delete();