예제 #1
0
  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_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')
예제 #3
0
 def testNoDefaultAccountId(self):
     os.environ = {'LUCI_CONTEXT': 'path'}
     open().read.return_value = json.dumps({
         'local_auth': {
             'secret':
             'secret',
             'accounts': [{
                 'email': '*****@*****.**',
                 'id': 'system',
             }],
             'rpc_port':
             1234,
         }
     })
     self.assertFalse(auth.has_luci_context_local_auth())
     open.assert_called_with('path')
예제 #4
0
 def testHasLocalAuth(self):
     os.environ = {'LUCI_CONTEXT': 'path'}
     open().read.return_value = json.dumps({
         'local_auth': {
             'secret':
             'secret',
             'accounts': [
                 {
                     'email': '*****@*****.**',
                     'id': 'system',
                 },
                 {
                     'email': '*****@*****.**',
                     'id': 'task',
                 },
             ],
             'rpc_port':
             1234,
             'default_account_id':
             'task',
         },
     })
     self.assertTrue(auth.has_luci_context_local_auth())
     open.assert_called_with('path')
예제 #5
0
 def is_luci():
   return auth.has_luci_context_local_auth()
 def test_incorrect_port_format(self):
   _mockLocalAuth('account', 'secret', 'port')
   self.assertFalse(auth.has_luci_context_local_auth())
   with self.assertRaises(auth.LuciContextAuthError):
     auth.get_luci_context_access_token()
 def test_no_account_id(self):
   _mockLocalAuth(None, 'secret', 8080)
   self.assertFalse(auth.has_luci_context_local_auth())
   self.assertIsNone(auth.get_luci_context_access_token())
예제 #8
0
 def testNoLocalAuth(self):
     os.environ = {'LUCI_CONTEXT': 'path'}
     open().read.return_value = '{}'
     self.assertFalse(auth.has_luci_context_local_auth())
     open.assert_called_with('path')
예제 #9
0
 def testInvalidJsonFile(self):
     os.environ = {'LUCI_CONTEXT': 'path'}
     open().read.return_value = 'not-a-json-file'
     self.assertFalse(auth.has_luci_context_local_auth())
     open.assert_called_with('path')
예제 #10
0
 def testUnexistentPath(self):
     os.environ = {'LUCI_CONTEXT': 'path'}
     open.side_effect = OSError
     self.assertFalse(auth.has_luci_context_local_auth())
     open.assert_called_with('path')
예제 #11
0
 def testNoLuciContextEnvVar(self):
     os.environ = {}
     self.assertFalse(auth.has_luci_context_local_auth())
예제 #12
0
 def is_luci():
   return auth.has_luci_context_local_auth()
예제 #13
0
 def test_incorrect_port_format(self):
   self._mock_local_auth('account', 'secret', 'port')
   self.assertFalse(auth.has_luci_context_local_auth())
   with self.assertRaises(auth.LuciContextAuthError):
     auth.get_luci_context_access_token()
예제 #14
0
 def test_no_account_id(self):
   self._mock_local_auth(None, 'secret', 8080)
   self.assertFalse(auth.has_luci_context_local_auth())
   self.assertIsNone(auth.get_luci_context_access_token())