mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 16:18:00 +01:00
support REST deprecation by platform for all requests with % rollout
This commit is contained in:
committed by
GitHub
parent
36439b5252
commit
2a7551cca5
@@ -6,6 +6,7 @@
|
||||
package org.whispersystems.textsecuregcm.filters;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -13,6 +14,7 @@ import com.google.common.net.HttpHeaders;
|
||||
import jakarta.ws.rs.WebApplicationException;
|
||||
import jakarta.ws.rs.core.SecurityContext;
|
||||
import java.net.URI;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import org.glassfish.jersey.server.ContainerRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -48,11 +50,13 @@ class RestDeprecationFilterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOldClient() throws Exception {
|
||||
void testOldClientAuthenticated() throws Exception {
|
||||
final DynamicConfiguration config = SystemMapper.yamlMapper().readValue(
|
||||
"""
|
||||
minimumRestFreeVersion:
|
||||
ANDROID: 200.0.0
|
||||
restDeprecation:
|
||||
platforms:
|
||||
ANDROID:
|
||||
minimumRestFreeVersion: 200.0.0
|
||||
experiments:
|
||||
restDeprecation:
|
||||
uuidEnrollmentPercentage: 100
|
||||
@@ -73,12 +77,42 @@ class RestDeprecationFilterTest {
|
||||
filter.filter(req);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBlocking() throws Exception {
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 99})
|
||||
void testOldClientUnauthenticated(int randomRoll) throws Exception {
|
||||
final DynamicConfiguration config = SystemMapper.yamlMapper().readValue(
|
||||
"""
|
||||
minimumRestFreeVersion:
|
||||
ANDROID: 10.10.10
|
||||
restDeprecation:
|
||||
platforms:
|
||||
ANDROID:
|
||||
minimumRestFreeVersion: 200.0.0
|
||||
universalRolloutPercent: 50
|
||||
experiments:
|
||||
restDeprecation:
|
||||
uuidEnrollmentPercentage: 100
|
||||
""",
|
||||
DynamicConfiguration.class);
|
||||
final DynamicConfigurationManager<DynamicConfiguration> dynamicConfigurationManager = new FakeDynamicConfigurationManager<>(config);
|
||||
final ExperimentEnrollmentManager experimentEnrollmentManager = new ExperimentEnrollmentManager(dynamicConfigurationManager);
|
||||
final Random fakeRandom = mock(Random.class);
|
||||
when(fakeRandom.nextInt(anyInt())).thenReturn(randomRoll);
|
||||
|
||||
final RestDeprecationFilter filter = new RestDeprecationFilter(dynamicConfigurationManager, experimentEnrollmentManager, () -> fakeRandom);
|
||||
|
||||
final ContainerRequest req = new ContainerRequest(null, new URI("/some/uri"), "GET", null, null, null);
|
||||
req.getHeaders().add(HttpHeaders.USER_AGENT, "Signal-Android/100.0.0");
|
||||
|
||||
filter.filter(req);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBlockingAuthenticated() throws Exception {
|
||||
final DynamicConfiguration config = SystemMapper.yamlMapper().readValue(
|
||||
"""
|
||||
restDeprecation:
|
||||
platforms:
|
||||
ANDROID:
|
||||
minimumRestFreeVersion: 10.10.10
|
||||
experiments:
|
||||
restDeprecation:
|
||||
enrollmentPercentage: 100
|
||||
@@ -108,4 +142,46 @@ class RestDeprecationFilterTest {
|
||||
assertThrows(WebApplicationException.class, () -> filter.filter(req));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 10, 20, 30, 40, 50, 60, 69, 70, 71, 80, 90, 99})
|
||||
void testBlockingUnauthenticated(int randomRoll) throws Exception {
|
||||
final DynamicConfiguration config = SystemMapper.yamlMapper().readValue(
|
||||
"""
|
||||
restDeprecation:
|
||||
platforms:
|
||||
ANDROID:
|
||||
minimumRestFreeVersion: 10.10.10
|
||||
universalRolloutPercent: 70
|
||||
""",
|
||||
DynamicConfiguration.class);
|
||||
final DynamicConfigurationManager<DynamicConfiguration> dynamicConfigurationManager = new FakeDynamicConfigurationManager<>(config);
|
||||
final ExperimentEnrollmentManager experimentEnrollmentManager = new ExperimentEnrollmentManager(dynamicConfigurationManager);
|
||||
final Random fakeRandom = mock(Random.class);
|
||||
when(fakeRandom.nextInt(anyInt())).thenReturn(randomRoll);
|
||||
|
||||
final RestDeprecationFilter filter = new RestDeprecationFilter(dynamicConfigurationManager, experimentEnrollmentManager, () -> fakeRandom);
|
||||
|
||||
final ContainerRequest req = new ContainerRequest(null, new URI("/some/path"), "GET", null, null, null);
|
||||
|
||||
req.getHeaders().putSingle(HttpHeaders.USER_AGENT, "Signal-Android/10.9.15");
|
||||
filter.filter(req);
|
||||
|
||||
req.getHeaders().putSingle(HttpHeaders.USER_AGENT, "Signal-Android/10.10.9");
|
||||
filter.filter(req);
|
||||
|
||||
req.getHeaders().putSingle(HttpHeaders.USER_AGENT, "Signal-Android/10.10.10");
|
||||
if (randomRoll < 70) {
|
||||
assertThrows(WebApplicationException.class, () -> filter.filter(req));
|
||||
} else {
|
||||
filter.filter(req);
|
||||
}
|
||||
|
||||
req.getHeaders().putSingle(HttpHeaders.USER_AGENT, "Signal-Android/100.0.0");
|
||||
if (randomRoll < 70) {
|
||||
assertThrows(WebApplicationException.class, () -> filter.filter(req));
|
||||
} else {
|
||||
filter.filter(req);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user