Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vision: All of the negative vision vpc sc tests should use the same file. #8439

Merged
merged 2 commits into from
Jun 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 18 additions & 32 deletions vision/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_detect_logos_async(self):
response = self.client.async_batch_annotate_images([request], output_config)

# Wait for the operation to complete.
lro_waiting_seconds = 60
lro_waiting_seconds = 90
start_time = time.time()
while not response.done() and (time.time() - start_time) < lro_waiting_seconds:
time.sleep(1)
Expand Down Expand Up @@ -209,7 +209,7 @@ def test_async_batch_annotate_files(self):
response = self.client.async_batch_annotate_files([request])

# Wait for the operation to complete.
lro_waiting_seconds = 60
lro_waiting_seconds = 90
start_time = time.time()
while not response.done() and (time.time() - start_time) < lro_waiting_seconds:
time.sleep(1)
Expand Down Expand Up @@ -815,6 +815,10 @@ class TestVisionClientVpcsc(VisionSystemTestBase):
# Tests to verify Vision API methods are blocked by VPC SC when trying to access a gcs resource outside of a secure perimeter.
def setUp(self):
VisionSystemTestBase.setUp(self)
self.blocked_file = "LC08/01_$folder$"
self.gcs_uri_blocked_file = "gs://{bucket}/{file}".format(
bucket=BUCKET_OUTSIDE, file=self.blocked_file
)
self._verify_vpc_sc_blocks_gcs_bucket()
self.gcs_read_error_message = "Error opening file: gs://"
self.gcs_write_error_message = "Error writing final output to: gs://"
Expand All @@ -824,7 +828,7 @@ def _verify_vpc_sc_blocks_gcs_bucket(self):
try:
storage_client = storage.Client()
outside_bucket = storage_client.get_bucket(BUCKET_OUTSIDE)
blob = outside_bucket.blob("set_up_test.txt")
blob = outside_bucket.blob(self.blocked_file)
blob.download_as_string()
except google.api_core.exceptions.Forbidden as e:
# Verify the Forbidden exception was due to VPC SC.
Expand All @@ -839,14 +843,16 @@ def _verify_vpc_sc_blocks_gcs_bucket(self):
"Unexpected exception raised while accessing gcs bucket: {}".format(e)
)
self.fail(
"No exception raised when accessing gcs bucket: {}".format(BUCKET_OUTSIDE)
"No exception raised when accessing gcs bucket: {}".format(
self.gcs_uri_blocked_file
)
)

@unittest.skipUnless(PROJECT_ID, "PROJECT_ID not set in environment.")
def test_import_product_sets_blocked(self):
# The csv file is outside the secure perimeter.
gcs_source = vision.types.ImportProductSetsGcsSource(
csv_file_uri="gs://{bucket}/some_file.csv".format(bucket=BUCKET_OUTSIDE)
csv_file_uri=self.gcs_uri_blocked_file
)
input_config = vision.types.ImportProductSetsInputConfig(gcs_source=gcs_source)
# Use a valid Project ID.
Expand Down Expand Up @@ -878,9 +884,7 @@ def test_async_batch_annotate_files_read_blocked(self):
# The input file is in a gcs bucket that is outside of the secure perimeter.
request = {
"input_config": {
"gcs_source": {
"uri": "gs://{bucket}/some_file.pdf".format(bucket=BUCKET_OUTSIDE)
},
"gcs_source": {"uri": self.gcs_uri_blocked_file},
"mime_type": "application/pdf",
},
"features": [{"type": vision.enums.Feature.Type.DOCUMENT_TEXT_DETECTION}],
Expand Down Expand Up @@ -926,7 +930,7 @@ def test_async_batch_annotate_files_write_blocked(self):
}
response = self.client.async_batch_annotate_files([request])
# Wait for the operation to complete.
lro_waiting_seconds = 60
lro_waiting_seconds = 90
start_time = time.time()
while not response.done() and (time.time() - start_time) < lro_waiting_seconds:
time.sleep(1)
Expand All @@ -946,13 +950,7 @@ def test_async_batch_annotate_files_write_blocked(self):
def test_async_batch_annotate_images_read_blocked(self):
# Make the request. The input file is in a gcs bucket that is outside of the secure perimeter.
request = {
"image": {
"source": {
"image_uri": "gs://{bucket}/some_image.jpg".format(
bucket=BUCKET_OUTSIDE
)
}
},
"image": {"source": {"image_uri": self.gcs_uri_blocked_file}},
"features": [{"type": vision.enums.Feature.Type.LOGO_DETECTION}],
}
method_name = "test_async_batch_annotate_images_read_blocked"
Expand All @@ -962,7 +960,7 @@ def test_async_batch_annotate_images_read_blocked(self):
output_config = {"gcs_destination": {"uri": output_gcs_uri_prefix}}
response = self.client.async_batch_annotate_images([request], output_config)
# Wait for the operation to complete.
lro_waiting_seconds = 60
lro_waiting_seconds = 90
start_time = time.time()
while not response.done() and (time.time() - start_time) < lro_waiting_seconds:
time.sleep(1)
Expand Down Expand Up @@ -993,13 +991,7 @@ def test_async_batch_annotate_images_read_blocked(self):
def test_async_batch_annotate_images_write_blocked(self):
# Make the request.
request = {
"image": {
"source": {
"image_uri": "gs://{bucket}/some_image.jpg".format(
bucket=BUCKET_OUTSIDE
)
}
},
"image": {"source": {"image_uri": self.gcs_uri_blocked_file}},
"features": [{"type": vision.enums.Feature.Type.LOGO_DETECTION}],
}
method_name = "test_async_batch_annotate_images_write_blocked"
Expand All @@ -1010,7 +1002,7 @@ def test_async_batch_annotate_images_write_blocked(self):
output_config = {"gcs_destination": {"uri": output_gcs_uri_prefix}}
response = self.client.async_batch_annotate_images([request], output_config)
# Wait for the operation to complete.
lro_waiting_seconds = 60
lro_waiting_seconds = 90
start_time = time.time()
while not response.done() and (time.time() - start_time) < lro_waiting_seconds:
time.sleep(1)
Expand All @@ -1029,13 +1021,7 @@ def test_async_batch_annotate_images_write_blocked(self):

def test_batch_annotate_images_read_blocked(self):
response = self.client.logo_detection(
{
"source": {
"image_uri": "gs://{bucket}/some_image.jpg".format(
bucket=BUCKET_OUTSIDE
)
}
}
{"source": {"image_uri": self.gcs_uri_blocked_file}}
)
error = response.error
assert error.code == 7
Expand Down