Пример #1
0
    def test_redirect(self, redirect, pulp_conf, url):
        remote_ip = "172.10.08.20"
        scheme = "https"
        host = "localhost"
        port = 443
        path = "/var/pulp/content/zoo/lion"
        redirect_path = "/streamer"
        query = "arch=x86"
        conf = {
            "authentication": {"rsa_key": "/tmp/key"},
            "lazy": {"enabled": "true", "redirect_host": host, "redirect_port": port, "redirect_path": redirect_path},
        }
        pulp_conf.get.side_effect = lambda s, p: conf.get(s).get(p)
        self.environ["QUERY_STRING"] = query
        self.environ["REMOTE_ADDR"] = remote_ip
        request = Mock(environ=self.environ, path_info=path)
        key = Mock()

        # test
        reply = ContentView.redirect(request, key)

        # validation
        url.assert_called_once_with(ContentView.urljoin(scheme, host, port, redirect_path, path, query))
        url.return_value.sign.assert_called_once_with(key, remote_ip=remote_ip)
        redirect.assert_called_once_with(str(url.return_value.sign.return_value))
        self.assertEqual(reply, redirect.return_value)
Пример #2
0
    def test_redirect(self, redirect, pulp_conf, url):
        remote_ip = '172.10.08.20'
        scheme = 'https'
        host = 'localhost'
        port = 443
        path = '/var/pulp/content/zoo/lion'
        redirect_path = '/streamer'
        query = 'arch=x86'
        conf = {
            'authentication': {
                'rsa_key': '/tmp/key'
            },
            'lazy': {
                'enabled': 'true',
                'redirect_host': host,
                'redirect_port': port,
                'redirect_path': redirect_path,
            }
        }
        pulp_conf.get.side_effect = lambda s, p: conf.get(s).get(p)
        self.environ['QUERY_STRING'] = query
        self.environ['REMOTE_ADDR'] = remote_ip
        request = Mock(environ=self.environ, path_info=path)
        key = Mock()

        # test
        reply = ContentView.redirect(request, key)

        # validation
        url.assert_called_once_with(ContentView.urljoin(
            scheme, host, port, redirect_path, path, query))
        url.return_value.sign.assert_called_once_with(key, remote_ip=remote_ip)
        redirect.assert_called_once_with(str(url.return_value.sign.return_value))
        self.assertEqual(reply, redirect.return_value)
Пример #3
0
 def test_urljoin(self):
     scheme = "http"
     host = "redhat.com"
     port = 123
     base = "http://host"  # no trailing /
     path = "/my/path/"  # absolute path
     query = "age=10"
     joined = ContentView.urljoin(scheme, host, port, base, path, query)
     self.assertEqual(joined, "http://redhat.com:123http://host/my/path/?age=10")
Пример #4
0
 def test_urljoin(self):
     scheme = 'http'
     host = 'redhat.com'
     port = 123
     base = 'http://host'  # no trailing /
     path = '/my/path/'    # absolute path
     query = 'age=10'
     joined = ContentView.urljoin(scheme, host, port, base, path, query)
     self.assertEqual(joined, 'http://redhat.com:123http://host/my/path/?age=10')
Пример #5
0
 def test_urljoin(self):
     scheme = 'http'
     host = 'redhat.com'
     port = 123
     base = 'http://host'  # no trailing /
     path = '/my/path/'  # absolute path
     query = 'age=10'
     joined = ContentView.urljoin(scheme, host, port, base, path, query)
     self.assertEqual(joined,
                      'http://redhat.com:123http://host/my/path/?age=10')
Пример #6
0
    def test_redirect(self, redirect, pulp_conf, url):
        remote_ip = '172.10.08.20'
        scheme = 'http'
        host = 'localhost'
        port = 80
        path = '/var/pulp/content/zoo/lion'
        redirect_path = '/streamer'
        query = 'arch=x86'
        conf = {
            'authentication': {
                'rsa_key': '/tmp/key'
            },
            'lazy': {
                'enabled': 'true',
                'redirect_host': host,
                'redirect_port': port,
                'redirect_path': redirect_path,
            }
        }
        pulp_conf.get.side_effect = lambda s, p: conf.get(s).get(p)
        environ = {
            'REQUEST_SCHEME': scheme,
            'SERVER_NAME': host,
            'SERVER_PORT': port,
            'REDIRECT_URL': redirect_path,
            'QUERY_STRING': query,
            'REMOTE_ADDR': remote_ip
        }
        request = Mock(environ=environ, path_info=path)
        key = Mock()

        # test
        reply = ContentView.redirect(request, key)

        # validation
        url.assert_called_once_with(
            ContentView.urljoin(scheme, host, port, redirect_path, path,
                                query))
        url.return_value.sign.assert_called_once_with(key, remote_ip=remote_ip)
        redirect.assert_called_once_with(
            str(url.return_value.sign.return_value))
        self.assertEqual(reply, redirect.return_value)
Пример #7
0
    def test_redirect_default_host(self, redirect, pulp_conf, url):
        remote_ip = '172.10.08.20'
        scheme = 'https'
        host = self.environ['SERVER_NAME']
        port = self.environ['SERVER_PORT']
        path = '/var/pulp/content/zoo/lion'
        redirect_path = '/streamer'
        query = 'arch=x86'
        # this is in sync with server/pulp/server/config.py
        # as the actual server config is not used here
        conf = {
            'authentication': {
                'rsa_key': '/tmp/key'
            },
            'lazy': {
                'enabled': 'true',
                'redirect_host': '',
                'redirect_port': '',
                'redirect_path': redirect_path,
            }
        }
        pulp_conf.get.side_effect = lambda s, p: conf.get(s).get(p)
        self.environ['QUERY_STRING'] = query
        self.environ['REMOTE_ADDR'] = remote_ip
        request = Mock(environ=self.environ, path_info=path)
        key = Mock()

        # test
        reply = ContentView.redirect(request, key)

        # validation
        url.assert_called_once_with(
            ContentView.urljoin(scheme, host, port, redirect_path, path,
                                query))
        url.return_value.sign.assert_called_once_with(key, remote_ip=remote_ip)
        redirect.assert_called_once_with(
            str(url.return_value.sign.return_value))
        self.assertEqual(reply, redirect.return_value)
Пример #8
0
    def test_redirect_configured_host_port(self, redirect, pulp_conf, url):
        remote_ip = '172.10.08.20'
        scheme = 'https'
        host = 'pulptest.example.com'
        port = 8443
        path = '/var/pulp/content/zoo/lion'
        redirect_path = '/streamer'
        query = 'arch=x86'
        conf = {
            'authentication': {
                'rsa_key': '/tmp/key'
            },
            'lazy': {
                'enabled': 'true',
                'redirect_host': host,
                'redirect_port': port,
                'redirect_path': redirect_path,
            }
        }
        pulp_conf.get.side_effect = lambda s, p: conf.get(s).get(p)
        self.environ['QUERY_STRING'] = query
        self.environ['REMOTE_ADDR'] = remote_ip
        request = Mock(environ=self.environ, path_info=path)
        key = Mock()

        # test
        reply = ContentView.redirect(request, key)

        # validation
        url.assert_called_once_with(
            ContentView.urljoin(scheme, host, port, redirect_path, path,
                                query))
        url.return_value.sign.assert_called_once_with(key, remote_ip=remote_ip)
        redirect.assert_called_once_with(
            str(url.return_value.sign.return_value))
        self.assertEqual(reply, redirect.return_value)