def test_custom_condition_fail(self): def custom(req): return False addCommitCondition("custom-condition", custom=custom) checker = CommitChecker(self.request, ('custom-condition', )) self.assertTrue(not checker.can_commit())
def test_custom_condition_fail(self): def custom(req): return False addCommitCondition("custom-condition", custom=custom) checker = CommitChecker(self.request, ('custom-condition',)) self.assertTrue(not checker.can_commit())
def test_custom_condition_success(self): def custom(req): return True addCommitCondition("custom-condition", custom=custom) checker = CommitChecker(self.request, ('custom-condition', )) self.assertTrue(checker.can_commit())
def test_custom_condition_success(self): def custom(req): return True addCommitCondition("custom-condition", custom=custom) checker = CommitChecker(self.request, ('custom-condition',)) self.assertTrue(checker.can_commit())
def test_multiple_conditions_all_fail(self): addCommitCondition("path", path="/foo/bar") addCommitCondition("method", request_method="POST", host="www.foobar.com") self.request.set('ACTUAL_URL', self.portal_url + '/foo') self.request.set('REQUEST_METHOD', 'GET') self.request.set('BASE1', 'http://www.foboar.com') checker = CommitChecker(self.request, ('path', 'method')) self.assertTrue(not checker.can_commit())
def test_all_criteria_not_met(self): addCommitCondition("condition", path="/foo/bar", request_method="POST", host="www.foobar.com") self.request.set('ACTUAL_URL', self.portal_url + '/foo') self.request.set('REQUEST_METHOD', 'GET') self.request.set('BASE1', 'http://www.foboar.com') checker = CommitChecker(self.request, ('condition',)) self.assertTrue(not checker.can_commit())
def test_all_criteria_not_met(self): addCommitCondition("condition", path="/foo/bar", request_method="POST", host="www.foobar.com") self.request.set('ACTUAL_URL', self.portal_url + '/foo') self.request.set('REQUEST_METHOD', 'GET') self.request.set('BASE1', 'http://www.foboar.com') checker = CommitChecker(self.request, ('condition', )) self.assertTrue(not checker.can_commit())
def setUp(self): from wildcard.lockdown import addCommitCondition self.portal = self.layer["portal"] self.request = self.layer["request"] self.portal_url = self.portal.absolute_url() addCommitCondition("user-area", path="/users*", request_method="POST") folder = createObject(self.portal, "Folder", "users") createObject(folder, "News Item", "test1", title="Test 1") createObject(folder, "News Item", "test2", title="Test 2") createObject(self.portal, "Document", "testpage", title="Test page") transaction.commit() self.browser = Browser(self.layer["app"]) self.browser.handleErrors = False browserLogin(self.portal, self.browser)
def setUp(self): from wildcard.lockdown import addCommitCondition self.portal = self.layer['portal'] self.request = self.layer['request'] self.portal_url = self.portal.absolute_url() addCommitCondition("user-area", path="/users*", request_method="POST") folder = createObject(self.portal, 'Folder', 'users') createObject(folder, 'News Item', 'test1', title="Test 1") createObject(folder, 'News Item', 'test2', title="Test 2") createObject(self.portal, 'Document', 'testpage', title="Test page") registry = getUtility(IRegistry) self._settings = registry.forInterface(ISettings) transaction.commit() self.browser = Browser(self.layer['app']) self.browser.handleErrors = False browserLogin(self.portal, self.browser)
def test_host_condition_wildcard_fail(self): addCommitCondition("host-condition", host="*.bar.com") self.request.set('BASE1', 'http://fob.oar.com') checker = CommitChecker(self.request, ('host-condition',)) self.assertTrue(not checker.can_commit())
def test_portal_type_condition_fail(self): addCommitCondition("pt-condition", portal_type="foobar") self.request.set('PARENTS', [FakePT('foboar')]) checker = CommitChecker(self.request, ('pt-condition', )) self.assertTrue(not checker.can_commit())
def test_request_condition_fail(self): addCommitCondition("request-method-condition", request_method="POST") self.request.set('REQUEST_METHOD', 'GET') checker = CommitChecker(self.request, ('request-method-condition',)) self.assertTrue(not checker.can_commit())
def test_host_condition_plus_port_success(self): addCommitCondition("host-condition", host="www.foobar.com:8080") self.request.set('BASE1', 'https://www.foobar.com:8080') checker = CommitChecker(self.request, ('host-condition',)) self.assertTrue(checker.can_commit())
def test_path_condition_fail_with_wildcard(self): addCommitCondition("path-condition", path="/foo*") self.request.set('ACTUAL_URL', self.portal_url + '/fob/oar') checker = CommitChecker(self.request, ('path-condition',)) self.assertTrue(not checker.can_commit())
def test_request_condition_success_case_insensitive(self): addCommitCondition("request-method-condition", request_method="put") self.request.set('REQUEST_METHOD', 'PUT') checker = CommitChecker(self.request, ('request-method-condition',)) self.assertTrue(checker.can_commit())
def test_path_condition_success(self): addCommitCondition("path-condition", path="/foo/bar") self.request.set('ACTUAL_URL', self.portal_url + '/foo/bar') checker = CommitChecker(self.request, ('path-condition',)) self.assertTrue(checker.can_commit())
def test_path_condition_success(self): addCommitCondition("path-condition", path="/foo/bar") self.request.set('ACTUAL_URL', self.portal_url + '/foo/bar') checker = CommitChecker(self.request, ('path-condition', )) self.assertTrue(checker.can_commit())
def test_request_condition_success_case_insensitive(self): addCommitCondition("request-method-condition", request_method="put") self.request.set('REQUEST_METHOD', 'PUT') checker = CommitChecker(self.request, ('request-method-condition', )) self.assertTrue(checker.can_commit())
def test_path_condition_fail_with_wildcard(self): addCommitCondition("path-condition", path="/foo*") self.request.set('ACTUAL_URL', self.portal_url + '/fob/oar') checker = CommitChecker(self.request, ('path-condition', )) self.assertTrue(not checker.can_commit())
def test_request_condition_fail(self): addCommitCondition("request-method-condition", request_method="POST") self.request.set('REQUEST_METHOD', 'GET') checker = CommitChecker(self.request, ('request-method-condition', )) self.assertTrue(not checker.can_commit())
def test_portal_type_condition_fail(self): addCommitCondition("pt-condition", portal_type="foobar") self.request.set('PARENTS', [FakePT('foboar')]) checker = CommitChecker(self.request, ('pt-condition',)) self.assertTrue(not checker.can_commit())
from wildcard.lockdown import addCommitCondition addCommitCondition("Allow logged in on host", logged_in=True, host="backend.myhost.com")
def test_host_condition_wildcard_fail(self): addCommitCondition("host-condition", host="*.bar.com") self.request.set('BASE1', 'http://fob.oar.com') checker = CommitChecker(self.request, ('host-condition', )) self.assertTrue(not checker.can_commit())
def test_host_condition_plus_port_success(self): addCommitCondition("host-condition", host="www.foobar.com:8080") self.request.set('BASE1', 'https://www.foobar.com:8080') checker = CommitChecker(self.request, ('host-condition', )) self.assertTrue(checker.can_commit())