/** * Verifies the response when bad credentials are specified. * * @throws Exception ex */ @Test public void testInvalidCredentials() throws Exception { String url = BASE_URL + "/access/token"; ClientResponse response = TOKEN_USER.testCreateToken(url, "user@nifi", "not a real password"); // ensure the request is successful Assert.assertEquals(400, response.getStatus()); }
/** * Obtains a token and creates a processor using it. * * @throws Exception ex */ @Test public void testCreateProcessorUsingToken() throws Exception { String url = BASE_URL + "/access/token"; ClientResponse response = TOKEN_USER.testCreateToken(url, "user@nifi", "whateve"); // ensure the request is successful Assert.assertEquals(201, response.getStatus()); // get the token String token = response.getEntity(String.class); // attempt to create a processor with it createProcessor(token); }
/** * Request access using access token. * * @throws Exception ex */ @Test public void testRequestAccessUsingToken() throws Exception { String accessStatusUrl = BASE_URL + "/access"; String accessTokenUrl = BASE_URL + "/access/token"; ClientResponse response = TOKEN_USER.testGet(accessStatusUrl); // ensure the request is successful Assert.assertEquals(200, response.getStatus()); AccessStatusEntity accessStatusEntity = response.getEntity(AccessStatusEntity.class); AccessStatusDTO accessStatus = accessStatusEntity.getAccessStatus(); // verify unknown Assert.assertEquals("UNKNOWN", accessStatus.getStatus()); response = TOKEN_USER.testCreateToken(accessTokenUrl, "unregistered-user@nifi", "password"); // ensure the request is successful Assert.assertEquals(201, response.getStatus()); // get the token String token = response.getEntity(String.class); // authorization header Map<String, String> headers = new HashMap<>(); headers.put("Authorization", "Bearer " + token); // check the status with the token response = TOKEN_USER.testGetWithHeaders(accessStatusUrl, null, headers); // ensure the request is successful Assert.assertEquals(200, response.getStatus()); accessStatusEntity = response.getEntity(AccessStatusEntity.class); accessStatus = accessStatusEntity.getAccessStatus(); // verify unregistered Assert.assertEquals("ACTIVE", accessStatus.getStatus()); }