Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/reports/tests/test_resolveReport.py

Issue 29584613: #4431 - Introduce sitescripts.reports.web.resolveReport handler (Closed)
Patch Set: Address comments on PS1 Created Oct. 24, 2017, 3:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/reports/README.md ('k') | sitescripts/reports/web/resolveReport.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2017-present eyeo GmbH
3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation.
7 #
8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15
16 import base64
17 import ConfigParser
18
19 import pytest
20
21 from sitescripts.reports.web.resolveReport import (
22 resolve_report,
23 CONF_SECTION,
24 CONF_KEY_KEY,
25 CONF_URL_KEY,
26 )
27
28 ENCRYPTION_KEY = '12345678901234567890123456789012'
29 URL_TEMPLATE = 'https://example.com/{report_id}'
30
31 PLAINTEXT_GUID = '12345678-1234-1234-1234-123456789abc'
32 ENCRYPTED_GUID = ('MTIzNDU2Nzg5YWJj,9RuQq5zPNVw2fnjk7zT/jfS+YkDRjWFrly'
33 'YIRRrhdeiuy86yaBq0eqA7iTLwIfjzs1yefw==')
34
35 BAD_GUIDS = [
36 '', # Nothing.
37 'foobar', # No comma.
38 # Wrong base64 encoding.
39 'TIzNDU2Nzg5YWJj,9RuQq5zPNVw2fnjk7zT/jfS+YkDRjWFrly'
40 'YIRRrhdeiuy86yaBq0eqA7iTLwIfjzs1yefw==',
41 # Wrong nonce.
42 'MNIzNDU2Nzg5YWJj,9RuQq5zPNVw2fnjk7zT/jfS+YkDRjWFrly'
43 'YIRRrhdeiuy86yaBq0eqA7iTLwIfjzs1yefw==',
44 ]
45
46
47 @pytest.fixture()
48 def reports_config(mocker):
49 """Mock config to override encryption key and redirect URL."""
50 mock_config = ConfigParser.ConfigParser()
51 mock_config.add_section(CONF_SECTION)
52 mock_config.set(CONF_SECTION, CONF_KEY_KEY,
53 base64.b64encode(ENCRYPTION_KEY))
54 mock_config.set(CONF_SECTION, CONF_URL_KEY, URL_TEMPLATE)
55 mocker.patch('sitescripts.reports.web.resolveReport.get_config',
56 lambda: mock_config)
57
58
59 def test_success(reports_config, mocker):
60 start_response_mock = mocker.Mock()
61 result = resolve_report({'QUERY_STRING': ENCRYPTED_GUID},
62 start_response_mock)
63 assert result == ['Found']
64 start_response_mock.assert_called_once_with(
65 '302 Found',
66 [('Location', URL_TEMPLATE.format(report_id=PLAINTEXT_GUID))],
67 )
68
69
70 @pytest.mark.parametrize('guid', BAD_GUIDS)
71 def test_bad_wrong_guid(reports_config, mocker, guid):
72 start_response_mock = mocker.Mock()
73 result = resolve_report({'QUERY_STRING': guid},
74 start_response_mock)
75 assert result == ['Not Found']
76 start_response_mock.assert_called_once_with('404 Not Found', [])
OLDNEW
« no previous file with comments | « sitescripts/reports/README.md ('k') | sitescripts/reports/web/resolveReport.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld