Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
h_vialib
uwsgi
pywb
jinja2
whitenoise
newrelic
h-checkmatelib
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ fakeredis==0.16.0 # via pywb
future==0.18.2 # via h-checkmatelib
gevent==1.4.0 # via pywb
greenlet==0.4.16 # via gevent
h-checkmatelib==1.0.2 # via -r requirements.in
h-checkmatelib==1.0.3 # via -r requirements.in
h-vialib==1.0.0 # via -r requirements.in
idna==2.10 # via requests, tldextract
importlib-metadata==2.0.0 # via jsonschema
jinja2==2.11.2 # via -r requirements.in, pywb
jinja2==2.11.2 # via pywb
jsonschema==3.2.0 # via h-checkmatelib
markupsafe==1.1.1 # via jinja2
newrelic==5.22.1.152 # via -r requirements.in
Expand Down
146 changes: 0 additions & 146 deletions static/static/css/wrapper-style.css

This file was deleted.

1 change: 0 additions & 1 deletion static/static/img/warning.svg

This file was deleted.

19 changes: 5 additions & 14 deletions tests/unit/viahtml/views/blocklist_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest
from checkmatelib.exceptions import CheckmateException
from h_matchers import Any

from viahtml.views.blocklist import BlocklistView

Expand Down Expand Up @@ -48,25 +47,17 @@ def test_if_a_call_to_checkmate_fails_it_does_nothing(self, view, start_response

assert result is None

@pytest.mark.parametrize(
"block_reason,expected_heading",
(
("malicious", "Deceptive site ahead"),
("publisher-blocked", "Content not available"),
("anything-else-at-all", "Content cannot be annotated"),
),
)
def test_blocking(self, view, block_reason, start_response, expected_heading):
view.checkmate.check_url.return_value.reason_codes = [block_reason]
def test_blocking(self, view, start_response):
blocked_response = view.checkmate.check_url.return_value
blocked_response.reason_codes = ["some_reason"]

result = view("/proxy/http://example.com", {}, start_response)

start_response.assert_called_once_with(
"403 Forbidden", [("Content-Type", "text/html; charset=utf-8")]
"307 Temporary Redirect", [("Location", blocked_response.presentation_url)]
)

assert result == Any.list.of_size(1)
assert expected_heading in result[0].decode("utf-8")
assert result == []

@pytest.fixture
def start_response(self):
Expand Down
90 changes: 0 additions & 90 deletions viahtml/templates/viahtml/blocked_page.html.jinja2

This file was deleted.

26 changes: 0 additions & 26 deletions viahtml/templates/viahtml/wrapper.html.jinja2

This file was deleted.

24 changes: 7 additions & 17 deletions viahtml/views/blocklist.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
"""The blocklist view."""

import os
import re
from logging import getLogger

from checkmatelib import CheckmateClient, CheckmateException
from jinja2 import Environment, FileSystemLoader, select_autoescape
from pkg_resources import resource_filename

LOG = getLogger(__name__)

Expand All @@ -16,13 +13,6 @@ class BlocklistView:

PROXY_PATTERN = re.compile(r"^/proxy/(?:[a-z]{2}_/)?(.*)$")

JINJA_ENV = Environment(
loader=FileSystemLoader(
os.path.abspath(resource_filename("viahtml", "templates"))
),
autoescape=select_autoescape(["html", "xml"]),
)

def __init__(self, checkmate_host):
self.checkmate = CheckmateClient(checkmate_host)

Expand All @@ -49,16 +39,16 @@ def __call__(self, path, environ, start_response):
return None

try:
hits = self.checkmate.check_url(url, allow_all=True)
blocked = self.checkmate.check_url(url, allow_all=True)
except CheckmateException as err:
LOG.warning("Failed to check URL against Checkmate: %s", err)
return None

if not hits:
if not blocked:
return None

start_response("403 Forbidden", [("Content-Type", "text/html; charset=utf-8")])

template = self.JINJA_ENV.get_template("viahtml/blocked_page.html.jinja2")
content = template.render(reason=hits.reason_codes[0], url_to_annotate=url)
return [content.encode("utf-8")]
# Redirect the user to the presentation URL given to us by Checkmate
start_response(
"307 Temporary Redirect", [("Location", blocked.presentation_url)]
)
return []