This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify removing UserInfo from events prior to logging (#795)
- Loading branch information
Showing
2 changed files
with
97 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 76 additions & 76 deletions
152
src/api-service/tests/test_secret_filter.py → ...api-service/tests/test_userinfo_filter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,76 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
|
||
import unittest | ||
from uuid import uuid4 | ||
|
||
from onefuzztypes.enums import ContainerType, TaskType | ||
from onefuzztypes.events import EventTaskCreated, get_event_type | ||
from onefuzztypes.models import ( | ||
TaskConfig, | ||
TaskContainers, | ||
TaskDetails, | ||
TaskPool, | ||
UserInfo, | ||
) | ||
from onefuzztypes.primitives import Container, PoolName | ||
|
||
from __app__.onefuzzlib.events import filter_event | ||
|
||
|
||
class TestSecretFilter(unittest.TestCase): | ||
def test_secret_filter(self) -> None: | ||
job_id = uuid4() | ||
task_id = uuid4() | ||
application_id = uuid4() | ||
object_id = uuid4() | ||
upn = "testalias@contoso.com" | ||
|
||
user_info = UserInfo( | ||
application_id=application_id, object_id=object_id, upn=upn | ||
) | ||
|
||
task_config = TaskConfig( | ||
job_id=job_id, | ||
containers=[ | ||
TaskContainers( | ||
type=ContainerType.inputs, name=Container("test-container") | ||
) | ||
], | ||
tags={}, | ||
task=TaskDetails( | ||
type=TaskType.libfuzzer_fuzz, | ||
duration=12, | ||
target_exe="fuzz.exe", | ||
target_env={}, | ||
target_options=[], | ||
), | ||
pool=TaskPool(count=2, pool_name=PoolName("test-pool")), | ||
) | ||
|
||
test_event = EventTaskCreated( | ||
job_id=job_id, | ||
task_id=task_id, | ||
config=task_config, | ||
user_info=user_info, | ||
) | ||
|
||
control_test_event = EventTaskCreated( | ||
job_id=job_id, | ||
task_id=task_id, | ||
config=task_config, | ||
user_info=None, | ||
) | ||
|
||
test_event_type = get_event_type(test_event) | ||
|
||
scrubbed_test_event = filter_event(test_event, test_event_type) | ||
|
||
self.assertEqual(scrubbed_test_event, control_test_event) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
#!/usr/bin/env python | ||
# | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
|
||
import unittest | ||
from uuid import uuid4 | ||
|
||
from onefuzztypes.enums import ContainerType, TaskType | ||
from onefuzztypes.events import EventTaskCreated, get_event_type | ||
from onefuzztypes.models import ( | ||
TaskConfig, | ||
TaskContainers, | ||
TaskDetails, | ||
TaskPool, | ||
UserInfo, | ||
) | ||
from onefuzztypes.primitives import Container, PoolName | ||
|
||
from __app__.onefuzzlib.events import filter_event | ||
|
||
|
||
class TestUserInfoFilter(unittest.TestCase): | ||
def test_user_info_filter(self) -> None: | ||
job_id = uuid4() | ||
task_id = uuid4() | ||
application_id = uuid4() | ||
object_id = uuid4() | ||
upn = "testalias@contoso.com" | ||
|
||
user_info = UserInfo( | ||
application_id=application_id, object_id=object_id, upn=upn | ||
) | ||
|
||
task_config = TaskConfig( | ||
job_id=job_id, | ||
containers=[ | ||
TaskContainers( | ||
type=ContainerType.inputs, name=Container("test-container") | ||
) | ||
], | ||
tags={}, | ||
task=TaskDetails( | ||
type=TaskType.libfuzzer_fuzz, | ||
duration=12, | ||
target_exe="fuzz.exe", | ||
target_env={}, | ||
target_options=[], | ||
), | ||
pool=TaskPool(count=2, pool_name=PoolName("test-pool")), | ||
) | ||
|
||
test_event = EventTaskCreated( | ||
job_id=job_id, | ||
task_id=task_id, | ||
config=task_config, | ||
user_info=user_info, | ||
) | ||
|
||
control_test_event = EventTaskCreated( | ||
job_id=job_id, | ||
task_id=task_id, | ||
config=task_config, | ||
user_info=None, | ||
) | ||
|
||
test_event_type = get_event_type(test_event) | ||
|
||
scrubbed_test_event = filter_event(test_event, test_event_type) | ||
|
||
self.assertEqual(scrubbed_test_event, control_test_event) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |