Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre-Yves David
swh-web
Commits
6102891b
Commit
6102891b
authored
1 year ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
Badges: Return proper error instead of 500 status on invalid hashes
parent
8c949d58
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
swh/web/badges/__init__.py
+1
-1
1 addition, 1 deletion
swh/web/badges/__init__.py
swh/web/badges/tests/test_badges.py
+11
-0
11 additions, 0 deletions
swh/web/badges/tests/test_badges.py
swh/web/badges/urls.py
+7
-2
7 additions, 2 deletions
swh/web/badges/urls.py
with
19 additions
and
3 deletions
swh/web/badges/__init__.py
+
1
−
1
View file @
6102891b
...
...
@@ -134,7 +134,7 @@ def swh_badge(
if
parsed_object_type
==
ObjectType
.
RELEASE
:
right_text
=
"
release %s
"
%
swh_object
[
"
name
"
]
left_text
=
"
archived
"
except
(
BadInputExc
,
ValidationError
):
except
(
BadInputExc
,
ValidationError
,
ValueError
):
right_text
=
f
'
invalid
{
object_type
if
object_type
else
"
object
"
}
id
'
object_type
=
"
error
"
except
NotFoundExc
:
...
...
This diff is collapsed.
Click to expand it.
swh/web/badges/tests/test_badges.py
+
11
−
0
View file @
6102891b
...
...
@@ -5,6 +5,9 @@
from
corsheaders.middleware
import
ACCESS_CONTROL_ALLOW_ORIGIN
from
hypothesis
import
given
import
pytest
from
django.urls.exceptions
import
NoReverseMatch
from
swh.model.hashutil
import
hash_to_bytes
from
swh.model.swhids
import
ObjectType
,
QualifiedSWHID
...
...
@@ -74,6 +77,7 @@ def test_badge_errors(
(
ObjectType
.
RELEASE
,
invalid_sha1
),
(
ObjectType
.
REVISION
,
invalid_sha1
),
(
ObjectType
.
SNAPSHOT
,
invalid_sha1
),
(
ObjectType
.
SNAPSHOT
,
"
123
"
),
):
url_args
=
{
"
object_type
"
:
object_type
.
name
.
lower
(),
"
object_id
"
:
object_id
}
url
=
reverse
(
"
swh-badge
"
,
url_args
=
url_args
)
...
...
@@ -90,6 +94,13 @@ def test_badge_errors(
)
_check_generated_badge
(
resp
,
""
,
""
,
error
=
"
invalid id
"
)
for
object_type
,
object_id
in
(
(
ObjectType
.
SNAPSHOT
,
"
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
"
),
):
url_args
=
{
"
object_type
"
:
object_type
.
name
.
lower
(),
"
object_id
"
:
object_id
}
with
pytest
.
raises
(
NoReverseMatch
):
reverse
(
"
swh-badge
"
,
url_args
=
url_args
)
def
test_badge_endpoints_have_cors_header
(
client
,
origin
,
release
):
url
=
reverse
(
...
...
This diff is collapsed.
Click to expand it.
swh/web/badges/urls.py
+
7
−
2
View file @
6102891b
...
...
@@ -9,12 +9,17 @@ from swh.web.badges import swh_badge, swh_badge_swhid
urlpatterns
=
[
url
(
r
"
^badge/(?P<object_type>
[a-z]+
)/(?P<object_id>.+)/$
"
,
r
"
^badge/(?P<object_type>
origin
)/(?P<object_id>.+)/$
"
,
swh_badge
,
name
=
"
swh-badge
"
,
),
url
(
r
"
^badge/(?P<object_swhid>swh:[0-9]+:[a-z]+:[0-9a-f]+.*)/$
"
,
r
"
^badge/(?P<object_type>[a-z]+)/(?P<object_id>[0-9a-f]+)/$
"
,
swh_badge
,
name
=
"
swh-badge
"
,
),
url
(
r
"
^badge/(?P<object_swhid>swh:[0-9]+:[a-z]+:[0-9a-f]+(;.*)?)/$
"
,
swh_badge_swhid
,
name
=
"
swh-badge-swhid
"
,
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment