def test_get_access_denied(self): """Ensure it denies when every condition is false.""" self.mock.get_current_user.return_value = self.user self.mock.is_current_user_admin.return_value = False self.mock._is_privileged_user.return_value = False self.mock._is_domain_allowed.return_value = False self.mock.is_fuzzer_allowed_for_user.return_value = False self.mock.is_job_allowed_for_user.return_value = False self.assertEqual(access.get_access(fuzzer_name='test'), access.UserAccess.Denied) self.assertEqual(access.get_access(), access.UserAccess.Denied)
def test_get_access_external_job(self): """For a job, ensure it allows when a user is allowed.""" self.mock.get_current_user.return_value = self.user self.mock.is_current_user_admin.return_value = False self.mock._is_privileged_user.return_value = False self.mock._is_domain_allowed.return_value = False self.mock.is_fuzzer_allowed_for_user.return_value = False self.mock.is_job_allowed_for_user.return_value = True self.assertEqual(access.get_access(job_type='test'), access.UserAccess.Allowed) self.assertEqual(access.get_access(), access.UserAccess.Denied)
def test_get_access_allowed_domain(self): """For an allowed domain, ensure it allows when privileged is not needed, and ensure it denies when privileged is needed.""" self.mock.get_current_user.return_value = self.user self.mock.is_current_user_admin.return_value = False self.mock._is_privileged_user.return_value = False self.mock._is_domain_allowed.return_value = True self.assertEqual(access.get_access(need_privileged_access=False), access.UserAccess.Allowed) self.assertEqual(access.get_access(need_privileged_access=True), access.UserAccess.Denied)
def test_blacklisted_user(self): """Test blacklisted users.""" self.mock.is_current_user_admin.return_value = False self.mock._is_domain_allowed.return_value = True self.mock._is_blacklisted_user.return_value = True self.assertEqual(access.get_access(), access.UserAccess.Denied)
def test_get_access_privileged(self): """Ensure it allows when user is privileged.""" self.mock.get_current_user.return_value = self.user self.mock.is_current_user_admin.return_value = False self.mock._is_privileged_user.return_value = True self.assertEqual(access.get_access(), access.UserAccess.Allowed)
def test_get_access_access_redirect(self): """Ensure it redirects when user is None.""" self.mock.get_current_user.return_value = None self.mock.is_current_user_admin.return_value = False self.assertEqual(access.get_access(), access.UserAccess.Redirected)