Example #1
0
    def test_http_with_objects_in_target(self, mock_urlopen):

        check = _checks.HttpCheck('http', '//example.com/%(name)s')
        target = {'a': object(), 'name': 'target', 'b': 'test data'}
        self.assertTrue(
            check(target, dict(user='******', roles=['a', 'b', 'c']),
                  self.enforcer))
Example #2
0
    def test_http_with_strings_in_target(self):
        self.requests_mock.post("http://example.com/target", text='True')

        check = _checks.HttpCheck('http', '//example.com/%(name)s')
        target = {'a': 'some_string', 'name': 'target', 'b': 'test data'}
        self.assertTrue(
            check(target, dict(user='******', roles=['a', 'b', 'c']),
                  self.enforcer))
Example #3
0
    def test_http_with_strings_in_target(self):
        httpretty.register_uri(httpretty.POST,
                               "http://example.com/target",
                               body='True')
        httpretty.HTTPretty.allow_net_connect = False

        check = _checks.HttpCheck('http', '//example.com/%(name)s')
        target = {'a': 'some_string', 'name': 'target', 'b': 'test data'}
        self.assertTrue(
            check(target, dict(user='******', roles=['a', 'b', 'c']),
                  self.enforcer))
Example #4
0
    def test_accept(self):
        self.requests_mock.post('http://example.com/target', text='True')

        check = _checks.HttpCheck('http', '//example.com/%(name)s')

        target_dict = dict(name='target', spam='spammer')
        cred_dict = dict(user='******', roles=['a', 'b', 'c'])
        self.assertTrue(check(target_dict, cred_dict, self.enforcer))

        last_request = self.requests_mock.last_request
        self.assertEqual('POST', last_request.method)
        self.assertEqual(dict(target=target_dict, credentials=cred_dict),
                         self.decode_post_data(last_request.body))
Example #5
0
    def test_accept(self, mock_urlopen):
        check = _checks.HttpCheck('http', '//example.com/%(name)s')
        self.assertTrue(check(dict(name='target', spam='spammer'),
                              dict(user='******', roles=['a', 'b', 'c']),
                              self.enforcer))
        self.assertEqual(1, mock_urlopen.call_count)

        args = mock_urlopen.call_args[0]

        self.assertEqual('http://example.com/target', args[0])
        self.assertEqual(dict(
            target=dict(name='target', spam='spammer'),
            credentials=dict(user='******', roles=['a', 'b', 'c']),
        ), self.decode_post_data(args[1]))
Example #6
0
    def test_accept(self):
        httpretty.register_uri(httpretty.POST,
                               "http://example.com/target",
                               body='True')
        httpretty.HTTPretty.allow_net_connect = False

        check = _checks.HttpCheck('http', '//example.com/%(name)s')
        self.assertTrue(
            check(dict(name='target', spam='spammer'),
                  dict(user='******', roles=['a', 'b', 'c']), self.enforcer))

        last_request = httpretty.last_request()
        self.assertEqual('POST', last_request.method)
        self.assertEqual(
            dict(
                target=dict(name='target', spam='spammer'),
                credentials=dict(user='******', roles=['a', 'b', 'c']),
            ), self.decode_post_data(last_request.body.decode("utf8")))