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" version: "2.3"
services: services:
web: worker:
depends_on: depends_on:
- customs - customs
- wat - wat
@ -9,7 +9,21 @@ services:
customs: customs:
build: build:
context: ./private/addons-customs-scanner context: ./private/addons-customs-scanner
environment:
- ALLOWED_ORIGIN=http://olympia.test
- PORT=10101
links:
- "nginx:olympia.test"
depends_on:
- web
wat: wat:
build: build:
context: ./private/addons-wat 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: try:
if not os.path.exists(upload.path): if not os.path.exists(upload.path):
raise ValueError('Path "{}" is not a file or directory or does ' raise ValueError('File "{}" does not exist.' .format(upload.path))
'not exist.' .format(upload.path))
result = ScannersResult() result = ScannersResult()
result.upload = upload result.upload = upload
result.scanner = scanner result.scanner = scanner
with statsd.timer('devhub.{}'.format(scanner_name)): with statsd.timer('devhub.{}'.format(scanner_name)):
headers = {'Authorization': 'Bearer {}'.format(api_key)} json_payload = {
with open(upload.path, 'rb') as xpi: 'api_key': api_key,
response = requests.post(url=api_url, 'download_url': upload.get_authenticated_download_url(),
files={'xpi': xpi}, }
headers=headers, response = requests.post(url=api_url,
timeout=settings.SCANNER_TIMEOUT) 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)
results = response.json()
if 'error' in results: if 'error' in results:
raise ValueError(results) raise ValueError(results)

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

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