Skip to content

Commit 5adc8b0

Browse files
feat(storage): add conformance tests for virtual hosted style signed URLs (#83)
* feat(storage): add conformance tests * feat(storage): cover fix * feat(storage): nit * feat(storage): remove unnecessary test
1 parent cc853af commit 5adc8b0

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

tests/unit/test__signing.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,11 @@ def dummy_service_account():
778778
return _DUMMY_SERVICE_ACCOUNT
779779

780780

781+
_API_ACCESS_ENDPOINT = "https://storage.googleapis.com"
782+
783+
781784
def _run_conformance_test(
782-
resource, test_data, api_access_endpoint="https://storage.googleapis.com"
785+
resource, test_data, api_access_endpoint=_API_ACCESS_ENDPOINT
783786
):
784787
credentials = dummy_service_account()
785788
url = Test_generate_signed_url_v4._call_fut(
@@ -804,29 +807,37 @@ def test_conformance_client(test_data):
804807

805808
@pytest.mark.parametrize("test_data", _BUCKET_TESTS)
806809
def test_conformance_bucket(test_data):
810+
global _API_ACCESS_ENDPOINT
807811
if "urlStyle" in test_data and test_data["urlStyle"] == "BUCKET_BOUND_HOSTNAME":
808-
api_access_endpoint = "{scheme}://{bucket_bound_hostname}".format(
812+
_API_ACCESS_ENDPOINT = "{scheme}://{bucket_bound_hostname}".format(
809813
scheme=test_data["scheme"],
810814
bucket_bound_hostname=test_data["bucketBoundHostname"],
811815
)
812816
resource = "/"
813-
_run_conformance_test(resource, test_data, api_access_endpoint)
817+
_run_conformance_test(resource, test_data, _API_ACCESS_ENDPOINT)
814818
else:
815819
resource = "/{}".format(test_data["bucket"])
816820
_run_conformance_test(resource, test_data)
817821

818822

819823
@pytest.mark.parametrize("test_data", _BLOB_TESTS)
820824
def test_conformance_blob(test_data):
821-
if "urlStyle" in test_data and test_data["urlStyle"] == "BUCKET_BOUND_HOSTNAME":
822-
api_access_endpoint = "{scheme}://{bucket_bound_hostname}".format(
823-
scheme=test_data["scheme"],
824-
bucket_bound_hostname=test_data["bucketBoundHostname"],
825-
)
825+
global _API_ACCESS_ENDPOINT
826+
if "urlStyle" in test_data:
827+
if test_data["urlStyle"] == "BUCKET_BOUND_HOSTNAME":
828+
_API_ACCESS_ENDPOINT = "{scheme}://{bucket_bound_hostname}".format(
829+
scheme=test_data["scheme"],
830+
bucket_bound_hostname=test_data["bucketBoundHostname"],
831+
)
832+
833+
# For the VIRTUAL_HOSTED_STYLE
834+
else:
835+
_API_ACCESS_ENDPOINT = "{scheme}://{bucket_name}.storage.googleapis.com".format(
836+
scheme=test_data["scheme"], bucket_name=test_data["bucket"]
837+
)
826838
resource = "/{}".format(test_data["object"])
827-
_run_conformance_test(resource, test_data, api_access_endpoint)
839+
_run_conformance_test(resource, test_data, _API_ACCESS_ENDPOINT)
828840
else:
829-
830841
resource = "/{}/{}".format(test_data["bucket"], test_data["object"])
831842
_run_conformance_test(resource, test_data)
832843

tests/unit/url_signer_v4_test_data.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,19 @@
168168
"scheme": "https",
169169
"urlStyle": "BUCKET_BOUND_HOSTNAME",
170170
"bucketBoundHostname": "mydomain.tld"
171+
},
172+
173+
{
174+
"description": "Virtual Hosted Style",
175+
"bucket": "test-bucket",
176+
"object": "test-object",
177+
"method": "GET",
178+
"expiration": 10,
179+
"timestamp": "20190201T090000Z",
180+
"expectedUrl": "https://test-bucket.storage.googleapis.com/test-object?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=test-iam-credentials%40dummy-project-id.iam.gserviceaccount.com%2F20190201%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20190201T090000Z&X-Goog-Expires=10&X-Goog-SignedHeaders=host&X-Goog-Signature=06c633ea060b0eda81ee58dd3337b01b0d243a44f18cb03ec948861f533a129e579c7fd4c856d187f1c7b86e5715ea0abf6a1c6ba32b69274d22b1b0406df6847dc87f0d289fe8dc0682351574849b8b13e4b66922f39441af96becb73ea4c56cd5e3eeb30bc91fe84e8bd205adca8639253bdb65b2fcaf2598a230c6d8f6d8177c9e58a61b6e826767f594056b490184d676897c4bbedc15d6fbf08c3fa82a406c62e74db661e6c5d7d3ced29e0619ee719dce4b8136360345b8dce120b9f1debd511c8dac3e6d874ee05bfda8c8f1c4fedd0c07fc6d98f5f18a349bb204d8ff401402a025194e2792df8a09282141157e4ca51d26a8d0d142a01c805321911",
181+
"scheme": "https",
182+
"urlStyle": "VIRTUAL_HOSTED_STYLE",
183+
"expectedCanonicalRequest": "GET\n/test-object\nX-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=test-iam-credentials%40dummy-project-id.iam.gserviceaccount.com%2F20190201%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20190201T090000Z&X-Goog-Expires=10&X-Goog-SignedHeaders=host\nhost:test-bucket.storage.googleapis.com\n\nhost\nUNSIGNED-PAYLOAD",
184+
"expectedStringToSign": "GOOG4-RSA-SHA256\n20190201T090000Z\n20190201/auto/storage/goog4_request\n89eeae48258eccdcb1f592fb908008e3f5d36a949c002c1e614c94356dc18fc6"
171185
}
172186
]

0 commit comments

Comments
 (0)