From 9f60cb7b9f7d621d9260a26a6fa5c42ed7abe4a4 Mon Sep 17 00:00:00 2001 From: Yugang Wang Date: Mon, 21 Aug 2017 11:37:14 -0700 Subject: [PATCH] add a test --- tests/test_refresh_token.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/test_refresh_token.py b/tests/test_refresh_token.py index 90340457..41a11911 100644 --- a/tests/test_refresh_token.py +++ b/tests/test_refresh_token.py @@ -46,41 +46,48 @@ from tests.util import parameters as cp class TestRefreshToken(unittest.TestCase): - def setUp(self): - self.response_options = { 'refreshedRefresh' : True } - self.response = util.create_response(self.response_options) - self.wire_response = self.response['wireResponse'] @httpretty.activate def test_happy_path_with_resource_client_secret(self): - tokenRequest = util.setup_expected_refresh_token_request_response(200, self.wire_response, self.response['authority'], self.response['resource'], cp['clientSecret']) + response_options = { 'refreshedRefresh' : True } + response = util.create_response(response_options) + wire_response = response['wireResponse'] + tokenRequest = util.setup_expected_refresh_token_request_response(200, wire_response, response['authority'], response['resource'], cp['clientSecret']) context = adal.AuthenticationContext(cp['authorityTenant']) def side_effect (tokenfunc): - return self.response['decodedResponse'] + return response['decodedResponse'] context._acquire_token = mock.MagicMock(side_effect=side_effect) token_response = context.acquire_token_with_refresh_token(cp['refreshToken'], cp['clientId'], cp['clientSecret'], cp['resource']) self.assertTrue( - util.is_match_token_response(self.response['decodedResponse'], token_response), + util.is_match_token_response(response['decodedResponse'], token_response), 'The response did not match what was expected: ' + str(token_response) ) @httpretty.activate def test_happy_path_with_resource_adfs(self): - tokenRequest = util.setup_expected_refresh_token_request_response(200, self.wire_response, self.response['authority'], self.response['resource'], cp['clientSecret']) + user_id = 'foo@bar.com' + response_options = { + 'refreshedRefresh' : True, + 'mrrt': False + } + response = util.create_response(response_options) + wire_response = response['wireResponse'] + tokenRequest = util.setup_expected_refresh_token_request_response(200, wire_response, response['authority'], response['resource'], cp['clientSecret']) context = adal.AuthenticationContext(cp['authorityTenant']) def side_effect (tokenfunc): - return self.response['decodedResponse'] + return response['decodedResponse'] context._acquire_token = mock.MagicMock(side_effect=side_effect) - token_response = context.acquire_token(cp['refreshToken'], cp['clientId'], cp['clientSecret'], cp['resource']) + token_response = context.acquire_token(cp['resource'], user_id, cp['clientId']) self.assertTrue( - util.is_match_token_response(self.response['decodedResponse'], token_response), + util.is_match_token_response(response['decodedResponse'], token_response), 'The response did not match what was expected: ' + str(token_response) ) + if __name__ == '__main__': unittest.main()