/** * Returns the full URL for the given request path */ protected URL getURL(String path) throws MalformedURLException { InetSocketAddress serverAddr = server.getSocketAddress(); while (path.startsWith("/")) { path = path.substring(1); } return new URL(String.format("%s://%s:%d/%s", getProtocol(), serverAddr.getHostName(), serverAddr.getPort(), path)); }
@BeforeClass public static void setup() throws IOException, InterruptedException { initAuthTestProps(); externalHandlerServer = injector.getInstance(ExternalHandlerServer.class); externalHandlerServer.startAndWait(); externalAuthenticationServer = injector.getInstance(ExternalAuthenticationServer.class); externalAuthenticationServer.startAndWait(); // Wait *SLEEP_TIME_IN_SEC* for the complete service start Thread.sleep(1000 * SLEEP_TIME_IN_SEC); testServerPort = externalHandlerServer.getBindAddress().getPort(); authURL = String.format("http://%s:%d/token", externalAuthenticationServer.getSocketAddress().getHostName(), externalAuthenticationServer.getSocketAddress().getPort()); }
/** * Test that the service is discoverable. * */ @Test public void testServiceRegistration() { Iterable<Discoverable> discoverables = discoveryServiceClient.discover(Constants.Service.EXTERNAL_AUTHENTICATION); Set<SocketAddress> addresses = Sets.newHashSet(); for (Discoverable discoverable : discoverables) { addresses.add(discoverable.getSocketAddress()); } Assert.assertTrue(addresses.contains(server.getSocketAddress())); } }
protected void setup() throws Exception { Assert.assertNotNull("CConfiguration needs to be set by derived classes", configuration); // Intentionally set "security.auth.server.announce.urls" to invalid // values verify that they are not used by external authentication server configuration.set(Constants.Security.AUTH_SERVER_ANNOUNCE_URLS, "invalid.urls"); Module securityModule = Modules.override(new SecurityModules().getInMemoryModules()).with( new AbstractModule() { @Override protected void configure() { bind(AuditLogHandler.class) .annotatedWith(Names.named( ExternalAuthenticationServer.NAMED_EXTERNAL_AUTH)) .toInstance(new AuditLogHandler(TEST_AUDIT_LOGGER)); } } ); Injector injector = Guice.createInjector(new IOModule(), securityModule, new ConfigModule(getConfiguration(configuration), HBaseConfiguration.create(), sConfiguration), new InMemoryDiscoveryModule()); server = injector.getInstance(ExternalAuthenticationServer.class); tokenCodec = injector.getInstance(AccessTokenCodec.class); discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class); startExternalAuthenticationServer(); server.startAndWait(); LOG.info("Auth server running on address {}", server.getSocketAddress()); TimeUnit.SECONDS.sleep(3); }