mirror of https://github.com/grpc/grpc-java.git
Fix flakey security policy tests. (#8550)
Using ShadowProcess to set the processes uID doesn't help since SecurityPolicies class fetches the ID in a static initializer, and it may have already been loaded. Instead, just rely on whatever the uID is already, and ensure the other UIDs we test with are offset from that first value.
This commit is contained in:
parent
5396a1de3d
commit
e244065b0c
|
@ -13,8 +13,6 @@ android {
|
|||
srcDirs += "${projectDir}/../core/src/test/java/"
|
||||
setIncludes(["io/grpc/internal/FakeClock.java",
|
||||
"io/grpc/binder/**"])
|
||||
exclude 'io/grpc/binder/ServerSecurityPolicyTest.java'
|
||||
exclude 'io/grpc/binder/SecurityPoliciesTest.java'
|
||||
}
|
||||
}
|
||||
androidTest {
|
||||
|
|
|
@ -18,27 +18,21 @@ package io.grpc.binder;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.os.Process;
|
||||
import io.grpc.Status;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.shadows.ShadowProcess;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class SecurityPoliciesTest {
|
||||
private static final int MY_UID = 1234;
|
||||
private static final int MY_UID = Process.myUid();
|
||||
private static final int OTHER_UID = MY_UID + 1;
|
||||
|
||||
private static final String PERMISSION_DENIED_REASONS = "some reasons";
|
||||
|
||||
private SecurityPolicy policy;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ShadowProcess.setUid(MY_UID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInternalOnly() throws Exception {
|
||||
policy = SecurityPolicies.internalOnly();
|
||||
|
|
|
@ -18,13 +18,12 @@ package io.grpc.binder;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.os.Process;
|
||||
import com.google.common.base.Function;
|
||||
import io.grpc.Status;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.shadows.ShadowProcess;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class ServerSecurityPolicyTest {
|
||||
|
@ -33,16 +32,11 @@ public final class ServerSecurityPolicyTest {
|
|||
private static final String SERVICE2 = "service_two";
|
||||
private static final String SERVICE3 = "service_three";
|
||||
|
||||
private static final int MY_UID = 1234;
|
||||
private static final int MY_UID = Process.myUid();
|
||||
private static final int OTHER_UID = MY_UID + 1;
|
||||
|
||||
ServerSecurityPolicy policy;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ShadowProcess.setUid(MY_UID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultInternalOnly() {
|
||||
policy = new ServerSecurityPolicy();
|
||||
|
|
Loading…
Reference in New Issue