Fix Rubocop Security/Open (#1447)

* Re-run rubocop autogen config

* Fix Layout/* violations

* Fix Security/Open and use HEAD if GET is not needed
This commit is contained in:
rhymes 2019-01-02 22:35:19 +01:00 committed by Mac Siri
parent b48e573c31
commit dbf5fc63ad
5 changed files with 413 additions and 914 deletions

View file

@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-12-29 20:55:12 +0100 using RuboCop version 0.59.2.
# on 2019-01-02 20:59:45 +0100 using RuboCop version 0.59.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@ -27,12 +27,6 @@ RSpec/FilePath:
RSpec/MultipleExpectations:
Max: 6
# Offense count: 3
Security/Open:
Exclude:
- 'app/labor/podcast_feed.rb'
- 'app/labor/rss_reader.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
@ -87,7 +81,7 @@ Style/MixinUsage:
Exclude:
- 'app/models/podcast_episode.rb'
# Offense count: 1179
# Offense count: 1180
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:

View file

@ -1,6 +1,5 @@
require "rss"
require "rss/itunes"
require "open-uri"
class PodcastFeed
def get_all_episodes
@ -10,7 +9,7 @@ class PodcastFeed
end
def get_episodes(podcast, num = 1000)
rss = open(podcast.feed_url).read
rss = HTTParty.get(podcast.feed_url).body
feed = RSS::Parser.parse(rss, false)
feed.items.first(num).each do |item|
if !existing_episode(item, podcast)
@ -65,7 +64,7 @@ class PodcastFeed
def get_media_url(episode, item, podcast)
episode.media_url = if Rails.env.test? ||
open(item.enclosure.url.gsub(/http:/, "https:")).status[0] == "200"
HTTParty.head(item.enclosure.url.gsub(/http:/, "https:")).code == 200
item.enclosure.url.gsub(/http:/, "https:")
else
item.enclosure.url

View file

@ -161,10 +161,7 @@ class RssReader
possible_link = a_tag[0].inner_html
if /medium\.com\/media\/.+\/href/.match?(possible_link)
real_link = ""
open(possible_link) do |h|
real_link = h.base_uri.to_s
end
real_link = HTTParty.head(possible_link).request.last_uri.to_s
return unless real_link.include?("gist.github.com")
iframe.name = "p"

View file

@ -17,10 +17,11 @@ class UserRoleService
def update_tag_moderators(user_ids, tag)
users = user_ids.map do |id|
User.find(id)
rescue ActiveRecord::RecordNotFound
rescue ActiveRecord::RecordNotFound # rubocop:disable Layout/RescueEnsureAlignment
tag.errors[:moderator_ids] << ": user id #{id} was not found"
end
return false if tag.errors[:moderator_ids].present?
# Don't have to worry about comparing old and new values.
tag.tag_moderator_ids.each do |id|
User.find(id).remove_role(:tag_moderator, tag)

File diff suppressed because one or more lines are too long