Search in sources :

Example 11 with S3PropertiesLocation

use of org.finra.herd.model.api.xml.S3PropertiesLocation in project herd by FINRAOS.

the class JobServiceTest method testCreateJobWithS3PropertiesPrecedenceJobRequestS3OverridesDefinitionParams.

/**
 * Creates a job where the definition has S3 properties and parameters and request has S3 properties. The job create request's S3 properties should take
 * precedence if there are name clashes.
 *
 * @throws Exception
 */
@Test
public void testCreateJobWithS3PropertiesPrecedenceJobRequestS3OverridesDefinitionParams() throws Exception {
    Parameter jobDefinitionS3Parameter = new Parameter("testName", "testValue1");
    Parameter jobDefinitionRequestParameter = new Parameter("testName", "testValue2");
    Parameter jobCreateRequestS3Parameter = new Parameter("testName", "expectedValue");
    String s3BucketName = "s3BucketName";
    S3PropertiesLocation jobDefinitionS3PropertiesLocation = getS3PropertiesLocation(s3BucketName, "jobDefinitionObjectKey", jobDefinitionS3Parameter);
    S3PropertiesLocation jobCreateRequestS3PropertiesLocation = getS3PropertiesLocation(s3BucketName, "jobCreateRequestObjectKey", jobCreateRequestS3Parameter);
    Job resultJob = createJobWithParameters(jobDefinitionS3PropertiesLocation, Arrays.asList(jobDefinitionRequestParameter), jobCreateRequestS3PropertiesLocation, null);
    List<Parameter> actualParameters = resultJob.getParameters();
    assertParameterEquals(jobCreateRequestS3Parameter, actualParameters);
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) Parameter(org.finra.herd.model.api.xml.Parameter) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Example 12 with S3PropertiesLocation

use of org.finra.herd.model.api.xml.S3PropertiesLocation in project herd by FINRAOS.

the class JobServiceTest method getS3PropertiesLocation.

/**
 * Puts a Java properties into S3 where the key-value is the given parameter. Returns a {@link S3PropertiesLocation} with the S3 info.
 *
 * @param s3BucketName the S3 bucket name
 * @param s3ObjectKey the S3 object key
 * @param parameter the parameter
 *
 * @return the S3 properties location
 */
private S3PropertiesLocation getS3PropertiesLocation(String s3BucketName, String s3ObjectKey, Parameter parameter) {
    putParameterIntoS3(s3BucketName, s3ObjectKey, parameter);
    S3PropertiesLocation jobDefinitionS3PropertiesLocation = new S3PropertiesLocation();
    jobDefinitionS3PropertiesLocation.setBucketName(s3BucketName);
    jobDefinitionS3PropertiesLocation.setKey(s3ObjectKey);
    return jobDefinitionS3PropertiesLocation;
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation)

Example 13 with S3PropertiesLocation

use of org.finra.herd.model.api.xml.S3PropertiesLocation in project herd by FINRAOS.

the class JdbcServiceTest method testExecuteJdbcParamValidationS3PropertiesLocationKeyBlank.

/**
 * When S3 properties location is specified, object key must not be a blank string.
 */
@Test
public void testExecuteJdbcParamValidationS3PropertiesLocationKeyBlank() {
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.setS3PropertiesLocation(new S3PropertiesLocation("test_bucket", BLANK_TEXT));
    try {
        jdbcService.executeJdbc(jdbcExecutionRequest);
        Assert.fail("expected an IllegalArgumentException, but no exception was thrown");
    } catch (Exception e) {
        Assert.assertEquals("thrown exception type", IllegalArgumentException.class, e.getClass());
        Assert.assertEquals("thrown exception message", "S3 properties location key is required", e.getMessage());
    }
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) Test(org.junit.Test)

Example 14 with S3PropertiesLocation

use of org.finra.herd.model.api.xml.S3PropertiesLocation in project herd by FINRAOS.

the class JdbcServiceTest method testExecuteJdbcSensitiveDataIsMaskedInErrorMessage.

/**
 * Some JDBC exception messages echoes back parts of the SQL statement. This is problem for security if some of the variables were replaced, and may
 * accidentally expose secret information in the response error message. The application should mask any values given in the properties which exist in the
 * exception message.
 * <p/>
 * This test will use a SQL that will throw an exception, and the exception message is known. Then asserts that the value has been replaced with a mask in
 * the response error message.
 */
@Test
public void testExecuteJdbcSensitiveDataIsMaskedInErrorMessage() {
    String s3BucketName = "test_bucket";
    String s3ObjectKey = "test_key";
    String content = "foo=DataIntegrityViolationException";
    putS3Object(s3BucketName, s3ObjectKey, content);
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.getStatements().get(0).setSql(MockJdbcOperations.CASE_2_SQL);
    jdbcExecutionRequest.setS3PropertiesLocation(new S3PropertiesLocation(s3BucketName, s3ObjectKey));
    JdbcExecutionResponse jdbcExecutionResponse = jdbcService.executeJdbc(jdbcExecutionRequest);
    Assert.assertEquals("jdbc execution response statement [0] error message", "java.sql.SQLException: test **** cause", jdbcExecutionResponse.getStatements().get(0).getErrorMessage());
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) JdbcExecutionResponse(org.finra.herd.model.api.xml.JdbcExecutionResponse) Test(org.junit.Test)

Example 15 with S3PropertiesLocation

use of org.finra.herd.model.api.xml.S3PropertiesLocation in project herd by FINRAOS.

the class JdbcServiceTest method testExecuteJdbcWithS3PropertiesParamUrlBlankAfterReplace.

/**
 * If the result of replacing URL using S3 properties is blank, throws a validation error.
 */
@Test
public void testExecuteJdbcWithS3PropertiesParamUrlBlankAfterReplace() {
    String s3BucketName = "test_bucket";
    String s3ObjectKey = "test_key";
    String content = "foo=";
    putS3Object(s3BucketName, s3ObjectKey, content);
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.getConnection().setUrl("${foo}");
    jdbcExecutionRequest.setS3PropertiesLocation(new S3PropertiesLocation(s3BucketName, s3ObjectKey));
    try {
        jdbcService.executeJdbc(jdbcExecutionRequest);
        Assert.fail("expected an IllegalArgumentException, but no exception was thrown");
    } catch (Exception e) {
        Assert.assertEquals("thrown exception type", IllegalArgumentException.class, e.getClass());
        Assert.assertEquals("thrown exception message", "JDBC connection URL is required", e.getMessage());
    }
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) Test(org.junit.Test)

Aggregations

S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)33 Test (org.junit.Test)26 Parameter (org.finra.herd.model.api.xml.Parameter)13 Job (org.finra.herd.model.api.xml.Job)7 JdbcExecutionRequest (org.finra.herd.model.api.xml.JdbcExecutionRequest)6 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)5 AccessDeniedException (org.springframework.security.access.AccessDeniedException)5 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)4 JdbcExecutionResponse (org.finra.herd.model.api.xml.JdbcExecutionResponse)3 JobDefinitionCreateRequest (org.finra.herd.model.api.xml.JobDefinitionCreateRequest)3 JobSignalRequest (org.finra.herd.model.api.xml.JobSignalRequest)3 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)3 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)3 HashMap (java.util.HashMap)2 JdbcStatement (org.finra.herd.model.api.xml.JdbcStatement)2 JobDefinitionUpdateRequest (org.finra.herd.model.api.xml.JobDefinitionUpdateRequest)2 JobDefinitionParameterEntity (org.finra.herd.model.jpa.JobDefinitionParameterEntity)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 DataSource (javax.sql.DataSource)1