Exemplo n.º 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)
Exemplo n.º 2
0
    def test_get_not_found(self, not_found, allow_access, pulp_conf, exists,
                           realpath):
        allow_access.return_value = True
        exists.return_value = False
        realpath.side_effect = lambda p: p.upper()

        host = 'localhost'
        path = '/pulp/content'

        conf = {
            'authentication': {
                'rsa_key': '/tmp/key'
            },
            'lazy': {
                'enabled': 'false',
            }
        }
        pulp_conf.get.side_effect = lambda s, p: conf.get(s).get(p)

        request = Mock(path_info=path)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        realpath.assert_called_once_with(path)
        exists.assert_called_once_with(path.upper())
        not_found.assert_called_once_with(path)
        self.assertEqual(reply, not_found.return_value)
Exemplo n.º 3
0
    def test_get_not_found(self, not_found, allow_access, pulp_conf, exists, realpath):
        allow_access.return_value = True
        exists.return_value = False
        realpath.side_effect = lambda p: p.upper()

        host = 'localhost'
        path = '/pulp/content'

        conf = {
            'authentication': {
                'rsa_key': '/tmp/key'
            },
            'lazy': {
                'enabled': 'false',
            }
        }
        pulp_conf.get.side_effect = lambda s, p: conf.get(s).get(p)

        request = Mock(path_info=path)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        realpath.assert_called_once_with(path)
        exists.assert_called_once_with(path.upper())
        not_found.assert_called_once_with(path)
        self.assertEqual(reply, not_found.return_value)
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def test_get_http(self, realpath, allow_access):
        realpath.side_effect = lambda p: "/some/content"
        host = "localhost"
        path = "/some/content/"
        self.environ["wsgi.url_scheme"] = "http"

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        view.x_send = Mock()
        self.assertRaises(content_views.Http404, view.get, request)
        self.assertEqual(0, allow_access.call_count)
Exemplo n.º 6
0
    def test_get_http(self, realpath, allow_access):
        realpath.side_effect = lambda p: '/some/content'
        host = 'localhost'
        path = '/some/content/'
        self.environ['wsgi.url_scheme'] = 'http'

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        view.x_send = Mock()
        self.assertRaises(content_views.Http404, view.get, request)
        self.assertEqual(0, allow_access.call_count)
Exemplo n.º 7
0
 def test_x_send_mime_type(self, access):
     path = '/my/path.rpm'
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     self.assertEqual(reply['X-SENDFILE'], path)
     self.assertEqual(reply['Content-Type'], 'application/x-rpm')
Exemplo n.º 8
0
 def test_x_send_mime_type(self, access):
     path = "/my/path.rpm"
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     self.assertEqual(reply["X-SENDFILE"], path)
     self.assertEqual(reply["Content-Type"], "application/x-rpm")
Exemplo n.º 9
0
 def test_x_send_cannot_read(self, forbidden, access):
     path = "/my/path"
     access.return_value = False
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     forbidden.assert_called_once_with()
     self.assertEqual(reply, forbidden.return_value)
Exemplo n.º 10
0
    def test_get_not_authorized(self, forbidden, allow_access):
        allow_access.return_value = False

        host = "localhost"
        path = "/var/lib/pulp/published/content"

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        self.assertEqual(reply, forbidden.return_value)
Exemplo n.º 11
0
    def test_get_outside_pub(self, forbidden, allow_access):
        allow_access.return_value = True

        host = "localhost"
        path = "/etc/pki/tls/private/myprecious.key"

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        self.assertEqual(reply, forbidden.return_value)
Exemplo n.º 12
0
    def test_get_outside_pub(self, forbidden, allow_access):
        allow_access.return_value = True

        host = 'localhost'
        path = '/etc/pki/tls/private/myprecious.key'

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        self.assertEqual(reply, forbidden.return_value)
Exemplo n.º 13
0
    def test_get_not_authorized(self, forbidden, allow_access):
        allow_access.return_value = False

        host = 'localhost'
        path = '/var/lib/pulp/published/content'

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        self.assertEqual(reply, forbidden.return_value)
Exemplo n.º 14
0
 def test_x_send_cannot_read(self, forbidden, access):
     path = '/my/path'
     access.return_value = False
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     forbidden.assert_called_once_with()
     self.assertEqual(reply, forbidden.return_value)
Exemplo n.º 15
0
 def test_x_send(self, access):
     path = '/my/path'
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     self.assertEqual(reply['X-SENDFILE'], path)
     self.assertEqual(reply['Content-Type'], 'application/octet-stream')
Exemplo n.º 16
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")
Exemplo n.º 17
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')
Exemplo n.º 18
0
 def test_x_send_mime_type_noencoding(self, access):
     path = '/my/path.xml.gz'
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     self.assertEqual(reply['X-SENDFILE'], path)
     # If the normal mimetypes module was used, this would be 'text/xml' instead.
     # Most OSes return the 'gzip' version, but some (el6) return 'x-gzip'. Either is fine.
     self.assertTrue(reply['Content-Type'] in ('application/gzip', 'application/x-gzip'))
Exemplo n.º 19
0
 def test_x_send(self, response, access):
     path = '/my/path'
     response.return_value = {}
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     response.assert_called_once_with()
     self.assertEqual(response.return_value['X-SENDFILE'], path)
     self.assertEqual(reply, response.return_value)
Exemplo n.º 20
0
 def test_x_send(self, response, access):
     path = '/my/path'
     response.return_value = {}
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     response.assert_called_once_with()
     self.assertEqual(response.return_value['X-SENDFILE'], path)
     self.assertEqual(reply, response.return_value)
Exemplo n.º 21
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')
Exemplo n.º 22
0
 def test_x_send_mime_type_noencoding(self, access):
     path = '/my/path.xml.gz'
     access.return_value = True
     reply = ContentView.x_send(path)
     access.assert_called_once_with(path, os.R_OK)
     self.assertEqual(reply['X-SENDFILE'], path)
     # If the normal mimetypes module was used, this would be 'text/xml' instead.
     # Most OSes return the 'gzip' version, but some (el6) return 'x-gzip'. Either is fine.
     self.assertTrue(reply['Content-Type'] in ('application/gzip',
                                               'application/x-gzip'))
Exemplo n.º 23
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)
Exemplo n.º 24
0
    def test_get_x_send(self, x_send, allow_access, exists, realpath):
        allow_access.return_value = True
        exists.return_value = True
        realpath.side_effect = lambda p: "/var/lib/pulp/published/content"

        host = "localhost"
        path = "/var/www/pub/content"

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        realpath.assert_called_with(path)
        x_send.assert_called_once_with("/var/lib/pulp/published/content")
        self.assertEqual(reply, x_send.return_value)
Exemplo n.º 25
0
    def test_init(self, key_load, pulp_conf):
        key_path = '/tmp/rsa.key'
        conf = {'authentication': {'rsa_key': key_path}}

        pulp_conf.get.side_effect = lambda s, p: conf.get(s).get(p)

        # test
        ContentView()

        # validation
        key_load.assert_called_once_with(key_path)
Exemplo n.º 26
0
    def test_get_x_send(self, x_send, allow_access, exists, realpath):
        allow_access.return_value = True
        exists.return_value = True
        realpath.side_effect = lambda p: '/var/lib/pulp/published/content'

        host = 'localhost'
        path = '/var/www/pub/content'

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        realpath.assert_called_with(path)
        x_send.assert_called_once_with('/var/lib/pulp/published/content')
        self.assertEqual(reply, x_send.return_value)
Exemplo n.º 27
0
    def test_get_x_send(self, x_send, allow_access, exists, realpath):
        allow_access.return_value = True
        exists.return_value = True
        realpath.side_effect = lambda p: p.upper()

        host = 'localhost'
        path = '/pulp/content'

        request = Mock(path_info=path)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        realpath.assert_called_once_with(path)
        exists.assert_called_once_with(path.upper())
        x_send.assert_called_once_with(path.upper())
        self.assertEqual(reply, x_send.return_value)
Exemplo n.º 28
0
    def test_get_x_send(self, x_send, allow_access, exists, realpath):
        allow_access.return_value = True
        exists.return_value = True
        realpath.side_effect = lambda p: p.upper()

        host = 'localhost'
        path = '/pulp/content'

        request = Mock(path_info=path)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        realpath.assert_called_once_with(path)
        exists.assert_called_once_with(path.upper())
        x_send.assert_called_once_with(path.upper())
        self.assertEqual(reply, x_send.return_value)
Exemplo n.º 29
0
    def test_get_redirected(self, redirect, allow_access, mock_conf_get, exists, realpath):
        allow_access.return_value = True
        exists.return_value = False
        realpath.side_effect = lambda p: "/var/lib/pulp/content/rpm"

        host = "localhost"
        path = "/var/www/pub/content"

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        realpath.assert_called_with(path)
        exists.assert_has_call("/var/lib/pulp/content/rpm")
        self.assertTrue(exists.call_count > 0)
        redirect.assert_called_once_with(request, view.key)
        self.assertEqual(reply, redirect.return_value)
Exemplo n.º 30
0
    def test_get_redirected(self, redirect, allow_access, mock_conf_get, exists, realpath):
        allow_access.return_value = True
        exists.return_value = False
        realpath.side_effect = lambda p: p.upper()

        host = 'localhost'
        path = '/pulp/content'

        request = Mock(path_info=path)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        realpath.assert_called_once_with(path)
        exists.assert_has_call(path.upper())
        self.assertTrue(exists.call_count > 0)
        redirect.assert_called_once_with(request, view.key)
        self.assertEqual(reply, redirect.return_value)
Exemplo n.º 31
0
    def test_get_not_found_no_link(self, not_found, pulp_conf):
        host = 'localhost'
        path = '/pulp/content'
        request = Mock(path_info=path)
        request.get_host.return_value = host
        conf = {
            'authentication': {
                'rsa_key': '/tmp/key'
            },
            'lazy': {
                'enabled': 'false',
            }
        }
        pulp_conf.get.side_effect = lambda s, p: conf.get(s).get(p)

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        not_found.assert_called_once_with(path)
        self.assertEqual(reply, not_found.return_value)
Exemplo n.º 32
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)
Exemplo n.º 33
0
    def test_get_redirected(self, redirect, allow_access, mock_conf_get,
                            exists, realpath):
        allow_access.return_value = True
        exists.return_value = False
        realpath.side_effect = lambda p: '/var/lib/pulp/content/rpm'

        host = 'localhost'
        path = '/var/www/pub/content'

        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host

        # test
        view = ContentView()
        reply = view.get(request)

        # validation
        allow_access.assert_called_once_with(request.environ, host)
        realpath.assert_called_with(path)
        exists.assert_has_call('/var/lib/pulp/content/rpm')
        self.assertTrue(exists.call_count > 0)
        redirect.assert_called_once_with(request, view.key)
        self.assertEqual(reply, redirect.return_value)
Exemplo n.º 34
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)
Exemplo n.º 35
0
    def test_get_not_found(self, pulp_conf):
        host = 'localhost'
        path = '/var/lib/pulp/published/content'
        request = Mock(path_info=path, environ=self.environ)
        request.get_host.return_value = host
        conf = {
            'authentication': {
                'rsa_key': '/tmp/key'
            },
            'server': {
                'storage_dir': '/var/lib/pulp'
            }
        }
        pulp_conf.get.side_effect = lambda s, p: conf.get(s).get(p)

        # test
        view = ContentView()
        self.assertRaises(content_views.Http404, view.get, request)
Exemplo n.º 36
0
from django.conf.urls import url

from pulp.server.content.web.views import ContentView

urlpatterns = [
    url(r'.+', ContentView.as_view(), name='content'),
]
Exemplo n.º 37
0
from django.conf.urls import patterns, url

from pulp.server.content.web.views import ContentView

# View Prefix
PREFIX = ''

# Patterns
urlpatterns = patterns(
    PREFIX,
    url(r'.+', ContentView.as_view(), name='content'),
)