Search in sources :

Example 1 with AcceptAllHandler

use of org.forgerock.openam.radius.server.spi.handlers.AcceptAllHandler in project OpenAM by OpenRock.

the class RadiusRequestHandlerTest method testRun.

/**
     * Test that when run is called with an AcceptAllHandler then the RadiusAuthResponse contains a success code and an
     * AcceptResponse is sent.
     *
     * @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 testRun() 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");
    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 AcceptAllHandler());
    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_ACCEPT);
    verify(reqCtx, times(1)).send(isA(AccessAccept.class));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EventBus(org.forgerock.guava.common.eventbus.EventBus) AcceptAllHandler(org.forgerock.openam.radius.server.spi.handlers.AcceptAllHandler) ByteBuffer(java.nio.ByteBuffer) ClientConfig(org.forgerock.openam.radius.server.config.ClientConfig) AccessAccept(org.forgerock.openam.radius.common.AccessAccept) Test(org.testng.annotations.Test)

Aggregations

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