コード例 #1
0
  /**
   * 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());
  }
コード例 #2
0
  /**
   * 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());
  }
コード例 #3
0
  /**
   * 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);
  }
コード例 #4
0
  private ProcessorDTO createProcessor(final String token) throws Exception {
    String url = BASE_URL + "/process-groups/root/processors";

    // authorization header
    Map<String, String> headers = new HashMap<>();
    headers.put("Authorization", "Bearer " + token);

    // create the processor
    ProcessorDTO processor = new ProcessorDTO();
    processor.setName("Copy");
    processor.setType(SourceTestProcessor.class.getName());

    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(CLIENT_ID);
    revision.setVersion(0l);

    // create the entity body
    ProcessorEntity entity = new ProcessorEntity();
    entity.setRevision(revision);
    entity.setComponent(processor);

    // perform the request
    ClientResponse response = TOKEN_USER.testPostWithHeaders(url, entity, headers);

    // ensure the request is successful
    Assert.assertEquals(201, response.getStatus());

    // get the entity body
    entity = response.getEntity(ProcessorEntity.class);

    // verify creation
    processor = entity.getComponent();
    Assert.assertEquals("Copy", processor.getName());
    Assert.assertEquals(
        "org.apache.nifi.integration.util.SourceTestProcessor", processor.getType());

    return processor;
  }
コード例 #5
0
  /**
   * Test getting access configuration.
   *
   * @throws Exception ex
   */
  @Test
  public void testGetAccessConfig() throws Exception {
    String url = BASE_URL + "/access/config";

    ClientResponse response = TOKEN_USER.testGet(url);

    // ensure the request is successful
    Assert.assertEquals(200, response.getStatus());

    // extract the process group
    AccessConfigurationEntity accessConfigEntity =
        response.getEntity(AccessConfigurationEntity.class);

    // ensure there is content
    Assert.assertNotNull(accessConfigEntity);

    // extract the process group dto
    AccessConfigurationDTO accessConfig = accessConfigEntity.getConfig();

    // verify config
    Assert.assertTrue(accessConfig.getSupportsLogin());
  }