-
Notifications
You must be signed in to change notification settings - Fork 981
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add malware check syncing mechanism (#7190)
* Add malware check syncing mechanism * Code review changes.
- Loading branch information
Showing
9 changed files
with
464 additions
and
74 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pretend | ||
|
||
from warehouse.cli.malware import sync_checks | ||
from warehouse.malware.tasks import sync_checks as _sync_checks | ||
|
||
|
||
class TestCLIMalware: | ||
def test_sync_checks(self, cli): | ||
request = pretend.stub() | ||
task = pretend.stub( | ||
get_request=pretend.call_recorder(lambda *a, **kw: request), | ||
run=pretend.call_recorder(lambda *a, **kw: None), | ||
) | ||
config = pretend.stub(task=pretend.call_recorder(lambda *a, **kw: task)) | ||
|
||
result = cli.invoke(sync_checks, obj=config) | ||
|
||
assert result.exit_code == 0 | ||
assert config.task.calls == [ | ||
pretend.call(_sync_checks), | ||
pretend.call(_sync_checks), | ||
] | ||
assert task.get_request.calls == [pretend.call()] | ||
assert task.run.calls == [pretend.call(request)] |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import inspect | ||
|
||
import warehouse.malware.checks as checks | ||
|
||
from warehouse.malware.checks.base import MalwareCheckBase | ||
from warehouse.malware.utils import get_check_fields | ||
|
||
|
||
def test_checks_subclass_base(): | ||
checks_from_module = inspect.getmembers(checks, inspect.isclass) | ||
|
||
subclasses_of_malware_base = { | ||
cls.__name__: cls for cls in MalwareCheckBase.__subclasses__() | ||
} | ||
|
||
assert len(checks_from_module) == len(subclasses_of_malware_base) | ||
|
||
for check_name, check in checks_from_module: | ||
assert subclasses_of_malware_base[check_name] == check | ||
|
||
|
||
def test_checks_fields(): | ||
checks_from_module = inspect.getmembers(checks, inspect.isclass) | ||
|
||
for check_name, check in checks_from_module: | ||
elems = inspect.getmembers(check, lambda a: not (inspect.isroutine(a))) | ||
inspection_fields = {"name": check_name} | ||
for elem_name, value in elems: | ||
if not elem_name.startswith("__"): | ||
inspection_fields[elem_name] = value | ||
fields = get_check_fields(check) | ||
|
||
assert inspection_fields == fields |
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
Oops, something went wrong.