Browse Source

add tests of /session auth-ed and not

master
Adam Gibson 4 years ago
parent
commit
a04fb60f1d
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 35
      jmclient/test/test_wallet_rpc.py

35
jmclient/test/test_wallet_rpc.py

@ -158,6 +158,27 @@ class TrialTestWRPC_DisplayWallet(WalletRPCTestBase, unittest.TestCase):
yield handler(body, response.code)
return True
@defer.inlineCallbacks
def do_session_request(self, agent, addr, handler=None, token=None):
""" A `None` value for handler is reserved for the case
where we expect an Unauthorized request because we provided a token,
but it is not valid.
For other cases, provide the url prefix before `/session' as addr,
and we expect a 200 if token is valid *or* token is None, but contents
are to be checked by provided response handler callback.
"""
if handler is None:
assert token is not None
handler = self.unauthorized_session_request_handler
yield self.do_request(agent, b"GET", (addr+"/session").encode(),
None, handler, token)
def authorized_session_request_handler(self, response, code):
assert code == 200
def unauthorized_session_request_handler(self, response, code):
assert code == 401
@defer.inlineCallbacks
def test_create_list_lock_unlock(self):
""" A batch of tests in sequence here,
@ -195,6 +216,13 @@ class TrialTestWRPC_DisplayWallet(WalletRPCTestBase, unittest.TestCase):
yield self.do_request(agent, b"POST", addr, body,
self.process_create_wallet_response)
# 1a. Session request with valid token; should succeed
yield self.do_session_request(agent, root,
self.authorized_session_request_handler, token=self.jwt_token)
# 1b. Session request without token, even though one is active; should succeed
yield self.do_session_request(agent, root,
self.authorized_session_request_handler)
# 2. now *lock*
addr = root + "/wallet/" + wfn1 + "/lock"
addr = addr.encode()
@ -202,6 +230,13 @@ class TrialTestWRPC_DisplayWallet(WalletRPCTestBase, unittest.TestCase):
yield self.do_request(agent, b"GET", addr, None,
self.process_lock_response, token=self.jwt_token)
# 2a. Session request with now invalid token; should fail
yield self.do_session_request(agent, root,
self.unauthorized_session_request_handler, token=self.jwt_token)
# 2b. Session request without token, should still succeed.
yield self.do_session_request(agent, root,
self.authorized_session_request_handler)
# 3. Create this secondary wallet (so we can test re-unlock)
addr = root + "/wallet/create"
addr = addr.encode()

Loading…
Cancel
Save