public static String login(ServiceHost host, String username, String password) throws IOException { return login(host, username, password, false); }
protected static void assertClusterFromNodes(ManagementHost... hosts) throws Throwable { for (ManagementHost host : hosts) { String token = login(host, USERNAME, PASSWORD); assertNotNull(token); Map<String, String> headers = new HashMap<>(); headers.put(Operation.REQUEST_AUTH_TOKEN_HEADER, token); assertNodes(headers, hosts); } }
@Test public void testRestrictedOperationWithAuth() throws Throwable { String token = login(host, USERNAME, PASSWORD); assertNotNull(token); /* * This test sets the token as a header of the request, but it's possible also (and * recommended) to provide the token as a cookie if the client supports it * (e.g. any browser, Postman, HttpClient, etc.). */ Map<String, String> headers = new HashMap<>(); headers.put(Operation.REQUEST_AUTH_TOKEN_HEADER, token); int statusCode = doRestrictedOperation(host, headers); assertEquals("Operation should be OK!", HttpURLConnection.HTTP_OK, statusCode); }