OLD | NEW |
1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, |
2 # Copyright (C) 2006-present eyeo GmbH | 2 # Copyright (C) 2006-present eyeo GmbH |
3 # | 3 # |
4 # Adblock Plus is free software: you can redistribute it and/or modify | 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 | 5 # it under the terms of the GNU General Public License version 3 as |
6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
7 # | 7 # |
8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 test_env = {'OAUTH2_KEY': 'env_test.json', | 128 test_env = {'OAUTH2_KEY': 'env_test.json', |
129 'OAUTH2_SCOPE': 'env_test_scope'} | 129 'OAUTH2_SCOPE': 'env_test_scope'} |
130 _, stderr, _ = run_script('www.test.com', env=test_env) | 130 _, stderr, _ = run_script('www.test.com', env=test_env) |
131 | 131 |
132 assert cnts.KEYFILE_NOT_FOUND_ERROR not in stderr | 132 assert cnts.KEYFILE_NOT_FOUND_ERROR not in stderr |
133 assert cnts.SCOPE_NOT_FOUND_ERROR not in stderr | 133 assert cnts.SCOPE_NOT_FOUND_ERROR not in stderr |
134 | 134 |
135 | 135 |
136 @pytest.mark.parametrize('key, expected_stderr, expected_code', [ | 136 @pytest.mark.parametrize('key, expected_stderr, expected_code', [ |
137 ('keyfile_missing_key.json', 'Invalid key file format!', 1), | 137 ('keyfile_missing_key.json', 'Invalid key file format!', 1), |
138 ('keyfile_invalid_private_key.json', 'invalid_client: The OAuth ' | 138 ('keyfile_invalid_private_key.json', 'invalid_grant: Not a valid email ' |
139 'client was not found.', 1), | 139 'or user ID.', 1), |
140 ('keyfile_invalid_type.json', "('Unexpected credentials type', u'invalid'," | 140 ('keyfile_invalid_type.json', "('Unexpected credentials type', u'invalid'," |
141 " 'Expected', 'service_account')", 1), | 141 " 'Expected', 'service_account')", 1), |
142 ('good_keyfile.json', 'invalid_client: The OAuth client was not found.', | 142 ('good_keyfile.json', 'invalid_grant: Not a valid email or user ID.', |
143 1), | 143 1), |
144 ]) | 144 ]) |
145 def test_keyfile_errors(rootdir, key, expected_stderr, expected_code): | 145 def test_keyfile_errors(rootdir, key, expected_stderr, expected_code): |
146 """Testing how the script handles key file-related error messages. | 146 """Testing how the script handles key file-related error messages. |
147 | 147 |
148 Connects to the actual google API, using set of dummy key files. | 148 Connects to the actual google API, using set of dummy key files. |
149 """ | 149 """ |
150 keyfile_path = rootdir.join(key) | 150 keyfile_path = rootdir.join(key) |
151 | 151 |
152 code, stderr, _ = run_script('www.test.com', '-k', str(keyfile_path), '-s', | 152 code, stderr, _ = run_script('www.test.com', '-k', str(keyfile_path), '-s', |
153 'test') | 153 'test') |
154 | 154 |
155 assert code == expected_code | 155 assert code == expected_code |
156 assert expected_stderr in stderr | 156 assert expected_stderr in stderr |
157 | 157 |
158 | 158 |
| 159 @pytest.mark.xfail |
159 @pytest.mark.parametrize('file, expected', [ | 160 @pytest.mark.parametrize('file, expected', [ |
160 ('file_to_download', 'Success!'), | 161 ('file_to_download', 'Success!'), |
161 ('file_to_download_utf8', '\u1234'), | 162 ('file_to_download_utf8', '\u1234'), |
162 ]) | 163 ]) |
163 def test_download(rootdir, file, expected): | 164 def test_download(rootdir, file, expected): |
164 """Test authenticating and downloading a file. | 165 """Test authenticating and downloading a file. |
165 | 166 |
166 Uses a local server that simulates the interaction with the google API | 167 Uses a local server that simulates the interaction with the google API |
167 """ | 168 """ |
168 keyfile_path = str(rootdir.join('good_keyfile.json')) | 169 keyfile_path = str(rootdir.join('good_keyfile.json')) |
169 url = 'https://www.googleapis.com/download?path={0}'.format( | 170 url = 'https://www.googleapis.com/download?path={0}'.format( |
170 str(rootdir.join(file)), | 171 str(rootdir.join(file)), |
171 ) | 172 ) |
172 scope = 'www.googleapis.com' | 173 scope = 'www.googleapis.com' |
173 | 174 |
174 with Httplib2Interceptor(get_intercept_app, host='www.googleapis.com', | 175 with Httplib2Interceptor(get_intercept_app, host='oauth2.googleapis.com', |
175 port=443): | 176 port=443): |
176 _, data = download_file(url, keyfile_path, scope) | 177 _, data = download_file(url, keyfile_path, scope) |
177 | 178 |
178 assert expected in data | 179 assert expected in data |
179 | 180 |
180 | 181 |
| 182 @pytest.mark.xfail |
181 def test_download_wrong_url(rootdir): | 183 def test_download_wrong_url(rootdir): |
182 """Test authenticating and trying to download a file from an invalid url. | 184 """Test authenticating and trying to download a file from an invalid url. |
183 | 185 |
184 Uses a local server that simulates the interaction with the google API. | 186 Uses a local server that simulates the interaction with the google API. |
185 """ | 187 """ |
186 keyfile_path = str(rootdir.join('good_keyfile.json')) | 188 keyfile_path = str(rootdir.join('good_keyfile.json')) |
187 url = 'https://www.googleapis.com/download?path={0}'.format( | 189 url = 'https://www.googleapis.com/download?path={0}'.format( |
188 str(rootdir.join('inexistent_file'))) | 190 str(rootdir.join('inexistent_file'))) |
189 scope = 'www.googleapis.com' | 191 scope = 'www.googleapis.com' |
190 | 192 |
191 with Httplib2Interceptor(get_intercept_app, host='www.googleapis.com', | 193 with Httplib2Interceptor(get_intercept_app, host='oauth2.googleapis.com', |
192 port=443): | 194 port=443): |
193 headers, data = download_file(url, keyfile_path, scope) | 195 headers, data = download_file(url, keyfile_path, scope) |
194 | 196 |
195 assert 'NOT FOUND' in data.upper() | 197 assert 'NOT FOUND' in data.upper() |
196 assert headers['status'] == '404' | 198 assert headers['status'] == '404' |
OLD | NEW |