def test_incorrect_expiry_format(self): params = auth._LuciContextLocalAuthParams('account', 'secret', 8080) resp_content = { 'error_code': None, 'error_message': None, 'access_token': 'token', 'expiry': 'dead', } _mockResponse(200, json.dumps(resp_content)) with self.assertRaises(auth.LuciContextAuthError): auth._get_luci_context_access_token(params, datetime.datetime.min)
def test_incorrect_expiry_format(self): params = auth._LuciContextLocalAuthParams('account', 'secret', 8080) resp_content = { 'error_code': None, 'error_message': None, 'access_token': 'token', 'expiry': 'dead', } self._mock_loc_server_resp(200, json.dumps(resp_content)) with self.assertRaises(auth.LuciContextAuthError): auth._get_luci_context_access_token(params, datetime.datetime.min)
def test_incorrect_expiry_format(self): self._mock_local_auth('dead', 'beef', 10) resp_content = { 'error_code': None, 'error_message': None, 'access_token': 'token', 'expiry': 'dead', } self._mock_loc_server_resp(200, json.dumps(resp_content)) with self.assertRaises(auth.LuciContextAuthError): auth._get_luci_context_access_token(self.mock_env, datetime.datetime.min)
def test_expired_token(self): params = auth._LuciContextLocalAuthParams('account', 'secret', 8080) resp_content = { 'error_code': None, 'error_message': None, 'access_token': 'token', 'expiry': 1, } self._mock_loc_server_resp(200, json.dumps(resp_content)) with self.assertRaises(auth.LuciContextAuthError): auth._get_luci_context_access_token( params, datetime.datetime.utcfromtimestamp(1))
def test_correct_local_auth_format(self): self._mock_local_auth('dead', 'beef', 10) expiry_time = datetime.datetime.min + datetime.timedelta(minutes=60) resp_content = { 'error_code': None, 'error_message': None, 'access_token': 'token', 'expiry': time.mktime(expiry_time.timetuple()), } self._mock_loc_server_resp(200, json.dumps(resp_content)) token = auth._get_luci_context_access_token( self.mock_env, datetime.datetime.min) self.assertEquals(token.token, 'token')
def test_all_good(self): _mockLocalAuth('account', 'secret', 8080) self.assertTrue(auth.has_luci_context_local_auth()) expiry_time = datetime.datetime.min + datetime.timedelta(hours=1) resp_content = { 'error_code': None, 'error_message': None, 'access_token': 'token', 'expiry': (expiry_time - datetime.datetime.utcfromtimestamp(0)).total_seconds(), } _mockResponse(200, json.dumps(resp_content)) params = auth._get_luci_context_local_auth_params() token = auth._get_luci_context_access_token(params, datetime.datetime.min) self.assertEqual(token.token, 'token')
def test_all_good(self): self._mock_local_auth('account', 'secret', 8080) self.assertTrue(auth.has_luci_context_local_auth()) expiry_time = datetime.datetime.min + datetime.timedelta(hours=1) resp_content = { 'error_code': None, 'error_message': None, 'access_token': 'token', 'expiry': (expiry_time - datetime.datetime.utcfromtimestamp(0)).total_seconds(), } self._mock_loc_server_resp(200, json.dumps(resp_content)) params = auth._get_luci_context_local_auth_params() token = auth._get_luci_context_access_token(params, datetime.datetime.min) self.assertEquals(token.token, 'token')
def test_correct_local_auth_format(self): self._mock_local_auth('dead', 'beef', 10) expiry_time = datetime.datetime.min + datetime.timedelta(hours=1) resp_content = { 'error_code': None, 'error_message': None, 'access_token': 'token', 'expiry': (expiry_time - datetime.datetime.utcfromtimestamp(0)).total_seconds(), } self._mock_loc_server_resp(200, json.dumps(resp_content)) token = auth._get_luci_context_access_token(self.mock_env, datetime.datetime.min) self.assertEquals(token.token, 'token')
def test_incorrect_response_content_format(self): params = auth._LuciContextLocalAuthParams('account', 'secret', 8080) _mockResponse(200, '5') with self.assertRaises(auth.LuciContextAuthError): auth._get_luci_context_access_token(params, datetime.datetime.min)
def test_incorrect_response_content_format(self): self._mock_local_auth('dead', 'beef', 10) self._mock_loc_server_resp(200, '5') with self.assertRaises(auth.LuciContextAuthError): auth._get_luci_context_access_token(self.mock_env, datetime.datetime.min)
def test_no_account_id(self): self._mock_local_auth(None, 'bar', 10) token = auth._get_luci_context_access_token( self.mock_env, datetime.datetime.min) self.assertIsNone(token)
def test_incorrect_port_format(self): self._mock_local_auth('foo', 'bar', 'bar') with self.assertRaises(auth.LuciContextAuthError): auth._get_luci_context_access_token(self.mock_env, datetime.datetime.min)
def test_incorrect_response_content_format(self): params = auth._LuciContextLocalAuthParams('account', 'secret', 8080) self._mock_loc_server_resp(200, '5') with self.assertRaises(auth.LuciContextAuthError): auth._get_luci_context_access_token(params, datetime.datetime.min)