Fix oneof field validation

This commit is contained in:
Ravi Khadiwala
2026-03-03 12:08:10 -06:00
committed by ravi-signal
parent f5f217f3de
commit a90fa5db02
5 changed files with 43 additions and 9 deletions

View File

@@ -5,6 +5,7 @@
package org.whispersystems.textsecuregcm.grpc;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.protobuf.ByteString;
@@ -406,6 +407,22 @@ public class ValidatingInterceptorTest {
stub.validationsEndpoint(builderWithValidDefaults().setRecursiveMessage(recursiveMessage).build()));
}
@Test
public void oneOfValidation() throws Exception {
// These should pass even if we don't meet the requirements on the one-of case that we're not setting
assertDoesNotThrow(() ->
stub.validationsEndpoint(builderWithValidDefaults()
.setOneOfNonEmptyBytes(ByteString.copyFrom(new byte[1]))
.build()));
assertDoesNotThrow(() ->
stub.validationsEndpoint(builderWithValidDefaults()
.setOneOfMessage(ValidationsRequest.RequirePresentMessage.getDefaultInstance())
.build()));
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(ValidationsRequest.newBuilder().setOneOfNonEmptyBytes(ByteString.EMPTY).build()));
}
@Nonnull
private static ValidationsRequest.Builder builderWithValidDefaults() {
return ValidationsRequest.newBuilder()