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

feat(storage): add conformance tests for virtual hosted style signed URLs #83

Merged
merged 4 commits into from Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 32 additions & 14 deletions tests/unit/test__signing.py
Expand Up @@ -778,8 +778,11 @@ def dummy_service_account():
return _DUMMY_SERVICE_ACCOUNT


_API_ACCESS_ENDPOINT = "https://storage.googleapis.com"


def _run_conformance_test(
resource, test_data, api_access_endpoint="https://storage.googleapis.com"
resource, test_data, api_access_endpoint=_API_ACCESS_ENDPOINT
):
credentials = dummy_service_account()
url = Test_generate_signed_url_v4._call_fut(
Expand All @@ -804,29 +807,44 @@ def test_conformance_client(test_data):

@pytest.mark.parametrize("test_data", _BUCKET_TESTS)
def test_conformance_bucket(test_data):
if "urlStyle" in test_data and test_data["urlStyle"] == "BUCKET_BOUND_HOSTNAME":
api_access_endpoint = "{scheme}://{bucket_bound_hostname}".format(
scheme=test_data["scheme"],
bucket_bound_hostname=test_data["bucketBoundHostname"],
)
global _API_ACCESS_ENDPOINT
if "urlStyle" in test_data:
if test_data["urlStyle"] == "BUCKET_BOUND_HOSTNAME":
_API_ACCESS_ENDPOINT = "{scheme}://{bucket_bound_hostname}".format(
scheme=test_data["scheme"],
bucket_bound_hostname=test_data["bucketBoundHostname"],
)

# For the VIRTUAL_HOSTED_STYLE
else:
_API_ACCESS_ENDPOINT = "{scheme}://{bucket_name}.storage.googleapis.com".format(
scheme=test_data["scheme"], bucket_name=test_data["bucket"]
)
resource = "/"
_run_conformance_test(resource, test_data, api_access_endpoint)
_run_conformance_test(resource, test_data, _API_ACCESS_ENDPOINT)
else:
resource = "/{}".format(test_data["bucket"])
_run_conformance_test(resource, test_data)


@pytest.mark.parametrize("test_data", _BLOB_TESTS)
def test_conformance_blob(test_data):
if "urlStyle" in test_data and test_data["urlStyle"] == "BUCKET_BOUND_HOSTNAME":
api_access_endpoint = "{scheme}://{bucket_bound_hostname}".format(
scheme=test_data["scheme"],
bucket_bound_hostname=test_data["bucketBoundHostname"],
)
global _API_ACCESS_ENDPOINT
if "urlStyle" in test_data:
if test_data["urlStyle"] == "BUCKET_BOUND_HOSTNAME":
_API_ACCESS_ENDPOINT = "{scheme}://{bucket_bound_hostname}".format(
scheme=test_data["scheme"],
bucket_bound_hostname=test_data["bucketBoundHostname"],
)

# For the VIRTUAL_HOSTED_STYLE
else:
_API_ACCESS_ENDPOINT = "{scheme}://{bucket_name}.storage.googleapis.com".format(
scheme=test_data["scheme"], bucket_name=test_data["bucket"]
)
resource = "/{}".format(test_data["object"])
_run_conformance_test(resource, test_data, api_access_endpoint)
_run_conformance_test(resource, test_data, _API_ACCESS_ENDPOINT)
else:

resource = "/{}/{}".format(test_data["bucket"], test_data["object"])
_run_conformance_test(resource, test_data)

Expand Down
28 changes: 28 additions & 0 deletions tests/unit/url_signer_v4_test_data.json
Expand Up @@ -168,5 +168,33 @@
"scheme": "https",
"urlStyle": "BUCKET_BOUND_HOSTNAME",
"bucketBoundHostname": "mydomain.tld"
},

{
"description": "Virtual Hosted Style",
"bucket": "test-bucket",
"object": "test-object",
"method": "GET",
"expiration": 10,
"timestamp": "20190201T090000Z",
"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",
"scheme": "https",
"urlStyle": "VIRTUAL_HOSTED_STYLE",
"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",
"expectedStringToSign": "GOOG4-RSA-SHA256\n20190201T090000Z\n20190201/auto/storage/goog4_request\n89eeae48258eccdcb1f592fb908008e3f5d36a949c002c1e614c94356dc18fc6"
},

{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep consistency with https://github.com/googleapis/conformance-tests/blob/master/storage/v1/v4_signatures.json#L232-L244

I don't want to create inconsistencies between main conformance tests and language specific replicas.

"description": "Virtual Hosted Style",
"bucket": "test-bucket",
"object": "",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this test with empty object. It does not match any in the existing conformance tests.

"method": "GET",
"expiration": 10,
"timestamp": "20190201T090000Z",
"expectedUrl": "https://test-bucket.storage.googleapis.com/?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=79b49f12d21293882daaef1d7b0cf81529f302dc29e37d42e15ac1d55b6fe793efc4f53e29a7fe47ca71119fb82768cb34111410029fd5d1a542b8be7e38b54a4164f2fb2a330aa57d0c5762de7f31614c4dda3f1e29ff735a9886464e04e36445a043e5f2e9bac64a588cb339fa75d69dce97ca1322dd4bfe0e7a8fe33cf309f30b35f79e7d4cf78b1a9ed4eb2ce7ba91e662ade58b6e0d516c13d7bdc18244c191cf0bdd55e04bbaca01afb89df02123d0855ecec960d8c52bc792f8e5b36e0e3cd697bf7c9e390bd165b7767d94ba2d5938dc555e3918ac05a9d5c66293b204a104776c03a43d59764cce4a28e85f1e54b36b315367ed8f37ac691ef6a11b",
"scheme": "https",
"urlStyle": "VIRTUAL_HOSTED_STYLE",
"expectedCanonicalRequest": "GET\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",
"expectedStringToSign": "GOOG4-RSA-SHA256\n20190201T090000Z\n20190201/auto/storage/goog4_request\n4a3352bc39ec2a3eec47d568fb05688e66b0d0f88bbe9890fa83f53bf756483e"
}
]