-
Notifications
You must be signed in to change notification settings - Fork 963
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add rudimentary verdicts view. Progress on #6062. Also, add some better testing logic for wiped_out condition. * Code review changes. - Conditionally show fields that are populated - JSON pretty formatting * Fix unit test bug. - Use `get` instead of `filter` to look up verdict by pkey. * simplify unit tests for verdicts view
- Loading branch information
Showing
12 changed files
with
350 additions
and
4 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
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,63 @@ | ||
# 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 uuid | ||
|
||
from random import randint | ||
|
||
import pretend | ||
import pytest | ||
|
||
from pyramid.httpexceptions import HTTPBadRequest, HTTPNotFound | ||
|
||
from warehouse.admin.views import verdicts as views | ||
|
||
from ....common.db.malware import MalwareVerdictFactory | ||
|
||
|
||
class TestListVerdicts: | ||
def test_none(self, db_request): | ||
assert views.get_verdicts(db_request) == {"verdicts": []} | ||
|
||
def test_some(self, db_request): | ||
verdicts = [MalwareVerdictFactory.create() for _ in range(10)] | ||
|
||
assert views.get_verdicts(db_request) == {"verdicts": verdicts} | ||
|
||
def test_some_with_multipage(self, db_request): | ||
verdicts = [MalwareVerdictFactory.create() for _ in range(60)] | ||
|
||
db_request.GET["page"] = "2" | ||
|
||
assert views.get_verdicts(db_request) == {"verdicts": verdicts[25:50]} | ||
|
||
def test_with_invalid_page(self): | ||
request = pretend.stub(params={"page": "not an integer"}) | ||
|
||
with pytest.raises(HTTPBadRequest): | ||
views.get_verdicts(request) | ||
|
||
|
||
class TestGetVerdict: | ||
def test_found(self, db_request): | ||
verdicts = [MalwareVerdictFactory.create() for _ in range(10)] | ||
index = randint(0, 9) | ||
lookup_id = verdicts[index].id | ||
db_request.matchdict["verdict_id"] = lookup_id | ||
|
||
assert views.get_verdict(db_request) == {"verdict": verdicts[index]} | ||
|
||
def test_not_found(self, db_request): | ||
db_request.matchdict["verdict_id"] = uuid.uuid4() | ||
|
||
with pytest.raises(HTTPNotFound): | ||
views.get_verdict(db_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
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
80 changes: 80 additions & 0 deletions
80
warehouse/admin/templates/admin/malware/verdicts/detail.html
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,80 @@ | ||
{# | ||
# 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. | ||
-#} | ||
{% extends "admin/base.html" %} | ||
|
||
{% block title %}Verdict {{ verdict.id }}{% endblock %} | ||
|
||
{% block breadcrumb %} | ||
<li><a href="{{ request.route_path('admin.verdicts.list') }}">Verdicts</a></li> | ||
<li class="active">{{ verdict.id }}</li> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="box box-primary"> | ||
<div class="box-body box-profile"> | ||
<table class="table table-hover"> | ||
<tr> | ||
<th scope="row">Message</th> | ||
<td>{{ verdict.message }}</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Run Date</th> | ||
<td>{{ verdict.run_date }}</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Check</th> | ||
<td> | ||
<a href="{{ request.route_path('admin.checks.detail', check_name=verdict.check.name) }}"> | ||
{{ verdict.check.name }} v{{ verdict.check.version }} | ||
</a> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Object</th> | ||
<td>{% include 'object_link.html' %}</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Verdict Classification</th> | ||
<td>{{ verdict.classification.value }}</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Verdict Confidence</th> | ||
<td>{{ verdict.confidence.value }}</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Manually Reviewed</th> | ||
<td>{{ verdict.manually_reviewed }}</td> | ||
</tr> | ||
{% if verdict.manually_reviewed %} | ||
<tr> | ||
<th scope="row">Administrator Verdict</th> | ||
<td>{{ verdict.administrator_verdict }}</td> | ||
</tr> | ||
{% endif %} | ||
{% if verdict.full_report_link %} | ||
<tr> | ||
<th scope="row">Full Report Link</th> | ||
<td>{{ verdict.full_report_link }}</td> | ||
</tr> | ||
{% endif %} | ||
{% if verdict.details %} | ||
<tr> | ||
<th scope="row">Details</th> | ||
<td><pre>{{ verdict.details|tojson(indent=4) }}</pre></td> | ||
</tr> | ||
{% endif %} | ||
</table> | ||
</div> | ||
</div> | ||
{% endblock %} |
93 changes: 93 additions & 0 deletions
93
warehouse/admin/templates/admin/malware/verdicts/index.html
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,93 @@ | ||
{# | ||
# 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. | ||
-#} | ||
{% extends "admin/base.html" %} | ||
|
||
{% import "admin/utils/pagination.html" as pagination %} | ||
|
||
{% block title %}Malware Verdicts{% endblock %} | ||
|
||
{% block breadcrumb %} | ||
<li class="active">Verdicts</li> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="box box-primary"> | ||
<div class="box-body table-responsive no-padding"> | ||
<table class="table table-hover"> | ||
<tr> | ||
<th>Object</th> | ||
<th>Check</th> | ||
<th>Classification</th> | ||
<th>Confidence</th> | ||
<th>Detail</th> | ||
</tr> | ||
{% for verdict in verdicts %} | ||
<tr> | ||
<td>{% include 'object_link.html' %}</td> | ||
<td> | ||
<a href="{{ request.route_path('admin.checks.detail', check_name=verdict.check.name) }}"> | ||
{{ verdict.check.name }} v{{ verdict.check.version }} | ||
</a> | ||
</td> | ||
<td> | ||
<span title="{{ verdict.classification.value }}"> | ||
<i class="fa fa-exclamation"></i> | ||
{% if verdict.classification.value == 'indeterminate' %} | ||
<i class="fa fa-exclamation"></i> | ||
{% elif verdict.classification.value == 'threat' %} | ||
<i class="fa fa-exclamation"></i> | ||
<i class="fa fa-exclamation"></i> | ||
{% endif %} | ||
</span> | ||
</td> | ||
<td> | ||
<span title="{{ verdict.confidence.value }}"> | ||
<i class="fa fa-star"></i> | ||
{% if verdict.confidence.value == 'medium' %} | ||
<i class="fa fa-star"></i> | ||
{% elif verdict.confidence.value == 'high' %} | ||
<i class="fa fa-star"></i> | ||
<i class="fa fa-star"></i> | ||
{% endif %} | ||
</span> | ||
</td> | ||
<td> | ||
<a href="{{ request.route_path('admin.verdicts.detail', verdict_id=verdict.id) }}"> | ||
Detail | ||
</a> | ||
</td> | ||
</tr> | ||
{% else %} | ||
<tr> | ||
<td colspan="5"> | ||
<center> | ||
<i>No verdicts!</i> | ||
</center> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
<div class="box-footer"> | ||
<div class="col-sm-5"> | ||
{{ pagination.summary(verdicts) }} | ||
</div> | ||
<div class="col-sm-7"> | ||
<div class="pull-right"> | ||
{{ pagination.paginate(verdicts) }} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock content %} |
21 changes: 21 additions & 0 deletions
21
warehouse/admin/templates/admin/malware/verdicts/object_link.html
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,21 @@ | ||
{# | ||
# 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. | ||
-#} | ||
|
||
{% if verdict.project %} | ||
<a href="{{ request.route_path('admin.project.detail', project_name=verdict.project.normalized_name) }}"><i class="fa fa-cube"></i> {{ verdict.project.name }} </a> | ||
{% elif verdict.release %} | ||
<a href="{{ request.route_path('admin.project.release', project_name=verdict.release.project.normalized_name, version=verdict.release.version) }}"><i class="far fa-folder"></i> {{ verdict.release.project.name }}-{{ verdict.release.version }} </a> | ||
{% else %} | ||
<a href="{{ request.route_path('admin.project.release', project_name=verdict.release_file.release.project.normalized_name, version=verdict.release_file.release.version) }}"><i class="far fa-file"></i> {{ verdict.release_file.filename}} </a> | ||
{% endif %} |
Oops, something went wrong.