standardize on unix file endings (#516)

The majority of our source files have `\n` line endings.  This updates the few files that use `\r\n` to use `\n`.
This commit is contained in:
bmc-msft
2021-02-06 09:14:26 -05:00
committed by GitHub
parent be23e19cd6
commit fd995718c8
7 changed files with 318 additions and 318 deletions

View File

@ -1,11 +1,11 @@
# What is this for? # What is this for?
This section of code contains scripts which help to deploy latest releases of OneFuzz at demand. It uses Azure DevOps Build Pipeline. This section of code contains scripts which help to deploy latest releases of OneFuzz at demand. It uses Azure DevOps Build Pipeline.
The script [deploy-onefuzz.yml](deploy-onefuzz.yml) can be used saved in Azure DevOps Build Pipeline or can be stored in the repository and can be pointed to it. The script [deploy-onefuzz.yml](deploy-onefuzz.yml) can be used saved in Azure DevOps Build Pipeline or can be stored in the repository and can be pointed to it.
It also contain supporting `python` scripts which helps to fetch latest version and artifacts from OneFuzz GitHub repository. It also contain supporting `python` scripts which helps to fetch latest version and artifacts from OneFuzz GitHub repository.
# How to use it? # How to use it?
This script is intended only for deploying newer updates. There are certain set of pipeline variables needs to be set as mentioned in [deploy-onefuzz.yml](deploy-onefuzz.yml) for authentication purposes to the OneFuzz instance. This script is intended only for deploying newer updates. There are certain set of pipeline variables needs to be set as mentioned in [deploy-onefuzz.yml](deploy-onefuzz.yml) for authentication purposes to the OneFuzz instance.

View File

@ -1,21 +1,21 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# Copyright (c) Microsoft Corporation. # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License. # Licensed under the MIT License.
import azure.functions as func import azure.functions as func
# This endpoint handles the signalr negotation # This endpoint handles the signalr negotation
# As we do not differentiate from clients at this time, we pass the Functions runtime # As we do not differentiate from clients at this time, we pass the Functions runtime
# provided connection straight to the client # provided connection straight to the client
# #
# For more info: # For more info:
# https://docs.microsoft.com/en-us/azure/azure-signalr/signalr-concept-internals # https://docs.microsoft.com/en-us/azure/azure-signalr/signalr-concept-internals
def main(req: func.HttpRequest, connectionInfoJson: str) -> func.HttpResponse: def main(req: func.HttpRequest, connectionInfoJson: str) -> func.HttpResponse:
return func.HttpResponse( return func.HttpResponse(
connectionInfoJson, connectionInfoJson,
status_code=200, status_code=200,
headers={"Content-type": "application/json"}, headers={"Content-type": "application/json"},
) )

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# Copyright (c) Microsoft Corporation. # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License. # Licensed under the MIT License.

View File

@ -1,65 +1,65 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# Copyright (c) Microsoft Corporation. # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License. # Licensed under the MIT License.
import unittest import unittest
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
from uuid import UUID from uuid import UUID
from onefuzztypes.enums import OS, Architecture, ContainerType, TaskType from onefuzztypes.enums import OS, Architecture, ContainerType, TaskType
from onefuzztypes.models import TaskConfig, TaskContainers, TaskDetails, TaskPool from onefuzztypes.models import TaskConfig, TaskContainers, TaskDetails, TaskPool
from onefuzztypes.primitives import Container, PoolName from onefuzztypes.primitives import Container, PoolName
from __app__.onefuzzlib.autoscale import autoscale_pool, get_vm_count from __app__.onefuzzlib.autoscale import autoscale_pool, get_vm_count
from __app__.onefuzzlib.tasks.main import Task from __app__.onefuzzlib.tasks.main import Task
from __app__.onefuzzlib.workers.pools import Pool from __app__.onefuzzlib.workers.pools import Pool
class TestAutoscale(unittest.TestCase): class TestAutoscale(unittest.TestCase):
@patch("__app__.onefuzzlib.tasks.main.Task.get_tasks_by_pool_name") @patch("__app__.onefuzzlib.tasks.main.Task.get_tasks_by_pool_name")
def test_autoscale_pool(self, mock_get_tasks_by_pool_name: MagicMock) -> None: def test_autoscale_pool(self, mock_get_tasks_by_pool_name: MagicMock) -> None:
pool = Pool( pool = Pool(
name=PoolName("test-pool"), name=PoolName("test-pool"),
pool_id=UUID("6b049d51-23e9-4f5c-a5af-ff1f73d0d9e9"), pool_id=UUID("6b049d51-23e9-4f5c-a5af-ff1f73d0d9e9"),
os=OS.linux, os=OS.linux,
managed=False, managed=False,
arch=Architecture.x86_64, arch=Architecture.x86_64,
) )
autoscale_pool(pool=pool) autoscale_pool(pool=pool)
mock_get_tasks_by_pool_name.assert_not_called() mock_get_tasks_by_pool_name.assert_not_called()
@patch("__app__.onefuzzlib.tasks.main.Task.get_pool") @patch("__app__.onefuzzlib.tasks.main.Task.get_pool")
def test_get_vm_count(self, mock_get_pool: MagicMock) -> None: def test_get_vm_count(self, mock_get_pool: MagicMock) -> None:
self.assertEqual(get_vm_count([]), 0) self.assertEqual(get_vm_count([]), 0)
task_config = TaskConfig( task_config = TaskConfig(
job_id=UUID("6b049d51-23e9-4f5c-a5af-ff1f73d0d9e9"), job_id=UUID("6b049d51-23e9-4f5c-a5af-ff1f73d0d9e9"),
containers=[ containers=[
TaskContainers( TaskContainers(
type=ContainerType.inputs, name=Container("test-container") type=ContainerType.inputs, name=Container("test-container")
) )
], ],
tags={}, tags={},
task=TaskDetails( task=TaskDetails(
type=TaskType.libfuzzer_fuzz, type=TaskType.libfuzzer_fuzz,
duration=12, duration=12,
target_exe="fuzz.exe", target_exe="fuzz.exe",
target_env={}, target_env={},
target_options=[], target_options=[],
), ),
pool=TaskPool(count=2, pool_name=PoolName("test-pool")), pool=TaskPool(count=2, pool_name=PoolName("test-pool")),
) )
task = Task( task = Task(
job_id=UUID("6b049d51-23e9-4f5c-a5af-ff1f73d0d9e9"), job_id=UUID("6b049d51-23e9-4f5c-a5af-ff1f73d0d9e9"),
os=OS.linux, os=OS.linux,
config=task_config, config=task_config,
) )
mock_get_pool.return_value = Pool( mock_get_pool.return_value = Pool(
name=PoolName("test-pool"), name=PoolName("test-pool"),
pool_id=UUID("6b049d51-23e9-4f5c-a5af-ff1f73d0d9e9"), pool_id=UUID("6b049d51-23e9-4f5c-a5af-ff1f73d0d9e9"),
os=OS.linux, os=OS.linux,
managed=False, managed=False,
arch=Architecture.x86_64, arch=Architecture.x86_64,
) )
self.assertEqual(get_vm_count([task]), 2) self.assertEqual(get_vm_count([task]), 2)

View File

@ -1,147 +1,147 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# Copyright (c) Microsoft Corporation. # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License. # Licensed under the MIT License.
import unittest import unittest
from typing import Dict, Generator, List, TypeVar from typing import Dict, Generator, List, TypeVar
from uuid import UUID, uuid4 from uuid import UUID, uuid4
from onefuzztypes.enums import OS, ContainerType, TaskType from onefuzztypes.enums import OS, ContainerType, TaskType
from onefuzztypes.models import TaskConfig, TaskContainers, TaskDetails, TaskPool from onefuzztypes.models import TaskConfig, TaskContainers, TaskDetails, TaskPool
from onefuzztypes.primitives import Container, PoolName from onefuzztypes.primitives import Container, PoolName
from __app__.onefuzzlib.tasks.main import Task from __app__.onefuzzlib.tasks.main import Task
from __app__.onefuzzlib.tasks.scheduler import bucket_tasks from __app__.onefuzzlib.tasks.scheduler import bucket_tasks
A = TypeVar("A") A = TypeVar("A")
def chunks(items: List[A], size: int) -> Generator[List[A], None, None]: def chunks(items: List[A], size: int) -> Generator[List[A], None, None]:
return (items[x : x + size] for x in range(0, len(items), size)) return (items[x : x + size] for x in range(0, len(items), size))
class TestTaskBuckets(unittest.TestCase): class TestTaskBuckets(unittest.TestCase):
def build_tasks(self, size: int) -> List[Task]: def build_tasks(self, size: int) -> List[Task]:
tasks = [] tasks = []
for _ in range(size): for _ in range(size):
task = Task( task = Task(
job_id=UUID(int=0), job_id=UUID(int=0),
config=TaskConfig( config=TaskConfig(
job_id=UUID(int=0), job_id=UUID(int=0),
task=TaskDetails( task=TaskDetails(
type=TaskType.libfuzzer_fuzz, type=TaskType.libfuzzer_fuzz,
duration=1, duration=1,
target_exe="fuzz.exe", target_exe="fuzz.exe",
target_env={}, target_env={},
target_options=[], target_options=[],
), ),
pool=TaskPool(pool_name=PoolName("pool"), count=1), pool=TaskPool(pool_name=PoolName("pool"), count=1),
containers=[ containers=[
TaskContainers( TaskContainers(
type=ContainerType.setup, name=Container("setup") type=ContainerType.setup, name=Container("setup")
) )
], ],
tags={}, tags={},
colocate=True, colocate=True,
), ),
os=OS.linux, os=OS.linux,
) )
tasks.append(task) tasks.append(task)
return tasks return tasks
def test_all_colocate(self) -> None: def test_all_colocate(self) -> None:
# all tasks should land in one bucket # all tasks should land in one bucket
tasks = self.build_tasks(10) tasks = self.build_tasks(10)
for task in tasks: for task in tasks:
task.config.colocate = True task.config.colocate = True
buckets = bucket_tasks(tasks) buckets = bucket_tasks(tasks)
for bucket in buckets.values(): for bucket in buckets.values():
self.assertEqual(len(bucket), 10) self.assertEqual(len(bucket), 10)
self.check_buckets(buckets, tasks, bucket_count=1) self.check_buckets(buckets, tasks, bucket_count=1)
def test_partial_colocate(self) -> None: def test_partial_colocate(self) -> None:
# 2 tasks should land on their own, the rest should be colocated into a # 2 tasks should land on their own, the rest should be colocated into a
# single bucket. # single bucket.
tasks = self.build_tasks(10) tasks = self.build_tasks(10)
# a the task came before colocation was defined # a the task came before colocation was defined
tasks[0].config.colocate = None tasks[0].config.colocate = None
# a the task shouldn't be colocated # a the task shouldn't be colocated
tasks[1].config.colocate = False tasks[1].config.colocate = False
buckets = bucket_tasks(tasks) buckets = bucket_tasks(tasks)
lengths = [] lengths = []
for bucket in buckets.values(): for bucket in buckets.values():
lengths.append(len(bucket)) lengths.append(len(bucket))
self.assertEqual([1, 1, 8], sorted(lengths)) self.assertEqual([1, 1, 8], sorted(lengths))
self.check_buckets(buckets, tasks, bucket_count=3) self.check_buckets(buckets, tasks, bucket_count=3)
def test_all_unique_job(self) -> None: def test_all_unique_job(self) -> None:
# everything has a unique job_id # everything has a unique job_id
tasks = self.build_tasks(10) tasks = self.build_tasks(10)
for task in tasks: for task in tasks:
job_id = uuid4() job_id = uuid4()
task.job_id = job_id task.job_id = job_id
task.config.job_id = job_id task.config.job_id = job_id
buckets = bucket_tasks(tasks) buckets = bucket_tasks(tasks)
for bucket in buckets.values(): for bucket in buckets.values():
self.assertEqual(len(bucket), 1) self.assertEqual(len(bucket), 1)
self.check_buckets(buckets, tasks, bucket_count=10) self.check_buckets(buckets, tasks, bucket_count=10)
def test_multiple_job_buckets(self) -> None: def test_multiple_job_buckets(self) -> None:
# at most 3 tasks per bucket, by job_id # at most 3 tasks per bucket, by job_id
tasks = self.build_tasks(10) tasks = self.build_tasks(10)
for task_chunks in chunks(tasks, 3): for task_chunks in chunks(tasks, 3):
job_id = uuid4() job_id = uuid4()
for task in task_chunks: for task in task_chunks:
task.job_id = job_id task.job_id = job_id
task.config.job_id = job_id task.config.job_id = job_id
buckets = bucket_tasks(tasks) buckets = bucket_tasks(tasks)
for bucket in buckets.values(): for bucket in buckets.values():
self.assertLessEqual(len(bucket), 3) self.assertLessEqual(len(bucket), 3)
self.check_buckets(buckets, tasks, bucket_count=4) self.check_buckets(buckets, tasks, bucket_count=4)
def test_many_buckets(self) -> None: def test_many_buckets(self) -> None:
tasks = self.build_tasks(100) tasks = self.build_tasks(100)
job_id = UUID(int=1) job_id = UUID(int=1)
for i, task in enumerate(tasks): for i, task in enumerate(tasks):
if i % 2 == 0: if i % 2 == 0:
task.job_id = job_id task.job_id = job_id
task.config.job_id = job_id task.config.job_id = job_id
if i % 3 == 0: if i % 3 == 0:
task.os = OS.windows task.os = OS.windows
if i % 4 == 0: if i % 4 == 0:
task.config.containers[0].name = Container("setup2") task.config.containers[0].name = Container("setup2")
if i % 5 == 0: if i % 5 == 0:
if task.config.pool: if task.config.pool:
task.config.pool.pool_name = PoolName("alternate-pool") task.config.pool.pool_name = PoolName("alternate-pool")
buckets = bucket_tasks(tasks) buckets = bucket_tasks(tasks)
self.check_buckets(buckets, tasks, bucket_count=12) self.check_buckets(buckets, tasks, bucket_count=12)
def check_buckets(self, buckets: Dict, tasks: List, *, bucket_count: int) -> None: def check_buckets(self, buckets: Dict, tasks: List, *, bucket_count: int) -> None:
self.assertEqual(len(buckets), bucket_count, "bucket count") self.assertEqual(len(buckets), bucket_count, "bucket count")
for task in tasks: for task in tasks:
seen = False seen = False
for bucket in buckets.values(): for bucket in buckets.values():
if task in bucket: if task in bucket:
self.assertEqual(seen, False, "task seen in multiple buckets") self.assertEqual(seen, False, "task seen in multiple buckets")
seen = True seen = True
self.assertEqual(seen, True, "task not seein in any buckets") self.assertEqual(seen, True, "task not seein in any buckets")

View File

@ -1,51 +1,51 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# Copyright (c) Microsoft Corporation. # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License. # Licensed under the MIT License.
import unittest import unittest
from uuid import UUID from uuid import UUID
from onefuzztypes.events import EventPing, EventType from onefuzztypes.events import EventPing, EventType
from __app__.onefuzzlib.webhooks import build_message from __app__.onefuzzlib.webhooks import build_message
class TestWebhookHmac(unittest.TestCase): class TestWebhookHmac(unittest.TestCase):
def test_webhook_hmac(self) -> None: def test_webhook_hmac(self) -> None:
webhook_id = UUID(int=0) webhook_id = UUID(int=0)
event_id = UUID(int=1) event_id = UUID(int=1)
event_type = EventType.ping event_type = EventType.ping
event = EventPing(ping_id=UUID(int=2)) event = EventPing(ping_id=UUID(int=2))
data, digest = build_message( data, digest = build_message(
webhook_id=webhook_id, event_id=event_id, event_type=event_type, event=event webhook_id=webhook_id, event_id=event_id, event_type=event_type, event=event
) )
expected = ( expected = (
b"{" b"{"
b'"event": {"ping_id": "00000000-0000-0000-0000-000000000002"}, ' b'"event": {"ping_id": "00000000-0000-0000-0000-000000000002"}, '
b'"event_id": "00000000-0000-0000-0000-000000000001", ' b'"event_id": "00000000-0000-0000-0000-000000000001", '
b'"event_type": "ping", ' b'"event_type": "ping", '
b'"webhook_id": "00000000-0000-0000-0000-000000000000"' b'"webhook_id": "00000000-0000-0000-0000-000000000000"'
b"}" b"}"
) )
expected_digest = ( expected_digest = (
"3502f83237ce006b7f6cfa40b89c0295009e3ccb0a1e62ce1d689700c2c6e698" "3502f83237ce006b7f6cfa40b89c0295009e3ccb0a1e62ce1d689700c2c6e698"
"61c0de81e011495c2ca89fbf99485b841cee257bcfba326a3edc66f39dc1feec" "61c0de81e011495c2ca89fbf99485b841cee257bcfba326a3edc66f39dc1feec"
) )
print(repr(expected)) print(repr(expected))
self.assertEqual(data, expected) self.assertEqual(data, expected)
self.assertEqual(digest, None) self.assertEqual(digest, None)
data, digest = build_message( data, digest = build_message(
webhook_id=webhook_id, webhook_id=webhook_id,
event_id=event_id, event_id=event_id,
event_type=event_type, event_type=event_type,
event=event, event=event,
secret_token="hello there", secret_token="hello there",
) )
self.assertEqual(data, expected) self.assertEqual(data, expected)
self.assertEqual(digest, expected_digest) self.assertEqual(digest, expected_digest)

View File

@ -1,20 +1,20 @@
import logging import logging
import os import os
import azure.functions as func import azure.functions as func
from onefuzz.api import Onefuzz from onefuzz.api import Onefuzz
def main(req: func.HttpRequest) -> func.HttpResponse: def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info("Python HTTP trigger function processed a request.") logging.info("Python HTTP trigger function processed a request.")
o = Onefuzz() o = Onefuzz()
o.config( o.config(
endpoint=os.environ.get("ONEFUZZ_ENDPOINT"), endpoint=os.environ.get("ONEFUZZ_ENDPOINT"),
authority=os.environ.get("ONEFUZZ_AUTHORITY"), authority=os.environ.get("ONEFUZZ_AUTHORITY"),
client_id=os.environ.get("ONEFUZZ_CLIENT_ID"), client_id=os.environ.get("ONEFUZZ_CLIENT_ID"),
client_secret=os.environ.get("ONEFUZZ_CLIENT_SECRET"), client_secret=os.environ.get("ONEFUZZ_CLIENT_SECRET"),
) )
info = o.info.get() info = o.info.get()
return func.HttpResponse(info.json()) return func.HttpResponse(info.json())