Unit tests for AltsContextUtil.
| 37 | |
| 38 | /** Unit tests for {@link AltsContextUtil}. */ |
| 39 | @RunWith(JUnit4.class) |
| 40 | public class AltsContextUtilTest { |
| 41 | @Test |
| 42 | public void check_noAttributeValue() { |
| 43 | assertFalse(AltsContextUtil.check(Attributes.newBuilder().build())); |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void check_unexpectedAttributeValueType() { |
| 48 | assertFalse(AltsContextUtil.check(Attributes.newBuilder() |
| 49 | .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, new Object()) |
| 50 | .build())); |
| 51 | } |
| 52 | |
| 53 | @Test |
| 54 | public void check_altsInternalContext() { |
| 55 | assertTrue(AltsContextUtil.check(Attributes.newBuilder() |
| 56 | .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, AltsInternalContext.getDefaultInstance()) |
| 57 | .build())); |
| 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void checkServer_altsInternalContext() { |
| 62 | ServerCall<?,?> call = mock(ServerCall.class); |
| 63 | when(call.getAttributes()).thenReturn(Attributes.newBuilder() |
| 64 | .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, AltsInternalContext.getDefaultInstance()) |
| 65 | .build()); |
| 66 | |
| 67 | assertTrue(AltsContextUtil.check(call)); |
| 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void checkClient_altsInternalContext() { |
| 72 | ClientCall<?,?> call = mock(ClientCall.class); |
| 73 | when(call.getAttributes()).thenReturn(Attributes.newBuilder() |
| 74 | .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, AltsInternalContext.getDefaultInstance()) |
| 75 | .build()); |
| 76 | |
| 77 | assertTrue(AltsContextUtil.check(call)); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void createFrom_altsInternalContext() { |
| 82 | HandshakerResult handshakerResult = |
| 83 | HandshakerResult.newBuilder() |
| 84 | .setPeerIdentity(Identity.newBuilder().setServiceAccount("remote@peer")) |
| 85 | .setLocalIdentity(Identity.newBuilder().setServiceAccount("local@peer")) |
| 86 | .build(); |
| 87 | |
| 88 | AltsContext context = AltsContextUtil.createFrom(Attributes.newBuilder() |
| 89 | .set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, new AltsInternalContext(handshakerResult)) |
| 90 | .build()); |
| 91 | assertEquals("remote@peer", context.getPeerServiceAccount()); |
| 92 | assertEquals("local@peer", context.getLocalServiceAccount()); |
| 93 | assertEquals(SecurityLevel.INTEGRITY_AND_PRIVACY, context.getSecurityLevel()); |
| 94 | } |
| 95 | |
| 96 | @Test(expected = IllegalArgumentException.class) |
nothing calls this directly
no outgoing calls
no test coverage detected