update the ado logic to consume the list of existing items once (#3014)

* update the ado logic to consume the list of existing items once

* format

* Update src/ApiService/ApiService/onefuzzlib/notifications/Ado.cs

Co-authored-by: Teo Voinea <58236992+tevoinea@users.noreply.github.com>

* Adding a notification testing endpoint

* fix tests

* format

* regen docs

* update logic

* format

* fix dummy name

* mypy fix

* make mypy happy

* bandit fix

* renaming

* address PR Comment

---------

Co-authored-by: Teo Voinea <58236992+tevoinea@users.noreply.github.com>
This commit is contained in:
Cheick Keita
2023-04-19 14:27:16 -07:00
committed by GitHub
parent 6f06b8ffd4
commit aa28550aad
17 changed files with 244 additions and 103 deletions

View File

@ -8,6 +8,7 @@ import logging
import os
import tempfile
import time
import uuid
from datetime import datetime
from typing import Any, Dict, List, Optional, Set, Tuple, Union
from urllib.parse import urlparse
@ -18,13 +19,13 @@ from azure.applicationinsights import ApplicationInsightsDataClient
from azure.applicationinsights.models import QueryBody
from azure.identity import AzureCliCredential
from azure.storage.blob import ContainerClient
from onefuzztypes import models, requests
from onefuzztypes import models, requests, responses
from onefuzztypes.enums import ContainerType, TaskType
from onefuzztypes.models import BlobRef, Job, NodeAssignment, Report, Task, TaskConfig
from onefuzztypes.primitives import Container, Directory, PoolName
from onefuzztypes.responses import TemplateValidationResponse
from onefuzz.api import UUID_EXPANSION, Command, Onefuzz
from onefuzz.api import UUID_EXPANSION, Command, Endpoint, Onefuzz
from .azure_identity_credential_adapter import AzureIdentityCredentialAdapter
from .backend import wait
@ -775,6 +776,7 @@ class DebugNotification(Command):
"""Inject a report into the specified crash reporting task"""
task = self.onefuzz.tasks.get(task_id)
crashes = self._get_container(task, ContainerType.crashes)
reports = self._get_container(task, report_container_type)
@ -792,26 +794,15 @@ class DebugNotification(Command):
handle.write("")
self.onefuzz.containers.files.upload_file(crashes, file_path, crash_name)
report = Report(
input_blob=BlobRef(
account=self._get_storage_account(crashes),
container=crashes,
name=crash_name,
),
executable=task.config.task.target_exe,
crash_type="fake crash report",
crash_site="fake crash site",
call_stack=["#0 fake", "#1 call", "#2 stack"],
call_stack_sha256=ZERO_SHA256,
input_sha256=EMPTY_SHA256,
asan_log="fake asan log",
task_id=task_id,
job_id=task.job_id,
minimized_stack=[],
minimized_stack_function_names=[],
tool_name="libfuzzer",
tool_version="1.2.3",
onefuzz_version="1.2.3",
input_blob_ref = BlobRef(
account=self._get_storage_account(crashes),
container=crashes,
name=crash_name,
)
target_exe = task.config.task.target_exe if task.config.task.target_exe else ""
report = self._create_report(
task.job_id, task.task_id, target_exe, input_blob_ref
)
with tempfile.TemporaryDirectory() as tempdir:
@ -823,6 +814,58 @@ class DebugNotification(Command):
reports, file_path, crash_name + ".json"
)
def test_template(
self, task_id: UUID_EXPANSION, notificationConfig: models.NotificationConfig
) -> responses.NotificationTestResponse:
"""Test a notification template"""
endpoint = Endpoint(self.onefuzz)
task = self.onefuzz.tasks.get(task_id)
input_blob_ref = BlobRef(
account="dummy-storage-account",
container="test-notification-crashes",
name="fake-crash-sample",
)
report = self._create_report(
task.job_id, task.task_id, "fake_target.exe", input_blob_ref
)
report.report_url = "https://dummy-container.blob.core.windows.net/dummy-reports/dummy-report.json"
return endpoint._req_model(
"POST",
responses.NotificationTestResponse,
data=requests.NotificationTest(
report=report,
notification=models.Notification(
container=Container("test-notification-reports"),
notification_id=uuid.uuid4(),
config=notificationConfig.config,
),
),
alternate_endpoint="notifications/test",
)
def _create_report(
self, job_id: UUID, task_id: UUID, target_exe: str, input_blob_ref: BlobRef
) -> Report:
return Report(
input_blob=input_blob_ref,
executable=target_exe,
crash_type="fake crash report",
crash_site="fake crash site",
call_stack=["#0 fake", "#1 call", "#2 stack"],
call_stack_sha256=ZERO_SHA256,
input_sha256=EMPTY_SHA256,
asan_log="fake asan log",
task_id=task_id,
job_id=job_id,
minimized_stack=[],
minimized_stack_function_names=[],
tool_name="libfuzzer",
tool_version="1.2.3",
onefuzz_version="1.2.3",
)
class Debug(Command):
"""Debug running jobs"""