Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1cd7e801
Commit
1cd7e801
authored
Feb 15, 2020
by
Rajendra Kadam
Committed by
Peter Leitzen
Feb 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make follow up fixes for enable error tracking api
parent
90fd52b0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
41 deletions
+72
-41
app/models/error_tracking/project_error_tracking_setting.rb
app/models/error_tracking/project_error_tracking_setting.rb
+2
-0
changelogs/unreleased/error-tracking-api-followup.yml
changelogs/unreleased/error-tracking-api-followup.yml
+5
-0
spec/models/error_tracking/project_error_tracking_setting_spec.rb
...els/error_tracking/project_error_tracking_setting_spec.rb
+13
-0
spec/requests/api/error_tracking_spec.rb
spec/requests/api/error_tracking_spec.rb
+52
-41
No files found.
app/models/error_tracking/project_error_tracking_setting.rb
View file @
1cd7e801
...
@@ -27,6 +27,8 @@ module ErrorTracking
...
@@ -27,6 +27,8 @@ module ErrorTracking
validates
:api_url
,
length:
{
maximum:
255
},
public_url:
{
enforce_sanitization:
true
,
ascii_only:
true
},
allow_nil:
true
validates
:api_url
,
length:
{
maximum:
255
},
public_url:
{
enforce_sanitization:
true
,
ascii_only:
true
},
allow_nil:
true
validates
:enabled
,
inclusion:
{
in:
[
true
,
false
]
}
validates
:api_url
,
presence:
{
message:
'is a required field'
},
if: :enabled
validates
:api_url
,
presence:
{
message:
'is a required field'
},
if: :enabled
validate
:validate_api_url_path
,
if: :enabled
validate
:validate_api_url_path
,
if: :enabled
...
...
changelogs/unreleased/error-tracking-api-followup.yml
0 → 100644
View file @
1cd7e801
---
title
:
Refactor error tracking specs and add validation to enabled field in error tracking model
merge_request
:
24892
author
:
Rajendra Kadam
type
:
added
spec/models/error_tracking/project_error_tracking_setting_spec.rb
View file @
1cd7e801
...
@@ -19,6 +19,19 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
...
@@ -19,6 +19,19 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
it
{
is_expected
.
to
allow_value
(
"http://gitlab.com/api/0/projects/project1/something"
).
for
(
:api_url
)
}
it
{
is_expected
.
to
allow_value
(
"http://gitlab.com/api/0/projects/project1/something"
).
for
(
:api_url
)
}
it
{
is_expected
.
not_to
allow_values
(
"http://gitlab.com/api/0/projects/project1/something€"
).
for
(
:api_url
)
}
it
{
is_expected
.
not_to
allow_values
(
"http://gitlab.com/api/0/projects/project1/something€"
).
for
(
:api_url
)
}
it
'disallows non-booleans in enabled column'
do
is_expected
.
not_to
allow_value
(
nil
).
for
(
:enabled
)
end
it
'allows booleans in enabled column'
do
is_expected
.
to
allow_value
(
true
,
false
).
for
(
:enabled
)
end
it
'rejects invalid api_urls'
do
it
'rejects invalid api_urls'
do
is_expected
.
not_to
allow_values
(
is_expected
.
not_to
allow_values
(
"https://replaceme.com/'><script>alert(document.cookie)</script>"
,
# unsafe
"https://replaceme.com/'><script>alert(document.cookie)</script>"
,
# unsafe
...
...
spec/requests/api/error_tracking_spec.rb
View file @
1cd7e801
...
@@ -3,13 +3,13 @@
...
@@ -3,13 +3,13 @@
require
'spec_helper'
require
'spec_helper'
describe
API
::
ErrorTracking
do
describe
API
::
ErrorTracking
do
let
(
:user
)
{
create
(
:user
)
}
let
_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:setting
)
{
create
(
:project_error_tracking_setting
)
}
let
(
:setting
)
{
create
(
:project_error_tracking_setting
)
}
let
(
:project
)
{
setting
.
project
}
let
(
:project
)
{
setting
.
project
}
shared_examples
'returns project settings'
do
shared_examples
'returns project settings'
do
it
'returns correct project settings'
do
it
'returns correct project settings'
do
subjec
t
make_reques
t
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
eq
(
expect
(
json_response
).
to
eq
(
...
@@ -23,7 +23,7 @@ describe API::ErrorTracking do
...
@@ -23,7 +23,7 @@ describe API::ErrorTracking do
shared_examples
'returns 404'
do
shared_examples
'returns 404'
do
it
'returns correct project settings'
do
it
'returns correct project settings'
do
subjec
t
make_reques
t
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
json_response
[
'message'
])
expect
(
json_response
[
'message'
])
...
@@ -32,7 +32,9 @@ describe API::ErrorTracking do
...
@@ -32,7 +32,9 @@ describe API::ErrorTracking do
end
end
describe
"PATCH /projects/:id/error_tracking/settings"
do
describe
"PATCH /projects/:id/error_tracking/settings"
do
def
make_patch_request
(
**
params
)
let
(
:params
)
{
{
active:
false
}
}
def
make_request
patch
api
(
"/projects/
#{
project
.
id
}
/error_tracking/settings"
,
user
),
params:
params
patch
api
(
"/projects/
#{
project
.
id
}
/error_tracking/settings"
,
user
),
params:
params
end
end
...
@@ -42,26 +44,39 @@ describe API::ErrorTracking do
...
@@ -42,26 +44,39 @@ describe API::ErrorTracking do
end
end
context
'patch settings'
do
context
'patch settings'
do
subject
do
it_behaves_like
'returns project settings'
make_patch_request
(
active:
false
)
it
'updates enabled flag'
do
expect
(
setting
).
to
be_enabled
make_request
expect
(
json_response
).
to
include
(
'active'
=>
false
)
expect
(
setting
.
reload
).
not_to
be_enabled
end
end
it_behaves_like
'returns project settings'
context
'active is invalid'
do
let
(
:params
)
{
{
active:
"randomstring"
}
}
it
'returns active is invalid if non boolean'
do
it
'returns active is invalid if non boolean'
do
make_patch_request
(
active:
"randomstring"
)
make_request
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'error'
])
expect
(
json_response
[
'error'
])
.
to
eq
(
'active is invalid'
)
.
to
eq
(
'active is invalid'
)
end
end
end
it
'returns 400 if active is empty'
do
context
'active is empty'
do
make_patch_request
(
active:
''
)
let
(
:params
)
{
{
active:
''
}
}
it
'returns 400'
do
make_request
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'error'
])
expect
(
json_response
[
'error'
])
.
to
eq
(
'active is empty'
)
.
to
eq
(
'active is empty'
)
end
end
end
end
end
...
@@ -73,10 +88,6 @@ describe API::ErrorTracking do
...
@@ -73,10 +88,6 @@ describe API::ErrorTracking do
end
end
context
'patch settings'
do
context
'patch settings'
do
subject
do
make_patch_request
(
active:
true
)
end
it_behaves_like
'returns 404'
it_behaves_like
'returns 404'
end
end
end
end
...
@@ -87,10 +98,12 @@ describe API::ErrorTracking do
...
@@ -87,10 +98,12 @@ describe API::ErrorTracking do
project
.
add_reporter
(
user
)
project
.
add_reporter
(
user
)
end
end
it
'returns 403 for update request'
do
context
'patch request'
do
make_patch_request
(
active:
true
)
it
'returns 403'
do
make_request
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
end
end
end
...
@@ -99,28 +112,34 @@ describe API::ErrorTracking do
...
@@ -99,28 +112,34 @@ describe API::ErrorTracking do
project
.
add_developer
(
user
)
project
.
add_developer
(
user
)
end
end
it
'returns 403 for update request'
do
context
'patch request'
do
make_patch_request
(
active:
true
)
it
'returns 403'
do
make_request
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
end
end
end
context
'when authenticated as non-member'
do
context
'when authenticated as non-member'
do
it
'returns 404 for update request'
do
context
'patch request'
do
make_patch_request
(
active:
false
)
it
'returns 404'
do
make_request
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
end
end
end
context
'when unauthenticated'
do
context
'when unauthenticated'
do
let
(
:user
)
{
nil
}
let
(
:user
)
{
nil
}
it
'returns 401 for update request'
do
context
'patch request'
do
make_patch_request
(
active:
true
)
it
'returns 401 for update request'
do
make_request
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
end
end
end
end
end
...
@@ -136,10 +155,6 @@ describe API::ErrorTracking do
...
@@ -136,10 +155,6 @@ describe API::ErrorTracking do
end
end
context
'get settings'
do
context
'get settings'
do
subject
do
make_request
end
it_behaves_like
'returns project settings'
it_behaves_like
'returns project settings'
end
end
end
end
...
@@ -152,10 +167,6 @@ describe API::ErrorTracking do
...
@@ -152,10 +167,6 @@ describe API::ErrorTracking do
end
end
context
'get settings'
do
context
'get settings'
do
subject
do
make_request
end
it_behaves_like
'returns 404'
it_behaves_like
'returns 404'
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment