use of org.eclipse.hono.auth.AuthoritiesImpl in project hono by eclipse.
the class SimpleAuthenticationServerTest method testProcessRemoteOpenAddsClientAuthorities.
@SuppressWarnings("unchecked")
private void testProcessRemoteOpenAddsClientAuthorities(final String version, final Handler<Map<Symbol, Object>> connectionPropertiesAssertion) {
final AuthoritiesImpl authorities = new AuthoritiesImpl();
authorities.addResource("telemetry/DEFAULT_TENANT", Activity.READ);
final HonoUser client = mock(HonoUser.class);
when(client.getAuthorities()).thenReturn(authorities);
when(client.getExpirationTime()).thenReturn(Instant.now().plusSeconds(60));
when(client.getName()).thenReturn("application X");
final Map<Symbol, Object> properties = Collections.singletonMap(AddressAuthzHelper.PROPERTY_CLIENT_VERSION, version);
final RecordImpl attachments = new RecordImpl();
final ProtonConnection con = mock(ProtonConnection.class);
when(con.getRemoteDesiredCapabilities()).thenReturn(new Symbol[] { AddressAuthzHelper.CAPABILITY_ADDRESS_AUTHZ });
when(con.attachments()).thenReturn(attachments);
when(con.getRemoteContainer()).thenReturn("client container");
when(con.getRemoteProperties()).thenReturn(properties);
Constants.setClientPrincipal(con, client);
final Vertx vertx = mock(Vertx.class);
final SimpleAuthenticationServer server = new SimpleAuthenticationServer();
server.init(vertx, mock(Context.class));
server.processRemoteOpen(con);
final ArgumentCaptor<Symbol[]> offeredCapabilitiesCaptor = ArgumentCaptor.forClass(Symbol[].class);
verify(con).setOfferedCapabilities(offeredCapabilitiesCaptor.capture());
assertThat(Arrays.stream(offeredCapabilitiesCaptor.getValue()).anyMatch(symbol -> symbol.equals(AddressAuthzHelper.CAPABILITY_ADDRESS_AUTHZ))).isTrue();
final ArgumentCaptor<Map<Symbol, Object>> propsCaptor = ArgumentCaptor.forClass(Map.class);
verify(con).setProperties(propsCaptor.capture());
final Map<String, String[]> authz = (Map<String, String[]>) propsCaptor.getValue().get(AddressAuthzHelper.PROPERTY_ADDRESS_AUTHZ);
assertThat(authz).isNotNull();
assertThat(authz.get("telemetry/DEFAULT_TENANT")).isEqualTo(new String[] { "recv" });
connectionPropertiesAssertion.handle(propsCaptor.getValue());
}
Aggregations