Package com.starlight.intrepid.auth

Examples of com.starlight.intrepid.auth.TokenReconnectAuthenticationHandler


  public void testTokenReconnection() throws Exception {
    // Make sure we test the full stack. See comment on
    // "Intrepid.disable_inter_instance_bridge" for more info.
    IntrepidTesting.setInterInstanceBridgeDisabled( true );

    TokenReconnectAuthenticationHandler mock_auth_handler =
      createMock( TokenReconnectAuthenticationHandler.class );

    UserContextInfo test_info = new SimpleUserContextInfo( "test_user" );

    // Mock for first call - no token should be provided
    expect( mock_auth_handler.checkConnection( EasyMock.<ConnectionArgs>isNull(),
      EasyMock.<SocketAddress>notNull(), EasyMock.<SocketAddress>notNull(),
      EasyMock.<ConnectionArgs>isNull() ) ).andReturn( test_info );
    expect( mock_auth_handler.generateReconnectToken( eq( test_info ),
      EasyMock.<ConnectionArgs>isNull(),
      EasyMock.<SocketAddress>notNull(), EasyMock.<SocketAddress>notNull(),
      EasyMock.<ConnectionArgs>isNull() ) ).andReturn( "my test token" );
    expect( Integer.valueOf(
      mock_auth_handler.getTokenRegenerationInterval() ) ).andReturn(
      Integer.valueOf( 2 ) );
    expect( mock_auth_handler.generateReconnectToken( eq( test_info ),
      EasyMock.<ConnectionArgs>isNull(),
      EasyMock.<SocketAddress>notNull(), EasyMock.<SocketAddress>notNull(),
      eq( "my test token" ) ) ).andReturn( "my test token - TWO" );
    expect( Integer.valueOf(
      mock_auth_handler.getTokenRegenerationInterval() ) ).andReturn(
      Integer.valueOf( 2 ) );
    expect( mock_auth_handler.generateReconnectToken( eq( test_info ),
      EasyMock.<ConnectionArgs>isNull(),
      EasyMock.<SocketAddress>notNull(), EasyMock.<SocketAddress>notNull(),
      eq( "my test token - TWO" ) ) ).andReturn( "my test token - THREE" );
    expect( Integer.valueOf(
      mock_auth_handler.getTokenRegenerationInterval() ) ).andReturn(
      Integer.valueOf( 2 ) );

    replay( mock_auth_handler );

    IntrepidSetup setup = new IntrepidSetup();
    setup.authHandler( mock_auth_handler );
    setup.serverPort( 0 );
    server_instance = Intrepid.create( setup );
    Integer port = server_instance.getServerPort();
    assertNotNull( port );

    client_instance = Intrepid.create( null );
    VMID server_vmid = client_instance.connect( InetAddress.getLocalHost(),
      port.intValue(), null, null );
    assertEquals( server_instance.getLocalVMID(), server_vmid );

    CommTest.ServerImpl server_impl =
      new CommTest.ServerImpl( true, server_instance.getLocalVMID() );
    server_instance.getLocalRegistry().bind( "server", server_impl );

    CommTest.Server proxy = ( CommTest.Server ) client_instance.getRemoteRegistry(
      server_vmid ).lookup( "server" );

    // Make a call... should work
    proxy.getMessage();

    ThreadKit.sleep( 5000 );    // time to regen two session tokens

    // Shut down the server
    server_instance.close();
    System.out.println( "server instance closed" );

    // Make sure checkConnection was called once and only once
    verify( mock_auth_handler );

    // Mock for second call - token SHOULD be provided
    reset( mock_auth_handler );
    expect( mock_auth_handler.checkConnection( EasyMock.<ConnectionArgs>isNull(),
      EasyMock.<SocketAddress>notNull(), EasyMock.<SocketAddress>notNull(),
      eq( "my test token - THREE" ) ) ).andReturn( test_info );
    expect( mock_auth_handler.generateReconnectToken( eq( test_info ),
      EasyMock.<ConnectionArgs>isNull(), EasyMock.<SocketAddress>notNull(),
      EasyMock.<SocketAddress>notNull(), eq( "my test token - THREE" ) ) )
      .andReturn( "my NEW test token" );
    expect( Integer.valueOf(
      mock_auth_handler.getTokenRegenerationInterval() ) ).andReturn(
      Integer.valueOf( 60 ) );

    replay( mock_auth_handler );

View Full Code Here

TOP

Related Classes of com.starlight.intrepid.auth.TokenReconnectAuthenticationHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.