Skip to content

Commit 70d640a

Browse files
committed
add test with not-modified-since
1 parent c8524c3 commit 70d640a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/test_03_key_bundle.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,3 +969,41 @@ def test_remote():
969969
assert kb2.httpc_params == {'timeout': (2, 2)}
970970
assert kb2.imp_jwks
971971
assert kb2.last_updated
972+
973+
def test_remote_not_modified():
974+
source = 'https://example.com/keys.json'
975+
headers = {
976+
"Date": "Fri, 15 Mar 2019 10:14:25 GMT",
977+
"Last-Modified": "Fri, 1 Jan 1970 00:00:00 GMT",
978+
}
979+
headers = {}
980+
981+
# Mock response
982+
httpc_params = {'timeout': (2, 2)} # connect, read timeouts in seconds
983+
kb = KeyBundle(source=source, httpc=requests.request,
984+
httpc_params=httpc_params)
985+
986+
with responses.RequestsMock() as rsps:
987+
rsps.add(method="GET", url=source, json=JWKS_DICT, status=200, headers=headers)
988+
assert kb.do_remote()
989+
assert kb.last_remote == headers.get("Last-Modified")
990+
timeout1 = kb.time_out
991+
992+
with responses.RequestsMock() as rsps:
993+
rsps.add(method="GET", url=source, status=304, headers=headers)
994+
assert kb.do_remote()
995+
assert kb.last_remote == headers.get("Last-Modified")
996+
timeout2 = kb.time_out
997+
998+
assert timeout1 == timeout2
999+
1000+
exp = kb.dump()
1001+
kb2 = KeyBundle().load(exp)
1002+
assert kb2.source == source
1003+
assert len(kb2.keys()) == 3
1004+
assert len(kb2.get("rsa")) == 1
1005+
assert len(kb2.get("oct")) == 1
1006+
assert len(kb2.get("ec")) == 1
1007+
assert kb2.httpc_params == {'timeout': (2, 2)}
1008+
assert kb2.imp_jwks
1009+
assert kb2.last_updated

0 commit comments

Comments
 (0)