def test_executeAsUser_NT(self): """ Test executing as a different user. """ test_user = mk.getTestUser(u'normal') with system_users.executeAsUser( username=test_user.name, token=test_user.token): self.assertEqual( test_user.name, system_users.getCurrentUserName()) self.assertEqual( mk.username, system_users.getCurrentUserName())
def test_executeAsUser(self): """ It uses the token to impersonate the account under which this process is executed.. """ test_user = mk.getTestUser(u'domain') self.assertNotEqual(test_user.name, system_users.getCurrentUserName()) with system_users.executeAsUser( username=test_user.name, token=test_user.token): self.assertEqual( test_user.name, system_users.getCurrentUserName())
def test_getImpersonationContext_use_impersonation_nt(self): """ If use_impersonation is `True` an impersonation context is active. Inside the context we have the new user and outside we have the normal user. """ test_user = mk.getTestUser(u'normal') avatar = ImpersonatedAvatarImplementation( name=test_user.name, token=test_user.token, use_impersonation=True, ) with avatar.getImpersonationContext(): self.assertEqual( test_user.name, system_users.getCurrentUserName()) self.assertEqual( mk.username, system_users.getCurrentUserName())
def test_authenticateWithUsernameAndPassword_good(self): """ Return `True` when username and passwords are valid, together with a token that can be used for impersonating the account. """ result, token = system_users.authenticateWithUsernameAndPassword( username=TEST_ACCOUNT_USERNAME_DOMAIN, password=TEST_ACCOUNT_PASSWORD_DOMAIN, ) self.assertIsTrue(result) self.assertIsNotNone(token) with system_users.executeAsUser( username=TEST_ACCOUNT_USERNAME_DOMAIN, token=token): self.assertEqual( TEST_ACCOUNT_USERNAME_DOMAIN, system_users.getCurrentUserName(), )
def test_getCurrentUserName_NT(self): """ Check for helper method. """ self.assertEqual( mk.username, system_users.getCurrentUserName())