AccessValidatorController { void validateAccess(File propertiesFile, Boolean messageFlag) throws IOException, ApiException { propertiesHelper.loadProperties(propertiesFile); herdApiClientOperations.checkPropertiesFile(propertiesHelper, messageFlag); ApiClient apiClient = new ApiClient(); apiClient.setBasePath(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)); apiClient.setUsername(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)); apiClient.setPassword(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)); ApplicationApi applicationApi = new ApplicationApi(apiClient); CurrentUserApi currentUserApi = new CurrentUserApi(apiClient); LOGGER.info("Retrieving build information from the registration server..."); LOGGER.info("{}", herdApiClientOperations.applicationGetBuildInfo(applicationApi)); LOGGER.info("Retrieving user information from the registration server..."); LOGGER.info("{}", herdApiClientOperations.currentUserGetCurrentUser(currentUserApi)); ClientConfiguration clientConfiguration = new ClientConfiguration(); String awsRegion = propertiesHelper.getProperty(AWS_REGION_PROPERTY); String awsRoleArn = propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY); LOGGER.info("Assuming \"{}\" AWS role...", awsRoleArn); AWSCredentialsProvider awsCredentialsProvider = new STSAssumeRoleSessionCredentialsProvider.Builder(awsRoleArn, UUID.randomUUID().toString()) .withStsClient(AWSSecurityTokenServiceClientBuilder.standard().withClientConfiguration(clientConfiguration).withRegion(awsRegion).build()).build(); LOGGER.info("Creating AWS S3 client using role: \"{}\".", awsRoleArn); AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard().withCredentials(awsCredentialsProvider).withClientConfiguration(clientConfiguration).withRegion(awsRegion).build(); LOGGER.info("Creating AWS SQS client using role: \"{}\".", awsRoleArn); AmazonSQS amazonSQS = AmazonSQSClientBuilder.standard().withCredentials(awsCredentialsProvider).withClientConfiguration(clientConfiguration).withRegion(awsRegion) .build(); BusinessObjectDataKey bdataKey; if (messageFlag) { String sqsQueueUrl = propertiesHelper.getProperty(AWS_SQS_QUEUE_URL_PROPERTY); LOGGER.info("Getting message from SQS queue: {}", sqsQueueUrl); bdataKey = herdApiClientOperations.getBdataKeySqs(amazonSQS, sqsQueueUrl); } else { LOGGER.info("Creating BusinessObjectDataKey from properties file"); bdataKey = getBusinessObjectDataKeyFromPropertiesFile(); } LOGGER.info("Using business object data key: {}", bdataKey); BusinessObjectDataApi businessObjectDataApi = new BusinessObjectDataApi(apiClient); LOGGER.info("Retrieving business object data information from the registration server..."); BusinessObjectData businessObjectData = herdApiClientOperations .businessObjectDataGetBusinessObjectData(businessObjectDataApi, bdataKey.getNamespace(), bdataKey.getBusinessObjectDefinitionName(), bdataKey.getBusinessObjectFormatUsage(), bdataKey.getBusinessObjectFormatFileType(), null, bdataKey.getPartitionValue(), StringUtils.join(bdataKey.getSubPartitionValues(), "|"), bdataKey.getBusinessObjectFormatVersion(), bdataKey.getBusinessObjectDataVersion(), null, false, false, false); Gson gson = new GsonBuilder().setPrettyPrinting().create(); LOGGER.info("{}", gson.toJson(businessObjectData)); Assert.isTrue(CollectionUtils.isNotEmpty(businessObjectData.getStorageUnits()), "Business object data has no storage unit registered with it."); Assert.isTrue(businessObjectData.getStorageUnits().get(0).getStorage() != null, "Business object data storage unit does not have storage information."); String bucketName = null; for (Attribute attribute : businessObjectData.getStorageUnits().get(0).getStorage().getAttributes()) { if (StringUtils.equals(attribute.getName(), S3_BUCKET_NAME_ATTRIBUTE)) { bucketName = attribute.getValue(); break; } } Assert.isTrue(StringUtils.isNotBlank(bucketName), "S3 bucket name is not configured for the storage."); LOGGER.info("Validating that S3 files registered with the business object data are downloadable."); boolean readAccessValidated = false; if (CollectionUtils.isNotEmpty(businessObjectData.getStorageUnits().get(0).getStorageFiles())) { for (StorageFile storageFile : businessObjectData.getStorageUnits().get(0).getStorageFiles()) { LOGGER.info("Attempting to read \"{}/{}\" S3 file...", bucketName, storageFile.getFilePath()); ObjectMetadata objectMetadata = s3Operations.getObjectMetadata(bucketName, storageFile.getFilePath(), amazonS3); if (verifyReadAccessToS3Object(bucketName, storageFile.getFilePath(), objectMetadata.getContentLength(), amazonS3)) { readAccessValidated = true; break; } } } else { Assert.isTrue(businessObjectData.getStorageUnits().get(0).getStorageDirectory() != null && StringUtils.isNotBlank(businessObjectData.getStorageUnits().get(0).getStorageDirectory().getDirectoryPath()), "" + "No storage files or directory path is registered with the business object data storage unit."); String getS3KeyPrefix = StringUtils.appendIfMissing(businessObjectData.getStorageUnits().get(0).getStorageDirectory().getDirectoryPath(), "/"); LOGGER.info("Attempting to list S3 files located under \"{}/{}\" S3 key prefix...", bucketName, getS3KeyPrefix); ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(getS3KeyPrefix); ObjectListing objectListing = s3Operations.listObjects(listObjectsRequest, amazonS3); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { if (verifyReadAccessToS3Object(bucketName, objectSummary.getKey(), objectSummary.getSize(), amazonS3)) { readAccessValidated = true; break; } } } if (readAccessValidated) { LOGGER.info("{}Finished: SUCCESS", LINE_FEED); } else { LOGGER.error("{}Could not read valid content from any file: FAILURE", LINE_FEED); } }    }
@Test public void testValidateAccessMessageOptionEnabled() throws Exception { BusinessObjectData businessObjectData = createBusinessObjectData(); BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(NAMESPACE, BUSINESS_OBJECT_DEFINITION_NAME, BUSINESS_OBJECT_FORMAT_USAGE, BUSINESS_OBJECT_FORMAT_FILE_TYPE, BUSINESS_OBJECT_FORMAT_VERSION, PRIMARY_PARTITION_VALUE, Lists.newArrayList(SUB_PARTITION_VALUES), BUSINESS_OBJECT_DATA_VERSION); GetObjectRequest getObjectRequest = new GetObjectRequest(S3_BUCKET_NAME, S3_KEY).withRange(0, MAX_BYTE_DOWNLOAD); S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ByteArrayInputStream(RandomStringUtils.randomAlphabetic(MAX_BYTE_DOWNLOAD).getBytes())); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(MAX_BYTE_DOWNLOAD); when(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)).thenReturn(HERD_BASE_URL); when(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)).thenReturn(HERD_USERNAME); when(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)).thenReturn(HERD_PASSWORD); when(propertiesHelper.getProperty(AWS_REGION_PROPERTY)).thenReturn(AWS_REGION_NAME_US_EAST_1); when(propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY)).thenReturn(AWS_ROLE_ARN); when(propertiesHelper.getProperty(AWS_SQS_QUEUE_URL_PROPERTY)).thenReturn(AWS_SQS_QUEUE_URL); when(herdApiClientOperations.getBdataKeySqs(any(AmazonSQS.class), eq(AWS_SQS_QUEUE_URL))).thenReturn(businessObjectDataKey); when(herdApiClientOperations .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false))).thenReturn(businessObjectData); when(s3Operations.getObjectMetadata(any(), any(), any())).thenReturn(objectMetadata); when(s3Operations.getS3Object(eq(getObjectRequest), any(AmazonS3.class))).thenReturn(s3Object); accessValidatorController.validateAccess(new File(PROPERTIES_FILE_PATH), true); verify(herdApiClientOperations).checkPropertiesFile(propertiesHelper, true); verify(propertiesHelper).loadProperties(new File(PROPERTIES_FILE_PATH)); verify(propertiesHelper).getProperty(HERD_BASE_URL_PROPERTY); verify(propertiesHelper).getProperty(HERD_USERNAME_PROPERTY); verify(propertiesHelper).getProperty(HERD_PASSWORD_PROPERTY); verify(herdApiClientOperations).applicationGetBuildInfo(any(ApplicationApi.class)); verify(herdApiClientOperations).currentUserGetCurrentUser(any(CurrentUserApi.class)); verify(propertiesHelper).getProperty(AWS_REGION_PROPERTY); verify(propertiesHelper).getProperty(AWS_ROLE_ARN_PROPERTY); verify(propertiesHelper).getProperty(AWS_SQS_QUEUE_URL_PROPERTY); verify(herdApiClientOperations).getBdataKeySqs(any(AmazonSQS.class), eq(AWS_SQS_QUEUE_URL)); verify(herdApiClientOperations) .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false)); verify(s3Operations).getObjectMetadata(any(), any(), any()); verify(s3Operations).getS3Object(eq(getObjectRequest), any(AmazonS3.class)); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAccessMissingOptionalProperties() throws Exception { BusinessObjectData businessObjectData = createBusinessObjectData(); GetObjectRequest getObjectRequest = new GetObjectRequest(S3_BUCKET_NAME, S3_KEY).withRange(0, MAX_BYTE_DOWNLOAD); S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ByteArrayInputStream(RandomStringUtils.randomAlphabetic(MAX_BYTE_DOWNLOAD).getBytes())); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(MAX_BYTE_DOWNLOAD); when(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)).thenReturn(HERD_BASE_URL); when(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)).thenReturn(HERD_USERNAME); when(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)).thenReturn(HERD_PASSWORD); when(propertiesHelper.getProperty(AWS_REGION_PROPERTY)).thenReturn(AWS_REGION_NAME_US_EAST_1); when(propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY)).thenReturn(AWS_ROLE_ARN); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY)).thenReturn(null); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY)).thenReturn(null); when(propertiesHelper.getProperty(NAMESPACE_PROPERTY)).thenReturn(NAMESPACE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY)).thenReturn(BUSINESS_OBJECT_DEFINITION_NAME); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_USAGE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_FILE_TYPE); when(propertiesHelper.getProperty(PRIMARY_PARTITION_VALUE_PROPERTY)).thenReturn(PRIMARY_PARTITION_VALUE); when(propertiesHelper.getProperty(SUB_PARTITION_VALUES_PROPERTY)).thenReturn(null); when(herdApiClientOperations .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(null), eq(null), eq(null), eq(null), eq(false), eq(false), eq(false))).thenReturn(businessObjectData); when(s3Operations.getObjectMetadata(any(), any(), any())).thenReturn(objectMetadata); when(s3Operations.getS3Object(eq(getObjectRequest), any(AmazonS3.class))).thenReturn(s3Object); accessValidatorController.validateAccess(new File(PROPERTIES_FILE_PATH), false); verify(herdApiClientOperations).checkPropertiesFile(propertiesHelper, false); verify(propertiesHelper).loadProperties(new File(PROPERTIES_FILE_PATH)); verify(propertiesHelper).getProperty(HERD_BASE_URL_PROPERTY); verify(propertiesHelper).getProperty(HERD_USERNAME_PROPERTY); verify(propertiesHelper).getProperty(HERD_PASSWORD_PROPERTY); verify(herdApiClientOperations).applicationGetBuildInfo(any(ApplicationApi.class)); verify(herdApiClientOperations).currentUserGetCurrentUser(any(CurrentUserApi.class)); verify(propertiesHelper).getProperty(AWS_REGION_PROPERTY); verify(propertiesHelper).getProperty(AWS_ROLE_ARN_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY); verify(propertiesHelper).getProperty(NAMESPACE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY); verify(propertiesHelper).getProperty(PRIMARY_PARTITION_VALUE_PROPERTY); verify(propertiesHelper).getProperty(SUB_PARTITION_VALUES_PROPERTY); verify(herdApiClientOperations) .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(null), eq(null), eq(null), eq(null), eq(false), eq(false), eq(false)); verify(s3Operations).getObjectMetadata(any(), any(), any()); verify(s3Operations).getS3Object(eq(getObjectRequest), any(AmazonS3.class)); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAccessNoStorage() throws Exception { BusinessObjectData businessObjectData = createBusinessObjectData(); businessObjectData.getStorageUnits().get(0).setStorage(null); when(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)).thenReturn(HERD_BASE_URL); when(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)).thenReturn(HERD_USERNAME); when(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)).thenReturn(HERD_PASSWORD); when(propertiesHelper.getProperty(AWS_REGION_PROPERTY)).thenReturn(AWS_REGION_NAME_US_EAST_1); when(propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY)).thenReturn(AWS_ROLE_ARN); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_VERSION.toString()); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_DATA_VERSION.toString()); when(propertiesHelper.getProperty(NAMESPACE_PROPERTY)).thenReturn(NAMESPACE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY)).thenReturn(BUSINESS_OBJECT_DEFINITION_NAME); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_USAGE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_FILE_TYPE); when(propertiesHelper.getProperty(PRIMARY_PARTITION_VALUE_PROPERTY)).thenReturn(PRIMARY_PARTITION_VALUE); when(propertiesHelper.getProperty(SUB_PARTITION_VALUES_PROPERTY)).thenReturn(SUB_PARTITION_VALUES); when(herdApiClientOperations .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false))).thenReturn(businessObjectData); try { accessValidatorController.validateAccess(new File(PROPERTIES_FILE_PATH), false); fail(); } catch (IllegalArgumentException e) { assertEquals("Business object data storage unit does not have storage information.", e.getMessage()); } verify(herdApiClientOperations).checkPropertiesFile(propertiesHelper, false); verify(propertiesHelper).loadProperties(new File(PROPERTIES_FILE_PATH)); verify(propertiesHelper).getProperty(HERD_BASE_URL_PROPERTY); verify(propertiesHelper).getProperty(HERD_USERNAME_PROPERTY); verify(propertiesHelper).getProperty(HERD_PASSWORD_PROPERTY); verify(herdApiClientOperations).applicationGetBuildInfo(any(ApplicationApi.class)); verify(herdApiClientOperations).currentUserGetCurrentUser(any(CurrentUserApi.class)); verify(propertiesHelper).getProperty(AWS_REGION_PROPERTY); verify(propertiesHelper).getProperty(AWS_ROLE_ARN_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY); verify(propertiesHelper).getProperty(NAMESPACE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY); verify(propertiesHelper).getProperty(PRIMARY_PARTITION_VALUE_PROPERTY); verify(propertiesHelper).getProperty(SUB_PARTITION_VALUES_PROPERTY); verify(herdApiClientOperations) .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false)); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAccessNoStorageFiles() throws Exception { BusinessObjectData businessObjectData = createBusinessObjectData(); businessObjectData.getStorageUnits().get(0).setStorageFiles(null); StorageDirectory storageDirectory = new StorageDirectory(); storageDirectory.setDirectoryPath(STORAGE_DIRECTORY_PATH); businessObjectData.getStorageUnits().get(0).setStorageDirectory(storageDirectory); S3ObjectSummary s3ObjectSummary = new S3ObjectSummary(); s3ObjectSummary.setKey(S3_KEY); s3ObjectSummary.setSize(FILE_SIZE_1_KB); objectListing = Mockito.mock(ObjectListing.class); when(objectListing.getObjectSummaries()).thenReturn(Lists.newArrayList(s3ObjectSummary)); GetObjectRequest getObjectRequest = new GetObjectRequest(S3_BUCKET_NAME, S3_KEY).withRange(0, MAX_BYTE_DOWNLOAD); S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ByteArrayInputStream(RandomStringUtils.randomAlphabetic(MAX_BYTE_DOWNLOAD).getBytes())); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(MAX_BYTE_DOWNLOAD); when(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)).thenReturn(HERD_BASE_URL); when(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)).thenReturn(HERD_USERNAME); when(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)).thenReturn(HERD_PASSWORD); when(propertiesHelper.getProperty(AWS_REGION_PROPERTY)).thenReturn(AWS_REGION_NAME_US_EAST_1); when(propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY)).thenReturn(AWS_ROLE_ARN); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_VERSION.toString()); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_DATA_VERSION.toString()); when(propertiesHelper.getProperty(NAMESPACE_PROPERTY)).thenReturn(NAMESPACE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY)).thenReturn(BUSINESS_OBJECT_DEFINITION_NAME); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_USAGE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_FILE_TYPE); when(propertiesHelper.getProperty(PRIMARY_PARTITION_VALUE_PROPERTY)).thenReturn(PRIMARY_PARTITION_VALUE); when(propertiesHelper.getProperty(SUB_PARTITION_VALUES_PROPERTY)).thenReturn(SUB_PARTITION_VALUES); when(herdApiClientOperations .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false))).thenReturn(businessObjectData); when(s3Operations.listObjects(any(ListObjectsRequest.class), any(AmazonS3.class))).thenReturn(objectListing); when(s3Operations.getS3Object(eq(getObjectRequest), any(AmazonS3.class))).thenReturn(s3Object); accessValidatorController.validateAccess(new File(PROPERTIES_FILE_PATH), false); verify(herdApiClientOperations).checkPropertiesFile(propertiesHelper, false); verify(propertiesHelper).loadProperties(new File(PROPERTIES_FILE_PATH)); verify(propertiesHelper).getProperty(HERD_BASE_URL_PROPERTY); verify(propertiesHelper).getProperty(HERD_USERNAME_PROPERTY); verify(propertiesHelper).getProperty(HERD_PASSWORD_PROPERTY); verify(herdApiClientOperations).applicationGetBuildInfo(any(ApplicationApi.class)); verify(herdApiClientOperations).currentUserGetCurrentUser(any(CurrentUserApi.class)); verify(propertiesHelper).getProperty(AWS_REGION_PROPERTY); verify(propertiesHelper).getProperty(AWS_ROLE_ARN_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY); verify(propertiesHelper).getProperty(NAMESPACE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY); verify(propertiesHelper).getProperty(PRIMARY_PARTITION_VALUE_PROPERTY); verify(propertiesHelper).getProperty(SUB_PARTITION_VALUES_PROPERTY); verify(herdApiClientOperations) .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false)); verify(s3Operations).listObjects(any(ListObjectsRequest.class), any(AmazonS3.class)); verify(s3Operations).getS3Object(eq(getObjectRequest), any(AmazonS3.class)); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAccessNoStorageFilesAndDirectoryPathIsBlank() throws Exception { BusinessObjectData businessObjectData = createBusinessObjectData(); businessObjectData.getStorageUnits().get(0).setStorageFiles(null); StorageDirectory storageDirectory = new StorageDirectory(); storageDirectory.setDirectoryPath(BLANK_TEXT); businessObjectData.getStorageUnits().get(0).setStorageDirectory(storageDirectory); when(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)).thenReturn(HERD_BASE_URL); when(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)).thenReturn(HERD_USERNAME); when(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)).thenReturn(HERD_PASSWORD); when(propertiesHelper.getProperty(AWS_REGION_PROPERTY)).thenReturn(AWS_REGION_NAME_US_EAST_1); when(propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY)).thenReturn(AWS_ROLE_ARN); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_VERSION.toString()); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_DATA_VERSION.toString()); when(propertiesHelper.getProperty(NAMESPACE_PROPERTY)).thenReturn(NAMESPACE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY)).thenReturn(BUSINESS_OBJECT_DEFINITION_NAME); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_USAGE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_FILE_TYPE); when(propertiesHelper.getProperty(PRIMARY_PARTITION_VALUE_PROPERTY)).thenReturn(PRIMARY_PARTITION_VALUE); when(propertiesHelper.getProperty(SUB_PARTITION_VALUES_PROPERTY)).thenReturn(SUB_PARTITION_VALUES); when(herdApiClientOperations .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false))).thenReturn(businessObjectData); try { accessValidatorController.validateAccess(new File(PROPERTIES_FILE_PATH), false); fail(); } catch (IllegalArgumentException e) { assertEquals("No storage files or directory path is registered with the business object data storage unit.", e.getMessage()); } verify(herdApiClientOperations).checkPropertiesFile(propertiesHelper, false); verify(propertiesHelper).loadProperties(new File(PROPERTIES_FILE_PATH)); verify(propertiesHelper).getProperty(HERD_BASE_URL_PROPERTY); verify(propertiesHelper).getProperty(HERD_USERNAME_PROPERTY); verify(propertiesHelper).getProperty(HERD_PASSWORD_PROPERTY); verify(herdApiClientOperations).applicationGetBuildInfo(any(ApplicationApi.class)); verify(herdApiClientOperations).currentUserGetCurrentUser(any(CurrentUserApi.class)); verify(propertiesHelper).getProperty(AWS_REGION_PROPERTY); verify(propertiesHelper).getProperty(AWS_ROLE_ARN_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY); verify(propertiesHelper).getProperty(NAMESPACE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY); verify(propertiesHelper).getProperty(PRIMARY_PARTITION_VALUE_PROPERTY); verify(propertiesHelper).getProperty(SUB_PARTITION_VALUES_PROPERTY); verify(herdApiClientOperations) .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false)); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAccessNoStorageFilesAndNoStorageDirectory() throws Exception { BusinessObjectData businessObjectData = createBusinessObjectData(); businessObjectData.getStorageUnits().get(0).setStorageFiles(null); businessObjectData.getStorageUnits().get(0).setStorageDirectory(null); when(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)).thenReturn(HERD_BASE_URL); when(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)).thenReturn(HERD_USERNAME); when(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)).thenReturn(HERD_PASSWORD); when(propertiesHelper.getProperty(AWS_REGION_PROPERTY)).thenReturn(AWS_REGION_NAME_US_EAST_1); when(propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY)).thenReturn(AWS_ROLE_ARN); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_VERSION.toString()); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_DATA_VERSION.toString()); when(propertiesHelper.getProperty(NAMESPACE_PROPERTY)).thenReturn(NAMESPACE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY)).thenReturn(BUSINESS_OBJECT_DEFINITION_NAME); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_USAGE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_FILE_TYPE); when(propertiesHelper.getProperty(PRIMARY_PARTITION_VALUE_PROPERTY)).thenReturn(PRIMARY_PARTITION_VALUE); when(propertiesHelper.getProperty(SUB_PARTITION_VALUES_PROPERTY)).thenReturn(SUB_PARTITION_VALUES); when(herdApiClientOperations .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false))).thenReturn(businessObjectData); try { accessValidatorController.validateAccess(new File(PROPERTIES_FILE_PATH), false); fail(); } catch (IllegalArgumentException e) { assertEquals("No storage files or directory path is registered with the business object data storage unit.", e.getMessage()); } verify(herdApiClientOperations).checkPropertiesFile(propertiesHelper, false); verify(propertiesHelper).loadProperties(new File(PROPERTIES_FILE_PATH)); verify(propertiesHelper).getProperty(HERD_BASE_URL_PROPERTY); verify(propertiesHelper).getProperty(HERD_USERNAME_PROPERTY); verify(propertiesHelper).getProperty(HERD_PASSWORD_PROPERTY); verify(herdApiClientOperations).applicationGetBuildInfo(any(ApplicationApi.class)); verify(herdApiClientOperations).currentUserGetCurrentUser(any(CurrentUserApi.class)); verify(propertiesHelper).getProperty(AWS_REGION_PROPERTY); verify(propertiesHelper).getProperty(AWS_ROLE_ARN_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY); verify(propertiesHelper).getProperty(NAMESPACE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY); verify(propertiesHelper).getProperty(PRIMARY_PARTITION_VALUE_PROPERTY); verify(propertiesHelper).getProperty(SUB_PARTITION_VALUES_PROPERTY); verify(herdApiClientOperations) .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false)); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAccessNoStorageFilesZeroByteS3File() throws Exception { BusinessObjectData businessObjectData = createBusinessObjectData(); businessObjectData.getStorageUnits().get(0).setStorageFiles(null); StorageDirectory storageDirectory = new StorageDirectory(); storageDirectory.setDirectoryPath(STORAGE_DIRECTORY_PATH); businessObjectData.getStorageUnits().get(0).setStorageDirectory(storageDirectory); S3ObjectSummary s3ObjectSummary = new S3ObjectSummary(); s3ObjectSummary.setKey(S3_KEY); s3ObjectSummary.setSize(FILE_SIZE_0_BYTE); objectListing = Mockito.mock(ObjectListing.class); when(objectListing.getObjectSummaries()).thenReturn(Lists.newArrayList(s3ObjectSummary)); GetObjectRequest getObjectRequest = new GetObjectRequest(S3_BUCKET_NAME, S3_KEY).withRange(0, MAX_BYTE_DOWNLOAD); S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ByteArrayInputStream(RandomStringUtils.randomAlphabetic(MAX_BYTE_DOWNLOAD).getBytes())); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(MAX_BYTE_DOWNLOAD); when(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)).thenReturn(HERD_BASE_URL); when(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)).thenReturn(HERD_USERNAME); when(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)).thenReturn(HERD_PASSWORD); when(propertiesHelper.getProperty(AWS_REGION_PROPERTY)).thenReturn(AWS_REGION_NAME_US_EAST_1); when(propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY)).thenReturn(AWS_ROLE_ARN); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_VERSION.toString()); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_DATA_VERSION.toString()); when(propertiesHelper.getProperty(NAMESPACE_PROPERTY)).thenReturn(NAMESPACE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY)).thenReturn(BUSINESS_OBJECT_DEFINITION_NAME); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_USAGE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_FILE_TYPE); when(propertiesHelper.getProperty(PRIMARY_PARTITION_VALUE_PROPERTY)).thenReturn(PRIMARY_PARTITION_VALUE); when(propertiesHelper.getProperty(SUB_PARTITION_VALUES_PROPERTY)).thenReturn(SUB_PARTITION_VALUES); when(herdApiClientOperations .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false))).thenReturn(businessObjectData); when(s3Operations.listObjects(any(ListObjectsRequest.class), any(AmazonS3.class))).thenReturn(objectListing); accessValidatorController.validateAccess(new File(PROPERTIES_FILE_PATH), false); verify(herdApiClientOperations).checkPropertiesFile(propertiesHelper, false); verify(propertiesHelper).loadProperties(new File(PROPERTIES_FILE_PATH)); verify(propertiesHelper).getProperty(HERD_BASE_URL_PROPERTY); verify(propertiesHelper).getProperty(HERD_USERNAME_PROPERTY); verify(propertiesHelper).getProperty(HERD_PASSWORD_PROPERTY); verify(herdApiClientOperations).applicationGetBuildInfo(any(ApplicationApi.class)); verify(herdApiClientOperations).currentUserGetCurrentUser(any(CurrentUserApi.class)); verify(propertiesHelper).getProperty(AWS_REGION_PROPERTY); verify(propertiesHelper).getProperty(AWS_ROLE_ARN_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY); verify(propertiesHelper).getProperty(NAMESPACE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY); verify(propertiesHelper).getProperty(PRIMARY_PARTITION_VALUE_PROPERTY); verify(propertiesHelper).getProperty(SUB_PARTITION_VALUES_PROPERTY); verify(herdApiClientOperations) .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false)); verify(s3Operations).listObjects(any(ListObjectsRequest.class), any(AmazonS3.class)); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAccessNoStorageUnit() throws Exception { BusinessObjectData businessObjectData = createBusinessObjectData(); businessObjectData.setStorageUnits(null); when(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)).thenReturn(HERD_BASE_URL); when(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)).thenReturn(HERD_USERNAME); when(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)).thenReturn(HERD_PASSWORD); when(propertiesHelper.getProperty(AWS_REGION_PROPERTY)).thenReturn(AWS_REGION_NAME_US_EAST_1); when(propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY)).thenReturn(AWS_ROLE_ARN); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_VERSION.toString()); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_DATA_VERSION.toString()); when(propertiesHelper.getProperty(NAMESPACE_PROPERTY)).thenReturn(NAMESPACE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY)).thenReturn(BUSINESS_OBJECT_DEFINITION_NAME); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_USAGE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_FILE_TYPE); when(propertiesHelper.getProperty(PRIMARY_PARTITION_VALUE_PROPERTY)).thenReturn(PRIMARY_PARTITION_VALUE); when(propertiesHelper.getProperty(SUB_PARTITION_VALUES_PROPERTY)).thenReturn(SUB_PARTITION_VALUES); when(herdApiClientOperations .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false))).thenReturn(businessObjectData); try { accessValidatorController.validateAccess(new File(PROPERTIES_FILE_PATH), false); fail(); } catch (IllegalArgumentException e) { assertEquals("Business object data has no storage unit registered with it.", e.getMessage()); } verify(herdApiClientOperations).checkPropertiesFile(propertiesHelper, false); verify(propertiesHelper).loadProperties(new File(PROPERTIES_FILE_PATH)); verify(propertiesHelper).getProperty(HERD_BASE_URL_PROPERTY); verify(propertiesHelper).getProperty(HERD_USERNAME_PROPERTY); verify(propertiesHelper).getProperty(HERD_PASSWORD_PROPERTY); verify(herdApiClientOperations).applicationGetBuildInfo(any(ApplicationApi.class)); verify(herdApiClientOperations).currentUserGetCurrentUser(any(CurrentUserApi.class)); verify(propertiesHelper).getProperty(AWS_REGION_PROPERTY); verify(propertiesHelper).getProperty(AWS_ROLE_ARN_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY); verify(propertiesHelper).getProperty(NAMESPACE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY); verify(propertiesHelper).getProperty(PRIMARY_PARTITION_VALUE_PROPERTY); verify(propertiesHelper).getProperty(SUB_PARTITION_VALUES_PROPERTY); verify(herdApiClientOperations) .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false)); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAccessStorageHasNoBucketNameAttribute() throws Exception { BusinessObjectData businessObjectData = createBusinessObjectData(); businessObjectData.getStorageUnits().get(0).getStorage().setAttributes(Lists.newArrayList(new Attribute())); when(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)).thenReturn(HERD_BASE_URL); when(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)).thenReturn(HERD_USERNAME); when(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)).thenReturn(HERD_PASSWORD); when(propertiesHelper.getProperty(AWS_REGION_PROPERTY)).thenReturn(AWS_REGION_NAME_US_EAST_1); when(propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY)).thenReturn(AWS_ROLE_ARN); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_VERSION.toString()); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_DATA_VERSION.toString()); when(propertiesHelper.getProperty(NAMESPACE_PROPERTY)).thenReturn(NAMESPACE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY)).thenReturn(BUSINESS_OBJECT_DEFINITION_NAME); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_USAGE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_FILE_TYPE); when(propertiesHelper.getProperty(PRIMARY_PARTITION_VALUE_PROPERTY)).thenReturn(PRIMARY_PARTITION_VALUE); when(propertiesHelper.getProperty(SUB_PARTITION_VALUES_PROPERTY)).thenReturn(SUB_PARTITION_VALUES); when(herdApiClientOperations .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false))).thenReturn(businessObjectData); try { accessValidatorController.validateAccess(new File(PROPERTIES_FILE_PATH), false); fail(); } catch (IllegalArgumentException e) { assertEquals("S3 bucket name is not configured for the storage.", e.getMessage()); } verify(herdApiClientOperations).checkPropertiesFile(propertiesHelper, false); verify(propertiesHelper).loadProperties(new File(PROPERTIES_FILE_PATH)); verify(propertiesHelper).getProperty(HERD_BASE_URL_PROPERTY); verify(propertiesHelper).getProperty(HERD_USERNAME_PROPERTY); verify(propertiesHelper).getProperty(HERD_PASSWORD_PROPERTY); verify(herdApiClientOperations).applicationGetBuildInfo(any(ApplicationApi.class)); verify(herdApiClientOperations).currentUserGetCurrentUser(any(CurrentUserApi.class)); verify(propertiesHelper).getProperty(AWS_REGION_PROPERTY); verify(propertiesHelper).getProperty(AWS_ROLE_ARN_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY); verify(propertiesHelper).getProperty(NAMESPACE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY); verify(propertiesHelper).getProperty(PRIMARY_PARTITION_VALUE_PROPERTY); verify(propertiesHelper).getProperty(SUB_PARTITION_VALUES_PROPERTY); verify(herdApiClientOperations) .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false)); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAccessZeroByteS3File() throws Exception { BusinessObjectData businessObjectData = createBusinessObjectData(); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(0); when(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)).thenReturn(HERD_BASE_URL); when(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)).thenReturn(HERD_USERNAME); when(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)).thenReturn(HERD_PASSWORD); when(propertiesHelper.getProperty(AWS_REGION_PROPERTY)).thenReturn(AWS_REGION_NAME_US_EAST_1); when(propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY)).thenReturn(AWS_ROLE_ARN); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_VERSION.toString()); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_DATA_VERSION.toString()); when(propertiesHelper.getProperty(NAMESPACE_PROPERTY)).thenReturn(NAMESPACE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY)).thenReturn(BUSINESS_OBJECT_DEFINITION_NAME); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_USAGE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_FILE_TYPE); when(propertiesHelper.getProperty(PRIMARY_PARTITION_VALUE_PROPERTY)).thenReturn(PRIMARY_PARTITION_VALUE); when(propertiesHelper.getProperty(SUB_PARTITION_VALUES_PROPERTY)).thenReturn(SUB_PARTITION_VALUES); when(herdApiClientOperations .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false))).thenReturn(businessObjectData); when(s3Operations.getObjectMetadata(any(), any(), any())).thenReturn(objectMetadata); accessValidatorController.validateAccess(new File(PROPERTIES_FILE_PATH), false); verify(herdApiClientOperations).checkPropertiesFile(propertiesHelper, false); verify(propertiesHelper).loadProperties(new File(PROPERTIES_FILE_PATH)); verify(propertiesHelper).getProperty(HERD_BASE_URL_PROPERTY); verify(propertiesHelper).getProperty(HERD_USERNAME_PROPERTY); verify(propertiesHelper).getProperty(HERD_PASSWORD_PROPERTY); verify(herdApiClientOperations).applicationGetBuildInfo(any(ApplicationApi.class)); verify(herdApiClientOperations).currentUserGetCurrentUser(any(CurrentUserApi.class)); verify(propertiesHelper).getProperty(AWS_REGION_PROPERTY); verify(propertiesHelper).getProperty(AWS_ROLE_ARN_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY); verify(propertiesHelper).getProperty(NAMESPACE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY); verify(propertiesHelper).getProperty(PRIMARY_PARTITION_VALUE_PROPERTY); verify(propertiesHelper).getProperty(SUB_PARTITION_VALUES_PROPERTY); verify(herdApiClientOperations) .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false)); verify(s3Operations).getObjectMetadata(any(), any(), any()); verifyNoMoreInteractionsHelper(); }
@Test public void testValidateAccess() throws Exception { BusinessObjectData businessObjectData = createBusinessObjectData(); GetObjectRequest getObjectRequest = new GetObjectRequest(S3_BUCKET_NAME, S3_KEY).withRange(0, MAX_BYTE_DOWNLOAD); S3Object s3Object = new S3Object(); s3Object.setObjectContent(new ByteArrayInputStream(RandomStringUtils.randomAlphabetic(MAX_BYTE_DOWNLOAD).getBytes())); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(MAX_BYTE_DOWNLOAD); when(propertiesHelper.getProperty(HERD_BASE_URL_PROPERTY)).thenReturn(HERD_BASE_URL); when(propertiesHelper.getProperty(HERD_USERNAME_PROPERTY)).thenReturn(HERD_USERNAME); when(propertiesHelper.getProperty(HERD_PASSWORD_PROPERTY)).thenReturn(HERD_PASSWORD); when(propertiesHelper.getProperty(AWS_REGION_PROPERTY)).thenReturn(AWS_REGION_NAME_US_EAST_1); when(propertiesHelper.getProperty(AWS_ROLE_ARN_PROPERTY)).thenReturn(AWS_ROLE_ARN); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_VERSION.toString()); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY)).thenReturn(BUSINESS_OBJECT_DATA_VERSION.toString()); when(propertiesHelper.getProperty(NAMESPACE_PROPERTY)).thenReturn(NAMESPACE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY)).thenReturn(BUSINESS_OBJECT_DEFINITION_NAME); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_USAGE); when(propertiesHelper.getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY)).thenReturn(BUSINESS_OBJECT_FORMAT_FILE_TYPE); when(propertiesHelper.getProperty(PRIMARY_PARTITION_VALUE_PROPERTY)).thenReturn(PRIMARY_PARTITION_VALUE); when(propertiesHelper.getProperty(SUB_PARTITION_VALUES_PROPERTY)).thenReturn(SUB_PARTITION_VALUES); when(herdApiClientOperations .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false))).thenReturn(businessObjectData); when(s3Operations.getObjectMetadata(any(), any(), any())).thenReturn(objectMetadata); when(s3Operations.getS3Object(eq(getObjectRequest), any(AmazonS3.class))).thenReturn(s3Object); accessValidatorController.validateAccess(new File(PROPERTIES_FILE_PATH), false); verify(herdApiClientOperations).checkPropertiesFile(propertiesHelper, false); verify(propertiesHelper).loadProperties(new File(PROPERTIES_FILE_PATH)); verify(propertiesHelper).getProperty(HERD_BASE_URL_PROPERTY); verify(propertiesHelper).getProperty(HERD_USERNAME_PROPERTY); verify(propertiesHelper).getProperty(HERD_PASSWORD_PROPERTY); verify(herdApiClientOperations).applicationGetBuildInfo(any(ApplicationApi.class)); verify(herdApiClientOperations).currentUserGetCurrentUser(any(CurrentUserApi.class)); verify(propertiesHelper).getProperty(AWS_REGION_PROPERTY); verify(propertiesHelper).getProperty(AWS_ROLE_ARN_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_VERSION_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DATA_VERSION_PROPERTY); verify(propertiesHelper).getProperty(NAMESPACE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY); verify(propertiesHelper).getProperty(BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY); verify(propertiesHelper).getProperty(PRIMARY_PARTITION_VALUE_PROPERTY); verify(propertiesHelper).getProperty(SUB_PARTITION_VALUES_PROPERTY); verify(herdApiClientOperations) .businessObjectDataGetBusinessObjectData(any(BusinessObjectDataApi.class), eq(NAMESPACE), eq(BUSINESS_OBJECT_DEFINITION_NAME), eq(BUSINESS_OBJECT_FORMAT_USAGE), eq(BUSINESS_OBJECT_FORMAT_FILE_TYPE), eq(null), eq(PRIMARY_PARTITION_VALUE), eq(SUB_PARTITION_VALUES), eq(BUSINESS_OBJECT_FORMAT_VERSION), eq(BUSINESS_OBJECT_DATA_VERSION), eq(null), eq(false), eq(false), eq(false)); verify(s3Operations).getObjectMetadata(any(), any(), any()); verify(s3Operations).getS3Object(eq(getObjectRequest), any(AmazonS3.class)); verifyNoMoreInteractionsHelper(); }