PeerAuth { boolean authorizePeer() { if (!attr.isEnabled(Attribute.RESTRICT_SERVLET)) { return true; } Iterable<PeerAuthenticator> peerAuthenticators = getPeerAuthenticatorInstances(); if (peerAuthenticators != null) { for (PeerAuthenticator peerAuthenticator : peerAuthenticators) { if (!peerAuthenticator.authenticate(request)) { return false; } } } return true; } @VisibleForTesting  PeerAuth(HttpServletRequest request); static PeerAuthenticator instantiatePeerAuthenticator(Class<? extends PeerAuthenticator> clazz);  }
@Test public void testPeerAuthorize_nonRestricted() throws Exception { attr.set(Attribute.RESTRICT_SERVLET, false); assertTrue(peerAuth.authorizePeer()); }
@Test public void testPeerAuthorize_pass() throws Exception { when(config.getPeerAuthenticators()).thenReturn( ImmutableList.<Class<? extends PeerAuthenticator>>of(PassPeerAuthenticator.class)); assertTrue(peerAuth.authorizePeer()); }
@Test public void testPeerAuthorize_fail() throws Exception { when(config.getPeerAuthenticators()).thenReturn( ImmutableList.<Class<? extends PeerAuthenticator>>of(FailPeerAuthenticator.class)); assertFalse(peerAuth.authorizePeer()); }
@Test public void testPeerAuthorize_passThenFail() throws Exception { when(config.getPeerAuthenticators()).thenReturn( ImmutableList.of(PassPeerAuthenticator.class, FailPeerAuthenticator.class)); assertFalse(peerAuth.authorizePeer()); }
@Test public void testPeerAuthorize_failThenPass() throws Exception { when(config.getPeerAuthenticators()).thenReturn( ImmutableList.of(FailPeerAuthenticator.class, PassPeerAuthenticator.class)); assertFalse(peerAuth.authorizePeer()); }