Exemple #1
0
    def test_publisher_connect_pat(self):
        """validate publisher issues a pat-authorization header"""
        #
        # Verify that a publisher will issue an `Authorization` header when
        # configure to use a personal access token.

        token = 'dummy-pat-value'
        expected_auth_value = 'Bearer {}'.format(token)

        config = self.config.clone()
        config.confluence_publish_token = token

        val = {
            'size': 1,
            'results': [{
                'name': 'My Space',
                'type': 'global',
            }],
        }

        with mock_confluence_instance(config) as daemon, \
                autocleanup_publisher(ConfluencePublisher) as publisher:
            daemon.register_get_rsp(200, val)

            publisher.init(config)
            publisher.connect()

            first_request = daemon.pop_get_request()
            self.assertIsNotNone(first_request)
            _, headers = first_request
            auth_header = headers.get('Authorization')
            if not auth_header:
                auth_header = headers.get('authorization')
            self.assertIsNotNone(auth_header)
            self.assertEqual(auth_header, expected_auth_value)
Exemple #2
0
    def test_publisher_connect_proxy(self):
        """validate publisher can find a valid space"""
        #
        # Verify that a publisher can query a Confluence instance and cache the
        # display name for a space.

        std_space_name = 'My Default Space'
        std_rsp = {
            'size': 1,
            'results': [{
                'name': std_space_name,
                'type': 'global',
            }],
        }

        proxy_space_name = 'My Proxy Space'
        proxy_rsp = {
            'size': 1,
            'results': [{
                'name': proxy_space_name,
                'type': 'global',
            }],
        }

        try:
            with mock_confluence_instance(self.config) as default_daemon,\
                    mock_confluence_instance() as proxy_daemon:

                proxy_host, proxy_port = proxy_daemon.server_address
                proxy_url = 'http://{}:{}/'.format(proxy_host, proxy_port)

                # check default space is accessible
                default_daemon.register_get_rsp(200, std_rsp)
                proxy_daemon.register_get_rsp(200, proxy_rsp)

                with autocleanup_publisher(ConfluencePublisher) as publisher:
                    publisher.init(self.config)
                    publisher.connect()

                self.assertEqual(publisher.space_display_name, std_space_name)

                # check confluence proxy option will go through proxy instance
                config = self.config.clone()
                config.confluence_proxy = proxy_url

                default_daemon.register_get_rsp(200, std_rsp)
                proxy_daemon.register_get_rsp(200, proxy_rsp)

                with autocleanup_publisher(ConfluencePublisher) as publisher:
                    publisher.init(config)
                    publisher.connect()

                self.assertEqual(publisher.space_display_name, proxy_space_name)

                # check system proxy option will go through proxy instance
                os.environ['http_proxy'] = proxy_url

                default_daemon.register_get_rsp(200, std_rsp)
                proxy_daemon.register_get_rsp(200, proxy_rsp)

                with autocleanup_publisher(ConfluencePublisher) as publisher:
                    publisher.init(self.config)
                    publisher.connect()

                self.assertEqual(publisher.space_display_name, proxy_space_name)
        finally:
            if 'http_proxy' in os.environ:
                del os.environ['http_proxy']