Esempio n. 1
0
    def test_build_sendfile_response_remove_extra_path_separators(self):

        with patch('wirecloud.commons.utils.http.os.path.isfile', return_value=True) as isfile_mock:
            response = build_sendfile_response('js///file.js', '/folder')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response['X-Sendfile'], '/folder/js/file.js')
            isfile_mock.assert_called_once_with('/folder/js/file.js')
Esempio n. 2
0
    def test_build_sendfile_response(self):

        with patch('wirecloud.commons.utils.http.os.path.isfile',
                   return_value=True):
            response = build_sendfile_response('file.js', '/folder')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response['X-Sendfile'], '/folder/file.js')
Esempio n. 3
0
    def test_build_sendfile_response_remove_extra_path_separators(self):

        with patch('wirecloud.commons.utils.http.os.path.isfile', return_value=True) as isfile_mock:
            response = build_sendfile_response('js///file.js', '/folder')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response['X-Sendfile'], '/folder/js/file.js')
            isfile_mock.assert_called_once_with('/folder/js/file.js')
Esempio n. 4
0
def serve_catalogue_media(request, vendor, name, version, file_path):

    base_dir = catalogue_utils.wgt_deployer.get_base_dir(vendor, name, version)

    if not getattr(settings, 'USE_XSENDFILE', False):
        response = serve(request, file_path, document_root=base_dir)
    else:
        response = build_sendfile_response(file_path, base_dir)

    if response.status_code == 302:
        response['Location'] = reverse('wirecloud_catalogue.media', kwargs= {"vendor": vendor, "name": name, "version": version, "file_path": response['Location']})

    return response
Esempio n. 5
0
def serve_showcase_media(request, vendor, name, version, file_path):

    resource = get_object_or_404(CatalogueResource, vendor=vendor, short_name=name, version=version)
    if resource.resource_type() not in ['widget', 'operator']:
        raise Http404()

    # For now, all widgets are freely accessible/distributable
    #if not resource.is_available_for(request.user):
    #    return build_error_response(request, 403, "Forbidden")

    base_dir = showcase_utils.wgt_deployer.get_base_dir(vendor, name, version)

    if not getattr(settings, 'USE_XSENDFILE', False):
        response = serve(request, file_path, document_root=base_dir)
    else:
        response = build_sendfile_response(file_path, base_dir)

    if response.status_code == 302:
        response['Location'] = reverse('wirecloud_catalogue.media', kwargs= {"vendor": vendor, "name": name, "version": version, "file_path": response['Location']})

    return response
Esempio n. 6
0
    def test_build_sendfile_response_redirect_on_invalid_path(self):

        response = build_sendfile_response('../a/../file.js', '/folder')
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['Location'], 'file.js')
Esempio n. 7
0
    def test_build_sendfile_response(self):

        with patch('wirecloud.commons.utils.http.os.path.isfile', return_value=True):
            response = build_sendfile_response('file.js', '/folder')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response['X-Sendfile'], '/folder/file.js')
Esempio n. 8
0
    def test_build_sendfile_response_redirect_on_invalid_path(self):

        response = build_sendfile_response('../a/../file.js', '/folder')
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['Location'], 'file.js')