Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(784)

Unified Diff: appengine/swarming/swarming_bot/bot_code/remote_client_test.py

Issue 2958413002: Add 'mint_oauth_token' method to RPC client. (Closed)
Patch Set: Add 'mint_oauth_token' method to RPC client. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/swarming/swarming_bot/bot_code/remote_client_grpc.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/swarming/swarming_bot/bot_code/remote_client_test.py
diff --git a/appengine/swarming/swarming_bot/bot_code/remote_client_test.py b/appengine/swarming/swarming_bot/bot_code/remote_client_test.py
index 7bfe8f6244ded3e230a8d877b3da8efe114c6070..b264ccc2215e8a225934e9187cabf4c857cc4f69 100755
--- a/appengine/swarming/swarming_bot/bot_code/remote_client_test.py
+++ b/appengine/swarming/swarming_bot/bot_code/remote_client_test.py
@@ -77,6 +77,44 @@ class TestRemoteClient(auto_stub.TestCase):
self.mock(time, 'time', lambda: 103500)
self.assertEqual({'Now': '103500'}, c.get_authentication_headers())
+ def test_mint_oauth_token_ok(self):
+ fake_resp = {
+ 'service_account': 'blah@example.com',
+ 'access_token': 'abc',
+ 'expiry': 12345,
+ }
+
+ c = remote_client.RemoteClientNative('http://localhost:1', None)
+ def mocked_call(url_path, data):
+ self.assertEqual('/swarming/api/v1/bot/oauth_token', url_path)
+ self.assertEqual({
+ 'account_id': 'account_id',
+ 'id': 'bot_id',
+ 'scopes': ['a', 'b'],
+ 'task_id': 'task_id',
+ }, data)
+ return fake_resp
+ self.mock(c, '_url_read_json', mocked_call)
+
+ resp = c.mint_oauth_token('task_id', 'bot_id', 'account_id', ['a', 'b'])
+ self.assertEqual(fake_resp, resp)
+
+ def test_mint_oauth_token_transient_err(self):
+ c = remote_client.RemoteClientNative('http://localhost:1', None)
+ def mocked_call(*_args, **_kwargs):
+ return None # that's how net.url_read_json indicates HTTP 500 :-/
+ self.mock(c, '_url_read_json', mocked_call)
+ with self.assertRaises(remote_client.InternalError):
+ c.mint_oauth_token('task_id', 'bot_id', 'account_id', ['a', 'b'])
+
+ def test_mint_oauth_token_fatal_err(self):
+ c = remote_client.RemoteClientNative('http://localhost:1', None)
+ def mocked_call(*_args, **_kwargs):
+ return {'error': 'blah'}
+ self.mock(c, '_url_read_json', mocked_call)
+ with self.assertRaises(remote_client.MintOAuthTokenError):
+ c.mint_oauth_token('task_id', 'bot_id', 'account_id', ['a', 'b'])
+
if __name__ == '__main__':
logging.basicConfig(
« no previous file with comments | « appengine/swarming/swarming_bot/bot_code/remote_client_grpc.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698