Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_login_success(self):
params = get_user_params()
login(params)
self.assertEqual(params.session_token, vault_env.session_token)
self.assertEqual(params.data_key, vault_env.data_key)
def test_login_success_params(self):
TestLogin.dataKeyAsEncParam = True
params = get_user_params()
login(params)
self.assertEqual(params.data_key, vault_env.data_key)
self.assertEqual(params.session_token, vault_env.session_token)
def test_login_success_2fa_device_token(self):
TestLogin.has2fa = True
params = get_user_params()
params.mfa_token = vault_env.device_token
params.mfa_type = 'device_token'
login(params)
self.assertEqual(params.session_token, vault_env.session_token)
self.assertEqual(params.data_key, vault_env.data_key)
def test_login_invalid_user(self):
params = get_user_params()
params.user = 'wrong.user@keepersecurity.com'
with self.assertRaises(AuthenticationError):
login(params)
'role_id': 123456789,
'public_key': vault_env.encoded_public_key
}]
}
elif call_no == 2:
pass
else:
raise Exception()
return rs
self.v2_execute_mock.side_effect = return_auth_expired
with mock.patch('keepercommander.api.accept_account_transfer_consent') as m_transfer:
m_transfer.return_value = True
with self.assertLogs():
login(params)
m_transfer.assert_called()
self.assertEqual(params.session_token, vault_env.session_token)
self.assertEqual(params.data_key, vault_env.data_key)
def test_login_failed(self):
params = get_user_params()
params.password = '123456'
with self.assertRaises(AuthenticationError):
login(params)
def setUpClass(cls):
cls.params = KeeperParams()
read_config_file(cls.params)
api.login(cls.params)
TestConnectedCommands.wipe_out_data()
elif call_no == 2:
pass
else:
raise Exception()
return rs
self.v2_execute_mock.side_effect = return_auth_expired
with mock.patch('keepercommander.api.change_master_password') as m_passwd:
def password_changed(params):
params.password = vault_env.password
return True
m_passwd.side_effect = password_changed
with self.assertLogs():
login(params)
m_passwd.assert_called()
self.assertEqual(params.session_token, vault_env.session_token)
self.assertEqual(params.data_key, vault_env.data_key)
try:
push = EnterprisePushCommand()
push.execute(params, user=[email], file=file_name)
should_accept_share = True
except Exception as e:
logging.info('Error accepting shares: %s', e)
# first accept shares from enterprise admin
if should_accept_share:
try:
param1 = KeeperParams()
param1.server = new_params.server
param1.user = email
param1.password = password
param1.rest_context.device_id = params.rest_context.device_id
api.login(param1)
rq = {
'command': 'accept_share',
'from_email': params.user
}
api.communicate(param1, rq)
except Exception as e:
logging.info('Error accepting shares: %s', e)
# last expire password
if kwargs.get('expire'):
try:
rq = {
'command': 'set_master_password_expire',
'email': email
}
api.communicate(params, rq)
if not user:
return
if not password:
password = getpass.getpass(prompt='... {0:>16}: '.format('Password'), stream=None).strip()
if not password:
return
except KeyboardInterrupt as e:
logging.info('Canceled')
return
params.user = user.lower()
params.password = password
logging.info('Logging in...')
api.login(params)