Skip to content

Commit

Permalink
Fix Rubocop offenses for Rails/HttpStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
saraycp committed May 20, 2024
1 parent f3eb238 commit bafa4e3
Show file tree
Hide file tree
Showing 26 changed files with 847 additions and 879 deletions.
32 changes: 0 additions & 32 deletions src/api/.rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -868,38 +868,6 @@ Rails/HelperInstanceVariable:
- 'app/helpers/webui/project_helper.rb'
- 'app/helpers/webui/webui_helper.rb'

# Offense count: 847
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: numeric, symbolic
Rails/HttpStatus:
Exclude:
- 'test/functional/about_controller_test.rb'
- 'test/functional/architectures_controller_test.rb'
- 'test/functional/attributes_test.rb'
- 'test/functional/build_controller_test.rb'
- 'test/functional/channel_maintenance_test.rb'
- 'test/functional/comments_controller_test.rb'
- 'test/functional/configurations_controller_test.rb'
- 'test/functional/group_test.rb'
- 'test/functional/interconnect_test.rb'
- 'test/functional/issue_controller_test.rb'
- 'test/functional/issue_trackers_controller_test.rb'
- 'test/functional/maintenance_test.rb'
- 'test/functional/person_controller_test.rb'
- 'test/functional/product_test.rb'
- 'test/functional/public_controller_test.rb'
- 'test/functional/published_controller_test.rb'
- 'test/functional/read_permission_test.rb'
- 'test/functional/release_management_test.rb'
- 'test/functional/request_controller_test.rb'
- 'test/functional/search_binary_release_test.rb'
- 'test/functional/search_controller_test.rb'
- 'test/functional/source_controller_test.rb'
- 'test/functional/source_services_test.rb'
- 'test/functional/statistics_controller_test.rb'
- 'test/functional/status_controller_test.rb'

# Offense count: 39
# Configuration parameters: IgnoreScopes, Include.
# Include: app/models/**/*.rb
Expand Down
2 changes: 1 addition & 1 deletion src/api/test/functional/about_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_about_anonymous
def test_application_controller
prepare_request_valid_user
get '/about?user[asd]=yxc'
assert_response 400
assert_response :bad_request
assert_xml_tag(tag: 'status', attributes: { code: 'invalid_parameter' })
end
end
4 changes: 2 additions & 2 deletions src/api/test/functional/architectures_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def setup
def test_index
# Get all issue trackers
get '/architectures'
assert_response 401
assert_response :unauthorized

prepare_request_valid_user
get '/architectures'
Expand All @@ -27,7 +27,7 @@ def test_show
assert_xml_tag tag: 'architecture', attributes: { name: 'i586' }

get '/architectures/futurearch'
assert_response 400
assert_response :bad_request
assert_xml_tag tag: 'status', attributes: { code: 'unknown_architecture' }
end
end
78 changes: 39 additions & 39 deletions src/api/test/functional/attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def setup

def test_index
get '/attribute/'
assert_response 401
assert_response :unauthorized

login_Iggy
get '/attribute/'
Expand All @@ -28,7 +28,7 @@ def test_namespace_index
login_Iggy

get '/attribute/NotExisting'
assert_response 404
assert_response :not_found

get '/attribute/OBS'
assert_response :success
Expand All @@ -53,11 +53,11 @@ def test_create_namespace_old

login_Iggy
post '/attribute/TEST/_meta', params: data
assert_response 403
assert_response :forbidden
assert_match(/Requires admin privileges/, @response.body)

delete '/attribute/OBS/_meta'
assert_response 403
assert_response :forbidden
assert_match(/Requires admin privileges/, @response.body)

login_king
Expand All @@ -69,7 +69,7 @@ def test_create_namespace_old
delete '/attribute/TEST/_meta'
assert_response :success
get '/attribute/TEST/_meta'
assert_response 404
assert_response :not_found

# using PUT and new delete route
put '/attribute/TEST/_meta', params: data
Expand All @@ -79,7 +79,7 @@ def test_create_namespace_old
delete '/attribute/TEST'
assert_response :success
get '/attribute/TEST/_meta'
assert_response 404
assert_response :not_found
end

def test_create_type
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_create_type
</definition>"

post '/attribute/TEST/Dummy/_meta', params: data
assert_response 401
assert_response :unauthorized

login_adrian
# FIXME3.0: POST is deprecated, use PUT
Expand All @@ -118,7 +118,7 @@ def test_create_type
delete '/attribute/TEST/Dummy/_meta'
assert_response :success
get '/attribute/TEST/Dummy/_meta'
assert_response 404
assert_response :not_found

# new PUT way
put '/attribute/TEST/Dummy/_meta', params: data
Expand All @@ -133,7 +133,7 @@ def test_create_type
</attribute>
</attributes>"
post '/source/home:adrian/_attribute', params: attrib_data
assert_response 400
assert_response :bad_request
assert_match(/Values Value ('|")M('|") is not allowed./, @response.body)
get '/source/home:adrian/_attribute'
assert_response :success
Expand All @@ -158,12 +158,12 @@ def test_create_type
# cleanup
login_Iggy
delete '/attribute/TEST/Dummy/_meta'
assert_response 403
assert_response :forbidden
login_adrian
delete '/attribute/TEST/Dummy'
assert_response :success
get '/attribute/TEST/Dummy/_meta'
assert_response 404
assert_response :not_found
end

def test_create_type_via_group
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_create_type_via_group
</definition>"

post '/attribute/TEST/Dummy/_meta', params: data
assert_response 401
assert_response :unauthorized

login_adrian
post '/attribute/TEST/Dummy/_meta', params: data
Expand All @@ -207,12 +207,12 @@ def test_create_type_via_group
end
login_Iggy
delete '/attribute/TEST/Dummy/_meta'
assert_response 403
assert_response :forbidden
login_adrian
delete '/attribute/TEST/Dummy/_meta'
assert_response :success
get '/attribute/TEST/Dummy/_meta'
assert_response 404
assert_response :not_found
end

def test_with_issue
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_with_issue
delete '/attribute/TEST/Dummy/_meta'
assert_response :success
get '/attribute/TEST/Dummy/_meta'
assert_response 404
assert_response :not_found
end

def test_attrib_type_meta
Expand All @@ -285,7 +285,7 @@ def test_attrib_type_meta
def test_invalid_get
login_Iggy
get '/source/RemoteInstance:BaseDistro/pack1/_attribute'
assert_response 404
assert_response :not_found
end

def test_attrib_write_permissions
Expand All @@ -295,10 +295,10 @@ def test_attrib_write_permissions

# XML with an attribute I should not be able to create
post '/source/home:tom/_attribute', params: data
assert_response 403
assert_response :forbidden
# same with attribute parameter
post '/source/home:tom/_attribute/OBS:Issues', params: data
assert_response 403
assert_response :forbidden
end

def test_attrib_delete_permissions
Expand All @@ -310,22 +310,22 @@ def test_attrib_delete_permissions

login_tom
delete '/source/home:tom/_attribute/OBS:VeryImportantProject'
assert_response 403
assert_response :forbidden
end

def test_create_attributes_project
login_tom

data = "<attributes><attribute namespace='OBS' name='Playground'/></attributes>"
post '/source/home:tom/_attribute', params: data
assert_response 404
assert_response :not_found
assert_select 'status[code] > summary', /Attribute Type OBS:Playground does not exist/

data = "<attributes><attribute namespace='OBS' name='Maintained' >
<value>blah</value>
</attribute></attributes>"
post '/source/home:tom/_attribute', params: data
assert_response 400
assert_response :bad_request
assert_select 'status[code] > summary', /has 1 values, but only 0 are allowed/

data = "<attributes><attribute namespace='OBS' name='Maintained'></attribute></attributes>"
Expand All @@ -341,15 +341,15 @@ def test_create_attributes_project
assert_equal({ 'attribute' => { 'name' => 'Maintained', 'namespace' => 'OBS' } }, Xmlhash.parse(@response.body))

get '/source/NOT_EXISTING/_attribute'
assert_response 404
assert_response :not_found
get '/source/home:tom/_attribute/OBS:NotExisting'
assert_response 404
assert_response :not_found
get '/source/home:tom/_attribute/NotExisting:NotExisting'
assert_response 404
assert_response :not_found

# via remote link
get '/source/RemoteInstance:home:tom/_attribute/OBS:Maintained'
assert_response 400
assert_response :bad_request

# via group
login_adrian
Expand All @@ -365,9 +365,9 @@ def test_create_attributes_project
# not allowed
login_Iggy
post '/source/home:tom/_attribute', params: data
assert_response 403
assert_response :forbidden
delete '/source/home:tom/_attribute/OBS:Maintained'
assert_response 403
assert_response :forbidden
get '/source/home:tom/_attribute/OBS:Maintained'
assert_response :success

Expand Down Expand Up @@ -409,7 +409,7 @@ def test_create_attributes_project
delete '/source/home:tom/_attribute/OBS:Maintained'
assert_response :success
delete '/source/home:tom/_attribute/OBS:Maintained'
assert_response 404
assert_response :not_found

# get old revision
# both ways need to work, first one for backward compatibility
Expand All @@ -432,21 +432,21 @@ def test_create_attributes_package

data = "<attributes><attribute namespace='OBS' name='Playground'/></attributes>"
post '/source/kde4/kdelibs/_attribute', params: data
assert_response 404
assert_response :not_found
assert_select 'status[code] > summary', /Attribute Type OBS:Playground does not exist/

data = "<attributes><attribute namespace='OBS' name='Maintained' >
<BROKENXML>
</attribute></attributes>"
post '/source/kde4/kdelibs/_attribute', params: data
assert_response 400
assert_response :bad_request
assert_select 'status[code] > summary', /Invalid XML/

data = "<attributes><attribute namespace='OBS' name='Maintained' >
<value>blah</value>
</attribute></attributes>"
post '/source/kde4/kdelibs/_attribute', params: data
assert_response 400
assert_response :bad_request
assert_select 'status[code] > summary', /has 1 values, but only 0 are allowed/

data = "<attributes><attribute namespace='OBS' name='Maintained'></attribute></attributes>"
Expand All @@ -471,30 +471,30 @@ def test_create_attributes_package
assert_equal({ 'attribute' => { 'name' => 'Maintained', 'namespace' => 'OBS', 'binary' => 'kdelibs-devel' } }, Xmlhash.parse(@response.body))

get '/source/kde4/NOT_EXISTING/_attribute'
assert_response 404
assert_response :not_found

# no permission check
login_Iggy
post '/source/kde4/kdelibs/_attribute', params: data
assert_response 403
assert_response :forbidden
post '/source/kde4/kdelibs/_attribute/OBS:Maintained', params: data
assert_response 403
assert_response :forbidden
post '/source/kde4/kdelibs/kdelibs-devel/_attribute/OBS:Maintained', params: data
assert_response 403
assert_response :forbidden
delete '/source/kde4/kdelibs/kdelibs-devel/_attribute/OBS:Maintained'
assert_response 403
assert_response :forbidden
get '/source/kde4/kdelibs/kdelibs-devel/_attribute/OBS:Maintained'
assert_response :success
delete '/source/kde4/kdelibs/_attribute/OBS:Maintained'
assert_response 403
assert_response :forbidden
get '/source/kde4/kdelibs/_attribute/OBS:Maintained'
assert_response :success

# invalid operations
delete '/source/kde4/kdelibs/kdelibs-devel/_attribute'
assert_response 404
assert_response :not_found
delete '/source/kde4/kdelibs/kdelibs-devel/_attribute/OBS_Maintained'
assert_response 400
assert_response :bad_request
assert_xml_tag tag: 'status', attributes: { code: 'invalid_attribute' }

# check history
Expand Down

0 comments on commit bafa4e3

Please sign in to comment.