Send download_url to the scanners (#12317)

This commit is contained in:
William Durand 2019-09-17 16:02:37 +02:00 коммит произвёл GitHub
Родитель 27d050f154
Коммит c9ba46c272
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 33 добавлений и 12 удалений

Просмотреть файл

@ -1,7 +1,7 @@
version: "2.3"
services:
web:
worker:
depends_on:
- customs
- wat
@ -9,7 +9,21 @@ services:
customs:
build:
context: ./private/addons-customs-scanner
environment:
- ALLOWED_ORIGIN=http://olympia.test
- PORT=10101
links:
- "nginx:olympia.test"
depends_on:
- web
wat:
build:
context: ./private/addons-wat
environment:
- ALLOWED_ORIGIN=http://olympia.test
- PORT=10102
links:
- "nginx:olympia.test"
depends_on:
- web

Просмотреть файл

@ -33,22 +33,27 @@ def run_scanner(upload_pk, scanner, api_url, api_key):
try:
if not os.path.exists(upload.path):
raise ValueError('Path "{}" is not a file or directory or does '
'not exist.' .format(upload.path))
raise ValueError('File "{}" does not exist.' .format(upload.path))
result = ScannersResult()
result.upload = upload
result.scanner = scanner
with statsd.timer('devhub.{}'.format(scanner_name)):
headers = {'Authorization': 'Bearer {}'.format(api_key)}
with open(upload.path, 'rb') as xpi:
json_payload = {
'api_key': api_key,
'download_url': upload.get_authenticated_download_url(),
}
response = requests.post(url=api_url,
files={'xpi': xpi},
headers=headers,
json=json_payload,
timeout=settings.SCANNER_TIMEOUT)
try:
results = response.json()
except ValueError:
# Log the response body when JSON decoding has failed.
raise ValueError(response.text)
if 'error' in results:
raise ValueError(results)

Просмотреть файл

@ -52,8 +52,10 @@ class TestRunScanner(UploadTest, TestCase):
assert requests_mock.called
requests_mock.assert_called_with(
url=self.API_URL,
files={'xpi': mock.ANY},
headers={'Authorization': 'Bearer {}'.format(self.API_KEY)},
json={
'api_key': self.API_KEY,
'download_url': upload.get_authenticated_download_url(),
},
timeout=123
)
result = ScannersResult.objects.all()[0]