Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions tests/protocol_test_suite_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# file to handle loading and parsing of mauth protocol test suite cases in order
# to run them as unit tests

from datetime import datetime
from datetime import datetime, timezone
import glob
import os
import json
Expand Down Expand Up @@ -29,7 +29,7 @@ def __init__(self):
with open(os.path.join(MAUTH_PROTOCOL_DIR, "signing-params/rsa-key-pub"), "r") as key_file:
self.public_key = key_file.read()

self.request_time = datetime.fromtimestamp(float(config["request_time"]))
self.request_time = datetime.fromtimestamp(float(config["request_time"]), timezone.utc)
self.app_uuid = config["app_uuid"]
self.signer = Signer(config["app_uuid"], private_key, "v2")
self.additional_attributes = {"app_uuid": config["app_uuid"], "time": config["request_time"]}
Expand All @@ -41,12 +41,12 @@ def cases(self):
class ProtocolTestSuiteParser:
def __init__(self, case_path):
self.case_name = os.path.basename(case_path)
self.request_attributes = self.request_attributes(case_path)
self.request_attributes = self.build_request_attributes(case_path)
self.sts = self.read_file_by_extension(case_path, "sts")
self.sig = self.read_file_by_extension(case_path, "sig")
self.auth_headers = self.read_json_by_extension(case_path, "authz")
self.auth_headers = {k: str(v) for k, v in self.read_json_by_extension(case_path, "authz").items()}

def request_attributes(self, case_path):
def build_request_attributes(self, case_path):
req = self.read_json_by_extension(case_path, "req")
body_file_path = os.path.join(case_path, req["body_filepath"]) if "body_filepath" in req else ""
body = self.read_file(body_file_path, "rb") if body_file_path else req.get("body")
Expand Down
2 changes: 1 addition & 1 deletion tests/protocol_test_suite_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_protocol_test_suite(self):
for case_path in TEST_SUITE.cases():
parser = ProtocolTestSuiteParser(case_path)
request_signable = RequestSignable(**parser.request_attributes)
signed_headers_v2 = TEST_SUITE.signer.signed_headers_v2(request_signable, TEST_SUITE.additional_attributes)
signed_headers_v2 = TEST_SUITE.signer.signed_headers_v2(request_signable)
if "authentication-only" not in case_path:
with self.subTest(test="string_to_sign_v2", case_name=parser.case_name):
string_to_sign = request_signable.string_to_sign_v2(TEST_SUITE.additional_attributes)
Expand Down
10 changes: 5 additions & 5 deletions tests/signer_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
from datetime import datetime
from datetime import datetime, timezone
import os
from freezegun import freeze_time
from mauth_client.signable import RequestSignable
from mauth_client.signer import Signer

APP_UUID = "5ff4257e-9c16-11e0-b048-0026bbfffe5e"
EPOCH = "1309891855" # 2011-07-05 18:50:00 UTC
EPOCH_DATETIME = datetime.fromtimestamp(float(EPOCH))
EPOCH_DATETIME = datetime.fromtimestamp(float(EPOCH), timezone.utc)
REQUEST_ATTRIBUTES = {"method": "GET", "url": "https://example.org/studies/123/users?k=v"}
ADDITIONAL_ATTRIBUTES = {"app_uuid": APP_UUID, "time": EPOCH}

Expand Down Expand Up @@ -40,7 +40,7 @@ def test_signed_headers(self):
"MCC-Time": EPOCH,
}

signed_headers = self.signer.signed_headers(self.signable, ADDITIONAL_ATTRIBUTES)
signed_headers = self.signer.signed_headers(self.signable)
self.assertEqual(signed_headers.keys(), expected.keys())
self.assertRegex(signed_headers["X-MWS-Authentication"], expected["X-MWS-Authentication"])
self.assertRegex(signed_headers["MCC-Authentication"], expected["MCC-Authentication"])
Expand All @@ -51,7 +51,7 @@ def test_signed_headers(self):
def test_signed_headers_v1_only(self):
expected = {"X-MWS-Authentication": r"\AMWS {}:".format(APP_UUID), "X-MWS-Time": EPOCH}

signed_headers = self.signer_v1_only.signed_headers(self.signable, ADDITIONAL_ATTRIBUTES)
signed_headers = self.signer_v1_only.signed_headers(self.signable)
self.assertEqual(signed_headers.keys(), expected.keys())
self.assertRegex(signed_headers["X-MWS-Authentication"], expected["X-MWS-Authentication"])
self.assertEqual(signed_headers["X-MWS-Time"], expected["X-MWS-Time"])
Expand All @@ -60,7 +60,7 @@ def test_signed_headers_v1_only(self):
def test_signed_headers_v2_only(self):
expected = {"MCC-Authentication": r"MWSV2 {}:[^;]*;".format(APP_UUID), "MCC-Time": EPOCH}

signed_headers = self.signer_v2_only.signed_headers(self.signable, ADDITIONAL_ATTRIBUTES)
signed_headers = self.signer_v2_only.signed_headers(self.signable)
self.assertEqual(signed_headers.keys(), expected.keys())
self.assertRegex(signed_headers["MCC-Authentication"], expected["MCC-Authentication"])
self.assertEqual(signed_headers["MCC-Time"], expected["MCC-Time"])
Expand Down
Loading