Skip to content

Commit 77eb62e

Browse files
committed
apache#2 #implementation of Unit Tests for BookieAuthZFactory: Added check on connection peer authorized id
1 parent c945a5e commit 77eb62e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

bookkeeper-server/src/test/java/org/apache/bookkeeper/tls/BookieAuthZFactoryTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ public void testProviderInit() {
117117
callBackMock.getAuthCode()
118118
);
119119

120+
if (authConfig.shouldAuthenticate()) {
121+
Assert.assertNotEquals("The peer connection must have an authorized Id\n" +
122+
authConfig.toString(), connectionPeerMock.getAuthorizedId(), null);
123+
124+
String certRole = TestUtils.getRoles(authConfig.getAuthConfig())[0];
125+
Assert.assertEquals("Certificate roles must be equals", certRole, connectionPeerMock.getAuthorizedId().getName());
126+
}
127+
120128
} catch (Exception e) {
121129
Assert.assertTrue("No exception was expected" +
122130
", but " + e.getClass().getName() + " has been thrown\n" +

bookkeeper-server/src/test/java/org/apache/bookkeeper/tls/mocks/ConnectionPeerMock.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ public ConnectionPeerMock mock() throws MockException {
4545
mockValidConnectionSocket();
4646
// This changes the behaviour between *VALID* and *INVALID* instances
4747
Mockito.when(connectionPeerMock.getProtocolPrincipals()).thenReturn(certificatesMock.getMockCertificates());
48+
49+
Mockito.doAnswer(invocation -> {
50+
// Access the arguments passed to the method
51+
BookKeeperPrincipal bookKeeperInputPrincipal = invocation.getArgument(0);
52+
53+
Mockito.when(connectionPeerMock.getAuthorizedId()).thenReturn(bookKeeperInputPrincipal);
54+
55+
return null;
56+
}).when(connectionPeerMock).setAuthorizedId(any(BookKeeperPrincipal.class));
57+
4858
}
4959

5060
return this;

0 commit comments

Comments
 (0)