Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
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 Boudes
mastodon
Commits
552d69ad
Unverified
Commit
552d69ad
authored
2 years ago
by
Eugen Rochko
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix error when invalid domain name is submitted (#19474)
Fix #19175
parent
523e106c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/concerns/domain_normalizable.rb
+2
-0
2 additions, 0 deletions
app/models/concerns/domain_normalizable.rb
spec/controllers/api/v1/admin/domain_allows_controller_spec.rb
+28
-16
28 additions, 16 deletions
...controllers/api/v1/admin/domain_allows_controller_spec.rb
with
30 additions
and
16 deletions
app/models/concerns/domain_normalizable.rb
+
2
−
0
View file @
552d69ad
...
...
@@ -11,5 +11,7 @@ module DomainNormalizable
def
normalize_domain
self
.
domain
=
TagManager
.
instance
.
normalize_domain
(
domain
&
.
strip
)
rescue
Addressable
::
URI
::
InvalidURIError
errors
.
add
(
:domain
,
:invalid
)
end
end
This diff is collapsed.
Click to expand it.
spec/controllers/api/v1/admin/domain_allows_controller_spec.rb
+
28
−
16
View file @
552d69ad
...
...
@@ -94,25 +94,37 @@ RSpec.describe Api::V1::Admin::DomainAllowsController, type: :controller do
describe
'POST #create'
do
let!
(
:domain_allow
)
{
Fabricate
(
:domain_allow
,
domain:
'example.com'
)
}
before
do
post
:create
,
params:
{
domain:
'foo.bar.com'
}
end
it_behaves_like
'forbidden for wrong scope'
,
'write:statuses'
it_behaves_like
'forbidden for wrong role'
,
''
it_behaves_like
'forbidden for wrong role'
,
'Moderator'
it
'returns http success'
do
expect
(
response
).
to
have_http_status
(
200
)
context
do
before
do
post
:create
,
params:
{
domain:
'foo.bar.com'
}
end
it_behaves_like
'forbidden for wrong scope'
,
'write:statuses'
it_behaves_like
'forbidden for wrong role'
,
''
it_behaves_like
'forbidden for wrong role'
,
'Moderator'
it
'returns http success'
do
expect
(
response
).
to
have_http_status
(
200
)
end
it
'returns expected domain name'
do
json
=
body_as_json
expect
(
json
[
:domain
]).
to
eq
'foo.bar.com'
end
it
'creates a domain block'
do
expect
(
DomainAllow
.
find_by
(
domain:
'foo.bar.com'
)).
to_not
be_nil
end
end
it
'returns expecte
d domain name'
do
json
=
body_as_json
expect
(
json
[
:domain
]).
to
eq
'foo
.
bar
.com'
end
context
'with invali
d domain name'
do
before
do
post
:create
,
params:
{
domain:
'foo
bar
'
}
end
it
'creates a domain block'
do
expect
(
DomainAllow
.
find_by
(
domain:
'foo.bar.com'
)).
to_not
be_nil
it
'returns http unprocessable entity'
do
expect
(
response
).
to
have_http_status
(
422
)
end
end
end
end
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