Skip to content

Commit 84101da

Browse files
author
Mat Lord
authored
Merge pull request #30 from stax-labs/feat/test-sigv4
chore(tests): Add unit test for sigv4 headers
2 parents 74b98b9 + 3e82002 commit 84101da

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ help:
1717
@echo " run black"
1818

1919
test: lint
20-
PYTHONPATH=$(CURRENT_DIRECTORY)/src ${PYTHON} -m pytest --cov=. --cov-config=.coveragerc --cov-report term-missing tests/ --junitxml=coverage-reports/test-report.xml --cov-report xml:coverage-reports/coverage-report.xml
20+
PYTHONPATH=$(CURRENT_DIRECTORY) ${PYTHON} -m pytest --cov=. --cov-config=.coveragerc --cov-report term-missing tests/ --junitxml=coverage-reports/test-report.xml --cov-report xml:coverage-reports/coverage-report.xml
2121

2222
install:
2323
python3 -m venv ${VIRTUAL_ENV}

tests/test_auth.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
import unittest
1010
import jwt
1111
import botocore
12+
import requests
13+
import responses
1214

1315
from botocore import UNSIGNED
1416
from botocore.client import Config as BotoConfig
1517
from botocore.stub import Stubber, ANY
1618

1719
from staxapp.auth import StaxAuth
20+
from staxapp.config import Config
1821
from staxapp.exceptions import InvalidCredentialsException
1922

2023

@@ -197,6 +200,35 @@ def stub_cognito_creds(self, token: str):
197200

198201
self.cognito_stub.activate()
199202

203+
@responses.activate
204+
def testSigV4Headers(self):
205+
"""
206+
Test sigv4 signed auth headers
207+
"""
208+
# Get signed auth headers
209+
sa = StaxAuth("ApiAuth")
210+
id_creds = {
211+
"Credentials": {
212+
"AccessKeyId": "ASIAX000000000000000",
213+
"SecretKey": "0000000000000000000000000000000000000000",
214+
"SessionToken": "a-totally-valid-JWT",
215+
"Expiration": datetime.datetime(2020, 1, 14, 11, 52, 26),
216+
}
217+
}
218+
auth = sa.sigv4_signed_auth_headers(id_creds)
219+
220+
# Mock request
221+
response_dict = {"Status": "OK"}
222+
responses.add(
223+
responses.GET,
224+
f"{Config.api_base_url()}/auth",
225+
json=response_dict,
226+
status=200,
227+
)
228+
response = requests.get(f"{Config.api_base_url()}/auth", auth=auth)
229+
self.assertEqual(response.json(), response_dict)
230+
self.assertIn("Authorization", response.request.headers)
231+
200232

201233
if __name__ == "__main__":
202234
unittest.main()

0 commit comments

Comments
 (0)