test_class.declarator: MAX_BYTE_DOWNLOAD = 200
test_class.modifier: private static final
test_class.original_string: private static final int MAX_BYTE_DOWNLOAD = 200;
test_class.type: int
test_class.var_name: MAX_BYTE_DOWNLOAD
test_class.declarator: accessValidatorController
test_class.modifier: @InjectMocks
      private
test_class.original_string: @InjectMocks
      private AccessValidatorController accessValidatorController;
test_class.type: AccessValidatorController
test_class.var_name: accessValidatorController
test_class.declarator: herdApiClientOperations
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private HerdApiClientOperations herdApiClientOperations;
test_class.type: HerdApiClientOperations
test_class.var_name: herdApiClientOperations
test_class.declarator: objectListing
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private ObjectListing objectListing;
test_class.type: ObjectListing
test_class.var_name: objectListing
test_class.declarator: propertiesHelper
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private PropertiesHelper propertiesHelper;
test_class.type: PropertiesHelper
test_class.var_name: propertiesHelper
test_class.declarator: s3Operations
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private S3Operations s3Operations;
test_class.type: S3Operations
test_class.var_name: s3Operations
test_class.file: herd-code/herd-tools/herd-access-validator/src/test/java/org/finra/herd/tools/access/validator/AccessValidatorControllerTest.java
test_class.identifier: AccessValidatorControllerTest
test_class.superclass: extends AbstractAccessValidatorTest
test_case.body: @Test
      public void testValidateAccessStorageHasNoBucketNameAttribute() throws Exception
      {
          // Create business object data with storage without bucket name attribute.
          BusinessObjectData businessObjectData = createBusinessObjectData();
          businessObjectData.getStorageUnits().get(0).getStorage().setAttributes(Lists.newArrayList(new Attribute()));
  
          // Mock the external calls.
          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 to call the method under test.
          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 the external calls.
          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_case.class_method_signature: AccessValidatorControllerTest.testValidateAccessStorageHasNoBucketNameAttribute()
test_case.full_signature: @Test public void testValidateAccessStorageHasNoBucketNameAttribute()
test_case.identifier: testValidateAccessStorageHasNoBucketNameAttribute
test_case.invocations: createBusinessObjectData setAttributes getStorage get getStorageUnits newArrayList thenReturn when getProperty thenReturn when getProperty thenReturn when getProperty thenReturn when getProperty thenReturn when getProperty thenReturn when getProperty toString thenReturn when getProperty toString thenReturn when getProperty thenReturn when getProperty thenReturn when getProperty thenReturn when getProperty thenReturn when getProperty thenReturn when getProperty thenReturn when businessObjectDataGetBusinessObjectData any eq eq eq eq eq eq eq eq eq eq eq eq eq validateAccess fail assertEquals getMessage checkPropertiesFile verify loadProperties verify getProperty verify getProperty verify getProperty verify applicationGetBuildInfo verify any currentUserGetCurrentUser verify any getProperty verify getProperty verify getProperty verify getProperty verify getProperty verify getProperty verify getProperty verify getProperty verify getProperty verify getProperty verify businessObjectDataGetBusinessObjectData verify any eq eq eq eq eq eq eq eq eq eq eq eq eq verifyNoMoreInteractionsHelper
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testValidateAccessStorageHasNoBucketNameAttribute()
focal_class.declarator: S3_BUCKET_NAME_ATTRIBUTE = "bucket.name"
focal_class.modifier: static final
focal_class.original_string: static final String S3_BUCKET_NAME_ATTRIBUTE = "bucket.name";
focal_class.type: String
focal_class.var_name: S3_BUCKET_NAME_ATTRIBUTE
focal_class.declarator: LINE_FEED = "\n\n\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String LINE_FEED = "\n\n\n";
focal_class.type: String
focal_class.var_name: LINE_FEED
focal_class.declarator: LOGGER = LoggerFactory.getLogger(AccessValidatorController.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(AccessValidatorController.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.declarator: herdApiClientOperations
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private HerdApiClientOperations herdApiClientOperations;
focal_class.type: HerdApiClientOperations
focal_class.var_name: herdApiClientOperations
focal_class.declarator: propertiesHelper
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private PropertiesHelper propertiesHelper;
focal_class.type: PropertiesHelper
focal_class.var_name: propertiesHelper
focal_class.declarator: s3Operations
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private S3Operations s3Operations;
focal_class.type: S3Operations
focal_class.var_name: s3Operations
focal_class.file: herd-code/herd-tools/herd-access-validator/src/main/java/org/finra/herd/tools/access/validator/AccessValidatorController.java
focal_class.identifier: AccessValidatorController
focal_class.class_method_signature: AccessValidatorController.validateAccess(File propertiesFile, Boolean messageFlag)
focal_class.full_signature:  void validateAccess(File propertiesFile, Boolean messageFlag)
focal_class.identifier: validateAccess
focal_class.parameters: (File propertiesFile, Boolean messageFlag)
focal_class.return: void
focal_class.signature: void validateAccess(File propertiesFile, Boolean messageFlag)
focal_class.class_method_signature: AccessValidatorController.getBusinessObjectDataKeyFromPropertiesFile()
focal_class.full_signature: private BusinessObjectDataKey getBusinessObjectDataKeyFromPropertiesFile()
focal_class.identifier: getBusinessObjectDataKeyFromPropertiesFile
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: BusinessObjectDataKey
focal_class.signature: BusinessObjectDataKey getBusinessObjectDataKeyFromPropertiesFile()
focal_class.class_method_signature: AccessValidatorController.verifyReadAccessToS3Object(String bucketName, String s3ObjectKey, long s3ObjectSize, AmazonS3 amazonS3)
focal_class.full_signature: private boolean verifyReadAccessToS3Object(String bucketName, String s3ObjectKey, long s3ObjectSize, AmazonS3 amazonS3)
focal_class.identifier: verifyReadAccessToS3Object
focal_class.modifiers: private
focal_class.parameters: (String bucketName, String s3ObjectKey, long s3ObjectSize, AmazonS3 amazonS3)
focal_class.return: boolean
focal_class.signature: boolean verifyReadAccessToS3Object(String bucketName, String s3ObjectKey, long s3ObjectSize, AmazonS3 amazonS3)
focal_method.body: void validateAccess(File propertiesFile, Boolean messageFlag) throws IOException, ApiException
      {
          // Load properties.
          propertiesHelper.loadProperties(propertiesFile);
  
          // Check properties
          herdApiClientOperations.checkPropertiesFile(propertiesHelper, messageFlag);
  
          // Create the API client to a specific REST endpoint with proper authentication.
          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));
  
          // Setup specific API classes.
          ApplicationApi applicationApi = new ApplicationApi(apiClient);
          CurrentUserApi currentUserApi = new CurrentUserApi(apiClient);
  
          // Retrieve build information from the registration server.
          LOGGER.info("Retrieving build information from the registration server...");
          LOGGER.info("{}", herdApiClientOperations.applicationGetBuildInfo(applicationApi));
  
          // Retrieve user information from the registration server.
          LOGGER.info("Retrieving user information from the registration server...");
          LOGGER.info("{}", herdApiClientOperations.currentUserGetCurrentUser(currentUserApi));
  
          // Create AWS client configuration.
          ClientConfiguration clientConfiguration = new ClientConfiguration();
  
          // Get AWS region.
          String awsRegion = propertiesHelper.getProperty(AWS_REGION_PROPERTY);
  
          // Get ARN for the AWS role to assume.
          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();
  
          // Create AWS S3 client using the assumed role.
          LOGGER.info("Creating AWS S3 client using role: \"{}\".", awsRoleArn);
  
          AmazonS3 amazonS3 =
              AmazonS3ClientBuilder.standard().withCredentials(awsCredentialsProvider).withClientConfiguration(clientConfiguration).withRegion(awsRegion).build();
  
          // Create AWS SQS client using the assumed role.
          LOGGER.info("Creating AWS SQS client using role: \"{}\".", awsRoleArn);
  
          AmazonSQS amazonSQS =
              AmazonSQSClientBuilder.standard().withCredentials(awsCredentialsProvider).withClientConfiguration(clientConfiguration).withRegion(awsRegion)
                  .build();
  
          BusinessObjectDataKey bdataKey;
  
          // Check if -m flag passed
          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);
  
          // Retrieve business object data from the registration server.
          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);
  
          // Log business object data information returned by the registration server.
          Gson gson = new GsonBuilder().setPrettyPrinting().create();
          LOGGER.info("{}", gson.toJson(businessObjectData));
  
          // Check if retrieved business object data has storage unit registered with it.
          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.");
  
          // Get S3 bucket name.
          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.");
  
          // Validate that S3 files registered with the business object data under can be streamed to disk.
          LOGGER.info("Validating that S3 files registered with the business object data are downloadable.");
  
          // Initialize a flag to be used to determine if we did not find any non-zero byte files registered for this business object data.
          boolean readAccessValidated = false;
  
          // If business object data has registered storage files, we go though the list until we fail
          // accessing S3 metadata or find a non-zero byte file that we can try to download.
          if (CollectionUtils.isNotEmpty(businessObjectData.getStorageUnits().get(0).getStorageFiles()))
          {
              // Loop through the list of storage files and attempt to read at least one file which has valid content.
              for (StorageFile storageFile : businessObjectData.getStorageUnits().get(0).getStorageFiles())
              {
                  LOGGER.info("Attempting to read \"{}/{}\" S3 file...", bucketName, storageFile.getFilePath());
  
                  // Get S3 object metadata.
                  ObjectMetadata objectMetadata = s3Operations.getObjectMetadata(bucketName, storageFile.getFilePath(), amazonS3);
  
                  // Try to verify read access to the S3 object.
                  if (verifyReadAccessToS3Object(bucketName, storageFile.getFilePath(), objectMetadata.getContentLength(), amazonS3))
                  {
                      readAccessValidated = true;
                      break;
                  }
              }
          }
          // If business object data has no registered storage files, we go though the list of S3 files found under
          // the storage unit directory path (S3 key prefix) until we find a non-zero byte file that we can try to download.
          else
          {
              // Check if storage unit has a non-blank directory path.
              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.");
  
              // Since storage unit directory path represents a directory, we add a trailing '/' character to it.
              String getS3KeyPrefix = StringUtils.appendIfMissing(businessObjectData.getStorageUnits().get(0).getStorageDirectory().getDirectoryPath(), "/");
  
              // List all S3 files located under the S3 prefix.
              // We are not using pagination here assuming that AWS page limit is enough to find at least one non-zero byte file.
              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())
              {
                  // Try to verify read access to the S3 object.
                  if (verifyReadAccessToS3Object(bucketName, objectSummary.getKey(), objectSummary.getSize(), amazonS3))
                  {
                      readAccessValidated = true;
                      break;
                  }
              }
          }
  
          // Report success if we were able to find a non-zero byte file and verify read
          // access by downloading some number of bytes from the beginning of the file.
          if (readAccessValidated)
          {
              LOGGER.info("{}Finished: SUCCESS", LINE_FEED);
          }
          // Otherwise, report a failure.
          else
          {
              LOGGER.error("{}Could not read valid content from any file: FAILURE", LINE_FEED);
          }
      }
focal_method.class_method_signature: AccessValidatorController.validateAccess(File propertiesFile, Boolean messageFlag)
focal_method.full_signature:  void validateAccess(File propertiesFile, Boolean messageFlag)
focal_method.identifier: validateAccess
focal_method.invocations: loadProperties checkPropertiesFile setBasePath getProperty setUsername getProperty setPassword getProperty info info applicationGetBuildInfo info info currentUserGetCurrentUser getProperty getProperty info build withStsClient toString randomUUID build withRegion withClientConfiguration standard info build withRegion withClientConfiguration withCredentials standard info build withRegion withClientConfiguration withCredentials standard getProperty info getBdataKeySqs info getBusinessObjectDataKeyFromPropertiesFile info info businessObjectDataGetBusinessObjectData getNamespace getBusinessObjectDefinitionName getBusinessObjectFormatUsage getBusinessObjectFormatFileType getPartitionValue join getSubPartitionValues getBusinessObjectFormatVersion getBusinessObjectDataVersion create setPrettyPrinting info toJson isTrue isNotEmpty getStorageUnits isTrue getStorage get getStorageUnits getAttributes getStorage get getStorageUnits equals getName getValue isTrue isNotBlank info isNotEmpty getStorageFiles get getStorageUnits getStorageFiles get getStorageUnits info getFilePath getObjectMetadata getFilePath verifyReadAccessToS3Object getFilePath getContentLength isTrue getStorageDirectory get getStorageUnits isNotBlank getDirectoryPath getStorageDirectory get getStorageUnits appendIfMissing getDirectoryPath getStorageDirectory get getStorageUnits info withPrefix withBucketName listObjects getObjectSummaries verifyReadAccessToS3Object getKey getSize info error
focal_method.parameters: (File propertiesFile, Boolean messageFlag)
focal_method.return: void
focal_method.signature: void validateAccess(File propertiesFile, Boolean messageFlag)