@@ -969,3 +969,41 @@ def test_remote():
969
969
assert kb2 .httpc_params == {'timeout' : (2 , 2 )}
970
970
assert kb2 .imp_jwks
971
971
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