use of org.forgerock.openam.radius.server.spi.handlers.RejectAllHandler in project OpenAM by OpenRock.
the class RadiusRequestHandlerTest method testRunReject.
/**
* Test that when run is called with an RejectAllHandler that the resultant promise returns a RadiusResponse
* containing an ACCESS_REJECT packet.
*
* @throws InterruptedException - when an interrupt occurs.
* @throws RadiusProcessingException - when something goes wrong processing a RADIUS packet.
* @throws UnknownHostException - if the host can't be determined
*/
@Test(enabled = true)
public void testRunReject() throws UnknownHostException, InterruptedException, RadiusProcessingException {
// given
final RadiusRequestContext reqCtx = mock(RadiusRequestContext.class);
final ClientConfig clientConfig = mock(ClientConfig.class);
String url = "forgerock.org";
InetSocketAddress socketAddress = new InetSocketAddress(Inet4Address.getByName(url), 6836);
when(reqCtx.getClientConfig()).thenReturn(clientConfig);
when(reqCtx.getSource()).thenReturn(socketAddress);
when(clientConfig.getName()).thenReturn("TestConfig");
when(clientConfig.getAccessRequestHandlerClass()).thenReturn(RejectAllHandler.class);
final ByteBuffer bfr = Utils.toBuffer(res);
final PromiseImpl<RadiusResponse, RadiusProcessingException> promise = PromiseImpl.create();
EventBus eventBus = new EventBus();
AccessRequestHandlerFactory accessRequestHandlerFactory = mock(AccessRequestHandlerFactory.class);
when(accessRequestHandlerFactory.getAccessRequestHandler(reqCtx)).thenReturn(new RejectAllHandler());
final RadiusRequestHandler handler = new RadiusRequestHandler(accessRequestHandlerFactory, reqCtx, bfr, promise, promise, eventBus);
handler.run();
// when
final RadiusResponse result = promise.getOrThrow();
// then
assertThat(result.getResponsePacket().getType()).isEqualTo(PacketType.ACCESS_REJECT);
verify(reqCtx, times(1)).send(isA(AccessReject.class));
}
Aggregations