Search in sources :

Example 1 with RejectAllHandler

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));
}
Also used : RejectAllHandler(org.forgerock.openam.radius.server.spi.handlers.RejectAllHandler) InetSocketAddress(java.net.InetSocketAddress) EventBus(org.forgerock.guava.common.eventbus.EventBus) ByteBuffer(java.nio.ByteBuffer) AccessReject(org.forgerock.openam.radius.common.AccessReject) ClientConfig(org.forgerock.openam.radius.server.config.ClientConfig) Test(org.testng.annotations.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 EventBus (org.forgerock.guava.common.eventbus.EventBus)1 AccessReject (org.forgerock.openam.radius.common.AccessReject)1 ClientConfig (org.forgerock.openam.radius.server.config.ClientConfig)1 RejectAllHandler (org.forgerock.openam.radius.server.spi.handlers.RejectAllHandler)1 Test (org.testng.annotations.Test)1