Exemplo n.º 1
0
    def test_it_sets_custom_content_security_policy_header(self, pyramid_request):
        client.sidebar_app(pyramid_request)
        csp_header = pyramid_request.response.headers["Content-Security-Policy"]

        assert (
            csp_header
            == "script-src 'self' http://example.com https://www.google-analytics.com; style-src http://example.com 'unsafe-inline'"
        )
Exemplo n.º 2
0
    def test_it_sets_custom_content_security_policy_header(
            self, pyramid_request):
        client.sidebar_app(pyramid_request)
        csp_header = pyramid_request.response.headers[
            "Content-Security-Policy"]

        assert (
            csp_header ==
            "script-src 'self' https://cdn.hypothes.is https://www.google-analytics.com; style-src https://cdn.hypothes.is"
        )
Exemplo n.º 3
0
    def test_uses_client_boot_script_when_enabled(self, pyramid_request):
        pyramid_request.feature.flags['use_client_boot_script'] = True

        ctx = client.sidebar_app(pyramid_request)

        assert ctx['app_js_urls'] == ['/embed.js']
        assert ctx['app_css_urls'] == []
Exemplo n.º 4
0
Arquivo: main.py Projeto: hypothesis/h
def annotation_page(context, request):
    annotation = context.annotation
    document = annotation.document
    if document and document.title:
        title = "Annotation by {user} on {title}".format(
            user=annotation.userid.replace("acct:", ""), title=document.title
        )
    else:
        title = "Annotation by {user}".format(
            user=annotation.userid.replace("acct:", "")
        )

    alternate = request.route_url("api.annotation", id=annotation.id)

    return sidebar_app(
        request,
        {
            "meta_attrs": (
                {"property": "og:title", "content": title},
                {"property": "og:description", "content": ""},
                {"property": "og:image", "content": "/assets/images/logo.png"},
                {"property": "og:site_name", "content": "Hypothes.is"},
                {"property": "og:url", "content": request.url},
            ),
            "link_attrs": (
                {"rel": "alternate", "href": alternate, "type": "application/json"},
            ),
        },
    )
Exemplo n.º 5
0
def stream(_context, request):
    q = request.params.get("q", "").split(":", 1)
    if len(q) >= 2 and q[0] == "tag":
        tag = q[1]
        if " " in tag:
            tag = '"' + tag + '"'
        query = {"q": "tag:{}".format(tag)}
        location = request.route_url("activity.search", _query=query)
        raise httpexceptions.HTTPFound(location=location)
    atom = request.route_url("stream_atom")
    rss = request.route_url("stream_rss")
    return sidebar_app(
        request,
        {
            "link_tags": [
                {
                    "rel": "alternate",
                    "href": atom,
                    "type": "application/atom+xml"
                },
                {
                    "rel": "alternate",
                    "href": rss,
                    "type": "application/rss+xml"
                },
            ]
        },
    )
Exemplo n.º 6
0
Arquivo: main.py Projeto: rsarxiv/h
def stream(context, request):
    q = request.params.get('q', '').split(':', 1)
    if len(q) >= 2 and q[0] == 'tag':
        tag = q[1]
        if ' ' in tag:
            tag = '"' + tag + '"'
        query = {'q': 'tag:{}'.format(tag)}
        location = request.route_url('activity.search', _query=query)
        raise httpexceptions.HTTPFound(location=location)
    atom = request.route_url('stream_atom')
    rss = request.route_url('stream_rss')
    return sidebar_app(
        request, {
            'link_tags': [
                {
                    'rel': 'alternate',
                    'href': atom,
                    'type': 'application/atom+xml'
                },
                {
                    'rel': 'alternate',
                    'href': rss,
                    'type': 'application/rss+xml'
                },
            ]
        })
Exemplo n.º 7
0
def annotation_page(context, request):
    annotation = context.annotation
    document = annotation.document
    if document and document.title:
        title = 'Annotation by {user} on {title}'.format(
            user=annotation.userid.replace('acct:', ''),
            title=document.title)
    else:
        title = 'Annotation by {user}'.format(
            user=annotation.userid.replace('acct:', ''))

    alternate = request.route_url('api.annotation', id=annotation.id)

    return sidebar_app(request, {
        'meta_attrs': (
            {'property': 'og:title', 'content': title},
            {'property': 'og:description', 'content': ''},
            {'property': 'og:image', 'content': '/assets/images/logo.png'},
            {'property': 'og:site_name', 'content': 'Hypothes.is'},
            {'property': 'og:url', 'content': request.url},
        ),
        'link_attrs': (
            {'rel': 'alternate', 'href': alternate,
                'type': 'application/json'},
        ),
    })
Exemplo n.º 8
0
def annotation_page(context, request):
    annotation = context.annotation
    document = annotation.document
    if document and document.title:
        title = "Annotation by {user} on {title}".format(
            user=annotation.userid.replace("acct:", ""), title=document.title
        )
    else:
        title = "Annotation by {user}".format(
            user=annotation.userid.replace("acct:", "")
        )

    alternate = request.route_url("api.annotation", id=annotation.id)

    return sidebar_app(
        request,
        {
            "meta_attrs": (
                {"property": "og:title", "content": title},
                {"property": "og:description", "content": ""},
                {"property": "og:image", "content": "/assets/images/logo.png"},
                {"property": "og:site_name", "content": "Hypothes.is"},
                {"property": "og:url", "content": request.url},
            ),
            "link_attrs": (
                {"rel": "alternate", "href": alternate, "type": "application/json"},
            ),
        },
    )
Exemplo n.º 9
0
    def test_it_sets_asset_urls(self, pyramid_request):
        pyramid_request.feature.flags['use_client_boot_script'] = False

        ctx = client.sidebar_app(pyramid_request)

        assert ctx['app_css_urls'] == ['/assets/client/app.css']
        assert ctx['app_js_urls'] == ['/assets/client/app.js']
Exemplo n.º 10
0
    def test_it_disables_oauth(self, pyramid_request):
        pyramid_request.feature.flags['client_oauth'] = False

        ctx = client.sidebar_app(pyramid_request)
        cfg = json.loads(ctx['app_config'])

        assert cfg['oauthEnabled'] is False
Exemplo n.º 11
0
    def test_it_includes_client_config(self, pyramid_request):
        ctx = client.sidebar_app(pyramid_request)
        expected_config = {
            "apiUrl": "http://example.com/api",
            "websocketUrl": "wss://example.com/ws",
            "sentry": {"dsn": "test-sentry-dsn", "environment": "dev"},
            "authDomain": "example.com",
            "googleAnalytics": "UA-4567",
            "oauthClientId": "test-client-id",
            "rpcAllowedOrigins": "https://lti.hypothes.is",
        }

        actual_config = json.loads(ctx["app_config"])

        assert actual_config == expected_config
Exemplo n.º 12
0
    def test_it_includes_client_config(self, pyramid_request):
        ctx = client.sidebar_app(pyramid_request)
        expected_config = {
            "apiUrl": "http://example.com/api",
            "websocketUrl": "wss://example.com/ws",
            "release": __version__,
            "raven": {"dsn": "test-sentry-dsn", "release": __version__},
            "authDomain": "example.com",
            "googleAnalytics": "UA-4567",
            "oauthClientId": "test-client-id",
            "rpcAllowedOrigins": "https://lti.hypothes.is",
        }

        actual_config = json.loads(ctx["app_config"])

        assert actual_config == expected_config
Exemplo n.º 13
0
def stream(context, request):
    q = request.params.get('q', '').split(':', 1)
    if len(q) >= 2 and q[0] == 'tag':
        tag = q[1]
        if ' ' in tag:
            tag = '"' + tag + '"'
        query = {'q': 'tag:{}'.format(tag)}
        location = request.route_url('activity.search', _query=query)
        raise httpexceptions.HTTPFound(location=location)
    atom = request.route_url('stream_atom')
    rss = request.route_url('stream_rss')
    return sidebar_app(request, {
        'link_tags': [
            {'rel': 'alternate', 'href': atom, 'type': 'application/atom+xml'},
            {'rel': 'alternate', 'href': rss, 'type': 'application/rss+xml'},
        ]
    })
Exemplo n.º 14
0
    def test_it_includes_client_config(self, pyramid_request):
        ctx = client.sidebar_app(pyramid_request)
        expected_config = {
            'apiUrl': 'http://example.com/api',
            'websocketUrl': 'wss://example.com/ws',
            'serviceUrl': 'http://example.com/',
            'release': __version__,
            'raven': {
                'dsn': 'test-sentry-dsn',
                'release': __version__
            },
            'authDomain': 'example.com',
            'googleAnalytics': 'UA-4567'
        }

        actual_config = json.loads(ctx['app_config'])

        assert actual_config == expected_config
Exemplo n.º 15
0
    def test_it_includes_client_config(self, pyramid_request):
        ctx = client.sidebar_app(pyramid_request)
        expected_config = {
                'apiUrl': 'http://example.com/api',
                'websocketUrl': 'wss://example.com/ws',
                'serviceUrl': 'http://example.com/',
                'release': __version__,
                'raven': {
                    'dsn': 'test-sentry-dsn',
                    'release': __version__
                },
                'authDomain': 'example.com',
                'googleAnalytics': 'UA-4567'
                }

        actual_config = json.loads(ctx['app_config'])

        assert actual_config == expected_config
Exemplo n.º 16
0
Arquivo: main.py Projeto: rsarxiv/h
def annotation_page(context, request):
    annotation = context.annotation
    document = annotation.document
    if document and document.title:
        title = 'Annotation by {user} on {title}'.format(
            user=annotation.userid.replace('acct:', ''), title=document.title)
    else:
        title = 'Annotation by {user}'.format(
            user=annotation.userid.replace('acct:', ''))

    alternate = request.route_url('api.annotation', id=annotation.id)

    return sidebar_app(
        request, {
            'meta_attrs': (
                {
                    'property': 'og:title',
                    'content': title
                },
                {
                    'property': 'og:description',
                    'content': ''
                },
                {
                    'property': 'og:image',
                    'content': '/assets/images/logo.png'
                },
                {
                    'property': 'og:site_name',
                    'content': 'Hypothes.is'
                },
                {
                    'property': 'og:url',
                    'content': request.url
                },
            ),
            'link_attrs': ({
                'rel': 'alternate',
                'href': alternate,
                'type': 'application/json'
            }, ),
        })
Exemplo n.º 17
0
Arquivo: main.py Projeto: hypothesis/h
def stream(context, request):
    q = request.params.get("q", "").split(":", 1)
    if len(q) >= 2 and q[0] == "tag":
        tag = q[1]
        if " " in tag:
            tag = '"' + tag + '"'
        query = {"q": "tag:{}".format(tag)}
        location = request.route_url("activity.search", _query=query)
        raise httpexceptions.HTTPFound(location=location)
    atom = request.route_url("stream_atom")
    rss = request.route_url("stream_rss")
    return sidebar_app(
        request,
        {
            "link_tags": [
                {"rel": "alternate", "href": atom, "type": "application/atom+xml"},
                {"rel": "alternate", "href": rss, "type": "application/rss+xml"},
            ]
        },
    )
Exemplo n.º 18
0
    def test_it_includes_client_config(self, pyramid_request):
        ctx = client.sidebar_app(pyramid_request)
        expected_config = {
                'apiUrl': 'http://example.com/api',
                'websocketUrl': 'wss://example.com/ws',
                'serviceUrl': 'http://example.com/',
                'release': __version__,
                'raven': {
                    'dsn': 'test-sentry-dsn',
                    'release': __version__
                },
                'authDomain': 'example.com',
                'googleAnalytics': 'UA-4567',
                'oauthClientId': 'test-client-id',
                'oauthEnabled': True,
                'rpcAllowedOrigins': 'https://lti.hypothes.is',
                }

        actual_config = json.loads(ctx['app_config'])

        assert actual_config == expected_config
Exemplo n.º 19
0
    def test_it_sets_embed_url(self, pyramid_request):
        ctx = client.sidebar_app(pyramid_request)

        assert ctx["embed_url"] == "/embed.js"
Exemplo n.º 20
0
    def test_it_sets_client_url(self, pyramid_request):
        ctx = client.sidebar_app(pyramid_request)

        assert ctx["client_url"] == "http://example.com/client_url"
Exemplo n.º 21
0
    def test_it_sets_embed_url(self, pyramid_request):
        ctx = client.sidebar_app(pyramid_request)

        assert ctx['embed_url'] == '/embed.js'