From 05d3d991d3e6e501e0f511599315ed8e6b197ff7 Mon Sep 17 00:00:00 2001 From: Matthew Albani Date: Wed, 17 Jan 2018 14:39:27 -0800 Subject: [PATCH 1/5] update rubocop to fix vuln CVE-2017-8418 --- .rubocop-bundler.yml | 12 +++++++++--- gemstash.gemspec | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.rubocop-bundler.yml b/.rubocop-bundler.yml index 0f180326..ac90d722 100644 --- a/.rubocop-bundler.yml +++ b/.rubocop-bundler.yml @@ -13,7 +13,7 @@ Lint/AssignmentInCondition: Enabled: false Lint/EndAlignment: - AlignWith: variable + EnforcedStyleAlignWith: variable Lint/UnusedMethodArgument: Enabled: false @@ -47,7 +47,10 @@ Style/StringLiteralsInInterpolation: # Having these make it easier to *not* forget to add one when adding a new # value and you can simply copy the previous line. -Style/TrailingComma: +Style/TrailingCommaInLiteral: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInArguments: EnforcedStyleForMultiline: comma # 1.8.7 support @@ -67,7 +70,10 @@ Style/EachWithObject: Style/SpecialGlobalVars: Enabled: false -Style/TrailingComma: +Style/TrailingCommaInArguments: + Enabled: false + +Style/TrailingCommaInLiteral: Enabled: false # Metrics diff --git a/gemstash.gemspec b/gemstash.gemspec index d2222ed3..8cc15d63 100644 --- a/gemstash.gemspec +++ b/gemstash.gemspec @@ -57,5 +57,5 @@ you push your own private gems as well." spec.add_development_dependency "rack-test", "~> 0.6" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.3" - spec.add_development_dependency "rubocop", "0.35.1" + spec.add_development_dependency "rubocop", "0.49" end From 4b354635d8c9f6d230b7e42caf7e682469101f68 Mon Sep 17 00:00:00 2001 From: Matthew Albani Date: Wed, 17 Jan 2018 15:09:57 -0800 Subject: [PATCH 2/5] rubocop fixes autofix Style/PercentLiteralDelimiters add MarshalLoad, BlockLenth, LineLength to disabled list set variable number to snake_case add DuplicateGem and GlovalVar exeptions for spec tests autofix the rest that rubocop would do Manually fix the remaning issues --- .rubocop-bundler.yml | 37 ++++++++++++++++--- Rakefile | 2 +- gemstash.gemspec | 1 + lib/gemstash/authorization.rb | 2 +- lib/gemstash/cli.rb | 6 +-- lib/gemstash/cli/authorize.rb | 6 ++- lib/gemstash/cli/base.rb | 9 +++-- lib/gemstash/cli/setup.rb | 4 +- lib/gemstash/cli/status.rb | 2 +- lib/gemstash/cli/stop.rb | 2 +- lib/gemstash/configuration.rb | 2 +- lib/gemstash/logging.rb | 6 +-- .../migrations/01_gem_dependencies.rb | 4 +- lib/gemstash/migrations/03_cached_gems.rb | 2 +- rake/doc/fix_github_line_breaks.rb | 6 +-- rake/doc/insert_github_generation_comment.rb | 2 +- rake/doc/insert_images.rb | 6 +-- rakelib/changelog.rake | 6 +-- rakelib/doc.rake | 16 ++++---- spec/concurrency_spec.rb | 28 +++++++------- spec/data/gems/example/Rakefile | 6 +-- spec/data/gems/example/example.gemspec | 1 + spec/data/gems/speaker/Rakefile | 16 ++++---- spec/data/gems/speaker/speaker.gemspec | 1 + spec/gemstash/authorization_spec.rb | 14 +++---- spec/gemstash/cli/authorize_spec.rb | 6 +-- spec/gemstash/dependencies_spec.rb | 32 ++++++++-------- spec/gemstash/gem_pusher_spec.rb | 16 ++++---- spec/gemstash/gem_yanker_spec.rb | 24 ++++++------ spec/gemstash/upstream_spec.rb | 3 +- spec/gemstash/web_spec.rb | 4 +- spec/integration_spec.rb | 32 ++++++++-------- spec/support/db_helpers.rb | 15 +++++--- spec/support/test_gemstash_server.rb | 8 ++-- 34 files changed, 181 insertions(+), 146 deletions(-) diff --git a/.rubocop-bundler.yml b/.rubocop-bundler.yml index ac90d722..f664e18a 100644 --- a/.rubocop-bundler.yml +++ b/.rubocop-bundler.yml @@ -20,16 +20,16 @@ Lint/UnusedMethodArgument: # Style -Style/AccessModifierIndentation: +Layout/AccessModifierIndentation: EnforcedStyle: outdent -Style/AlignParameters: +Layout/AlignParameters: EnforcedStyle: with_fixed_indentation -Style/MultilineOperationIndentation: +Layout/MultilineOperationIndentation: EnforcedStyle: indented -Style/SpaceInsideBlockBraces: +Layout/SpaceInsideBlockBraces: SpaceBeforeBlockParameters: false Style/TrivialAccessors: @@ -61,7 +61,7 @@ Style/HashSyntax: Style/Lambda: Enabled: false -Style/DotPosition: +Layout/DotPosition: EnforcedStyle: trailing Style/EachWithObject: @@ -76,6 +76,13 @@ Style/TrailingCommaInArguments: Style/TrailingCommaInLiteral: Enabled: false +Style/VariableNumber: + EnforcedStyle: 'snake_case' + +#alerts on some large if blocks +Style/GuardClause: + Enabled: false + # Metrics # We've chosen to use Rubocop only for style, and not for complexity or quality checks. @@ -99,3 +106,23 @@ Metrics/CyclomaticComplexity: Metrics/PerceivedComplexity: Enabled: false + +Metrics/BlockLength: + Enabled: false + +Metrics/LineLength: + Enabled: false + +#Security + +Security/MarshalLoad: + Enabled: false + +#Ignore certain test cases +Bundler/DuplicatedGem: + Exclude: + - spec/data/bundles/**/Gemfile + +Style/GlobalVars: + Exclude: + - spec/support/test_gemstash_server.ru diff --git a/Rakefile b/Rakefile index daa4e139..df6c3d06 100644 --- a/Rakefile +++ b/Rakefile @@ -6,7 +6,7 @@ RuboCop::RakeTask.new desc "Run specs" RSpec::Core::RakeTask.new(:spec) do |t| - t.rspec_opts = %w(--color) + t.rspec_opts = %w[--color] end task spec: :rubocop diff --git a/gemstash.gemspec b/gemstash.gemspec index 8cc15d63..832a5398 100644 --- a/gemstash.gemspec +++ b/gemstash.gemspec @@ -1,4 +1,5 @@ # coding: utf-8 + lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "gemstash/version" diff --git a/lib/gemstash/authorization.rb b/lib/gemstash/authorization.rb index 8dfca240..37f13fb8 100644 --- a/lib/gemstash/authorization.rb +++ b/lib/gemstash/authorization.rb @@ -9,7 +9,7 @@ class NotAuthorizedError < StandardError class Authorization extend Gemstash::Env::Helper extend Gemstash::Logging - VALID_PERMISSIONS = %w(push yank fetch).freeze + VALID_PERMISSIONS = %w[push yank fetch].freeze def self.authorize(auth_key, permissions) raise "Authorization key is required!" if auth_key.to_s.strip.empty? diff --git a/lib/gemstash/cli.rb b/lib/gemstash/cli.rb index be24b316..ed5b572e 100644 --- a/lib/gemstash/cli.rb +++ b/lib/gemstash/cli.rb @@ -24,10 +24,10 @@ def self.exit_on_failure? end def self.start(args = ARGV) - help_flags = %w(-h --help) + help_flags = %w[-h --help] if args.any? {|a| help_flags.include?(a) } - super(%w(help) + args.reject {|a| help_flags.include?(a) }) + super(%w[help] + args.reject {|a| help_flags.include?(a) }) else super end @@ -95,7 +95,7 @@ def stop def version say "Gemstash version #{Gemstash::VERSION}" end - map %w(-v --version) => :version + map %w[-v --version] => :version private diff --git a/lib/gemstash/cli/authorize.rb b/lib/gemstash/cli/authorize.rb index 711a4db0..c011269f 100644 --- a/lib/gemstash/cli/authorize.rb +++ b/lib/gemstash/cli/authorize.rb @@ -24,8 +24,10 @@ def setup_logging end def remove_authorization - raise Gemstash::CLI::Error.new(@cli, "To remove individual permissions, you do not need --remove -Instead just authorize with the new set of permissions") unless @args.empty? + unless @args.empty? + raise Gemstash::CLI::Error.new(@cli, "To remove individual permissions, you do not need --remove +Instead just authorize with the new set of permissions") + end Gemstash::Authorization.remove(auth_key(false)) end diff --git a/lib/gemstash/cli/base.rb b/lib/gemstash/cli/base.rb index 4cb987ba..76a97cdb 100644 --- a/lib/gemstash/cli/base.rb +++ b/lib/gemstash/cli/base.rb @@ -21,10 +21,11 @@ def prepare end def check_rubygems_version - @cli.say(@cli.set_color("Rubygems version is too old, " \ - "please update rubygems by running: " \ - "gem update --system", :red)) unless - Gem::Requirement.new(">= 2.4").satisfied_by?(Gem::Version.new(Gem::VERSION)) + unless Gem::Requirement.new(">= 2.4").satisfied_by?(Gem::Version.new(Gem::VERSION)) + @cli.say(@cli.set_color("Rubygems version is too old, " \ + "please update rubygems by running: " \ + "gem update --system", :red)) + end end def store_config diff --git a/lib/gemstash/cli/setup.rb b/lib/gemstash/cli/setup.rb index 37acba91..bc4e0168 100644 --- a/lib/gemstash/cli/setup.rb +++ b/lib/gemstash/cli/setup.rb @@ -72,7 +72,7 @@ def ask_storage def ask_cache say_current_config(:cache_type, "Current cache") - @config[:cache_type] = ask_with_default("Cache with what?", %w(memory memcached), "memory") + @config[:cache_type] = ask_with_default("Cache with what?", %w[memory memcached], "memory") ask_memcached_details if @config[:cache_type] == "memcached" end @@ -85,7 +85,7 @@ def ask_memcached_details def ask_database say_current_config(:db_adapter, "Current database adapter") - @config[:db_adapter] = ask_with_default("What database adapter?", %w(sqlite3 postgres mysql mysql2), "sqlite3") + @config[:db_adapter] = ask_with_default("What database adapter?", %w[sqlite3 postgres mysql mysql2], "sqlite3") ask_database_details(@config[:db_adapter]) unless @config[:db_adapter] == "sqlite3" end diff --git a/lib/gemstash/cli/status.rb b/lib/gemstash/cli/status.rb index 1234a20b..9df6d87f 100644 --- a/lib/gemstash/cli/status.rb +++ b/lib/gemstash/cli/status.rb @@ -14,7 +14,7 @@ def run private def args - pidfile_args + %w(status) + pidfile_args + %w[status] end end end diff --git a/lib/gemstash/cli/stop.rb b/lib/gemstash/cli/stop.rb index 7277b3d9..88a6d909 100644 --- a/lib/gemstash/cli/stop.rb +++ b/lib/gemstash/cli/stop.rb @@ -15,7 +15,7 @@ def run private def args - pidfile_args + %w(stop) + pidfile_args + %w[stop] end end end diff --git a/lib/gemstash/configuration.rb b/lib/gemstash/configuration.rb index 9e2d94ae..c0926f8d 100644 --- a/lib/gemstash/configuration.rb +++ b/lib/gemstash/configuration.rb @@ -73,7 +73,7 @@ def default_file def parse_config(file) if file.end_with?(".erb") - YAML.load(ERB.new(File.read(file)).result) || {} + YAML.safe_load(ERB.new(File.read(file)).result) || {} else YAML.load_file(file) || {} end diff --git a/lib/gemstash/logging.rb b/lib/gemstash/logging.rb index 7962856e..8400dc9b 100644 --- a/lib/gemstash/logging.rb +++ b/lib/gemstash/logging.rb @@ -75,11 +75,9 @@ def initialize(level) @level = level end - def flush - end + def flush; end - def sync=(_value) - end + def sync=(_value); end def write(message) Gemstash::Logging.logger.add(@level, message) diff --git a/lib/gemstash/migrations/01_gem_dependencies.rb b/lib/gemstash/migrations/01_gem_dependencies.rb index 51fc98eb..b4f3a708 100644 --- a/lib/gemstash/migrations/01_gem_dependencies.rb +++ b/lib/gemstash/migrations/01_gem_dependencies.rb @@ -19,9 +19,9 @@ TrueClass :prerelease, :null => false DateTime :created_at, :null => false DateTime :updated_at, :null => false - index [:rubygem_id, :number, :platform], :unique => true + index %i[rubygem_id number platform], :unique => true index [:indexed] - index [:indexed, :prerelease] + index %i[indexed prerelease] index [:number] index [:full_name], :unique => true index [:storage_id], :unique => true diff --git a/lib/gemstash/migrations/03_cached_gems.rb b/lib/gemstash/migrations/03_cached_gems.rb index f51d3fb6..5e61539e 100644 --- a/lib/gemstash/migrations/03_cached_gems.rb +++ b/lib/gemstash/migrations/03_cached_gems.rb @@ -17,7 +17,7 @@ String :resource_type, size: 191, null: false DateTime :created_at, null: false DateTime :updated_at, null: false - index [:upstream_id, :resource_type, :name], unique: true + index %i[upstream_id resource_type name], unique: true index [:name] end end diff --git a/rake/doc/fix_github_line_breaks.rb b/rake/doc/fix_github_line_breaks.rb index 05a03fbb..afb3aea1 100755 --- a/rake/doc/fix_github_line_breaks.rb +++ b/rake/doc/fix_github_line_breaks.rb @@ -7,8 +7,8 @@ # formatted properly. # First test that the problem still exists -PANDOC_MD_INPUT = "Multiple lines\\\nwith explicit\\\nline breaks" -INVALID_EXPECTED_MD_OUTPUT = "Multiple lines\nwith explicit\nline breaks\n" +PANDOC_MD_INPUT = "Multiple lines\\\nwith explicit\\\nline breaks".freeze +INVALID_EXPECTED_MD_OUTPUT = "Multiple lines\nwith explicit\nline breaks\n".freeze pandoc_results = nil @@ -35,7 +35,7 @@ element.elements.each_with_index do |e, i| next unless e.is_a?(PandocObjectFilters::Element::LineBreak) - if i == 0 + if i.zero? STDERR.puts "[#{File.basename(__FILE__)}][WARNING] Found line break at the beginning of a block!" next end diff --git a/rake/doc/insert_github_generation_comment.rb b/rake/doc/insert_github_generation_comment.rb index 797cb562..a1e2692a 100755 --- a/rake/doc/insert_github_generation_comment.rb +++ b/rake/doc/insert_github_generation_comment.rb @@ -3,7 +3,7 @@ require "open3" require "pandoc_object_filters" -COMMENT = %() +COMMENT = %().freeze def github_comment pandoc_results = nil diff --git a/rake/doc/insert_images.rb b/rake/doc/insert_images.rb index 8f883bc5..cad35d8f 100755 --- a/rake/doc/insert_images.rb +++ b/rake/doc/insert_images.rb @@ -3,7 +3,7 @@ require "open3" require "pandoc_object_filters" -HTML_IMAGES = %(

) +HTML_IMAGES = %(

).freeze GITHUB_IMAGES = %([![Build Status][TRAVIS_IMG]][TRAVIS] [![Code Climate][CODE_CLIMATE_IMG]][CODE_CLIMATE] [TRAVIS_IMG]: https://travis-ci.org/bundler/gemstash.svg?branch=master @@ -11,7 +11,7 @@ [CODE_CLIMATE_IMG]: https://codeclimate.com/github/bundler/gemstash/badges/gpa.svg [CODE_CLIMATE]: https://codeclimate.com/github/bundler/gemstash -

) +

).freeze def images_json(markdown) pandoc_results = nil @@ -41,7 +41,7 @@ def images_json(markdown) filter.filter! do |element| next if found - next unless %w(html markdown_github).include?(filter.format) + next unless %w[html markdown_github].include?(filter.format) next unless filter.doc.meta["insert_images"] && filter.doc.meta["insert_images"].value next unless element.is_a?(PandocObjectFilters::Element::Header) next unless element.elements.first.is_a?(PandocObjectFilters::Element::Str) diff --git a/rakelib/changelog.rake b/rakelib/changelog.rake index e4096cc7..3c102734 100644 --- a/rakelib/changelog.rake +++ b/rakelib/changelog.rake @@ -22,7 +22,7 @@ class Changelog tags = `git tag -l` return unless tags.include? Changelog.current_version print "Are you updating the 'master' CHANGELOG? [yes/no] " - abort("Please update lib/gemstash/version.rb with the new version first!") unless STDIN.gets.strip.casecmp("yes") == 0 + abort("Please update lib/gemstash/version.rb with the new version first!") unless STDIN.gets.strip.casecmp("yes").zero? @master_update = true end @@ -85,7 +85,7 @@ class Changelog puts "And store it at: #{token_path}" puts "Otherwise you might hit rate limits while running this" print "Continue without token? [yes/no] " - abort("Please create your token and retry") unless STDIN.gets.strip.casecmp("yes") == 0 + abort("Please create your token and retry") unless STDIN.gets.strip.casecmp("yes").zero? options = {} end @@ -248,7 +248,7 @@ class Changelog def fetch_all_pull_requests puts "Fetching all pull requests" @pull_requests = octokit.pull_requests("bundler/gemstash", state: "all"). - sort_by(&:number).map {|pr| PullRequest.new(pr) } + sort_by(&:number).map {|pr| PullRequest.new(pr) } end def reject_documented_pull_requests diff --git a/rakelib/doc.rake b/rakelib/doc.rake index 01044edd..8c427b6c 100644 --- a/rakelib/doc.rake +++ b/rakelib/doc.rake @@ -52,10 +52,10 @@ class Doc end def export_to_github - if base_file == "gemstash-readme.7.md" - path = doc.root_dir.join("README.md") + path = if base_file == "gemstash-readme.7.md" + doc.root_dir.join("README.md") else - path = to_extension(".md") + to_extension(".md") end export "markdown_github", export_path("docs", path) @@ -73,21 +73,21 @@ class Doc end def export_to_html - if base_file == "gemstash-readme.7.md" - path = "index.html" + path = if base_file == "gemstash-readme.7.md" + "index.html" else - path = to_extension(".html") + to_extension(".html") end export "html", export_path("html", path) end def filters - %w(insert_github_generation_comment.rb + %w[insert_github_generation_comment.rb insert_images.rb upcase_headers.rb fix_links_for_format.rb - fix_github_line_breaks.rb).map do |filter| + fix_github_line_breaks.rb].map do |filter| ::File.expand_path("../../rake/doc/#{filter}", __FILE__) end end diff --git a/spec/concurrency_spec.rb b/spec/concurrency_spec.rb index d40875c4..27def448 100644 --- a/spec/concurrency_spec.rb +++ b/spec/concurrency_spec.rb @@ -13,7 +13,7 @@ def write_thread(resource_id, content = "unchanging", &block) resource = storage.resource(resource_id.to_s) if block - block.call(resource) + yield(resource) else resource.save({ file: "Example content: #{content}" }, example: true, content: content) end @@ -31,7 +31,7 @@ def read_thread(resource_id, &block) if resource.exist?(:file) if block - block.call(resource) + yield(resource) else raise "Property mismatch" unless resource.properties[:example] raise "Property mismatch" unless resource.properties[:content] @@ -109,18 +109,18 @@ def check_for_errors_and_deadlocks(threads) ].freeze 50.times do - if rand(2) == 0 - threads << write_thread("large") do |resource| - large_content = possible_content[rand(possible_content.size)] - resource.save({ file: large_content }, example: true, content: large_content) - end - else - threads << read_thread("large") do |resource| - raise "Property mismatch" unless resource.properties[:example] - raise "Property mismatch" unless possible_content.include?(resource.properties[:content]) - raise "Content mismatch" unless possible_content.include?(resource.content(:file)) - end - end + threads << if rand(2) == 0 + write_thread("large") do |resource| + large_content = possible_content[rand(possible_content.size)] + resource.save({ file: large_content }, example: true, content: large_content) + end + else + read_thread("large") do |resource| + raise "Property mismatch" unless resource.properties[:example] + raise "Property mismatch" unless possible_content.include?(resource.properties[:content]) + raise "Content mismatch" unless possible_content.include?(resource.content(:file)) + end + end end check_for_errors_and_deadlocks(threads) diff --git a/spec/data/gems/example/Rakefile b/spec/data/gems/example/Rakefile index 5b6c3358..de8045a4 100644 --- a/spec/data/gems/example/Rakefile +++ b/spec/data/gems/example/Rakefile @@ -4,10 +4,10 @@ task :build do version = ENV["SPEC_VERSION"] version = "0.1.0" if version.to_s.empty? File.write(version_rb, <<-EOF) -#:nodoc: -module Example + #:nodoc: + module Example VERSION = "#{version}" -end + end EOF end diff --git a/spec/data/gems/example/example.gemspec b/spec/data/gems/example/example.gemspec index c39b1dfd..63b5ac54 100644 --- a/spec/data/gems/example/example.gemspec +++ b/spec/data/gems/example/example.gemspec @@ -1,4 +1,5 @@ # coding: utf-8 + version = ENV["SPEC_VERSION"] version = "0.1.0" if version.to_s.empty? diff --git a/spec/data/gems/speaker/Rakefile b/spec/data/gems/speaker/Rakefile index b1caba85..60c2553f 100644 --- a/spec/data/gems/speaker/Rakefile +++ b/spec/data/gems/speaker/Rakefile @@ -4,25 +4,25 @@ task :build do if RUBY_PLATFORM == "java" File.write(platform_rb, <<-EOF) -module Speaker + module Speaker #:nodoc: module Platform def self.name "Java" end end -end + end EOF else File.write(platform_rb, <<-EOF) -module Speaker + module Speaker #:nodoc: module Platform def self.name "Ruby" end end -end + end EOF end @@ -31,10 +31,10 @@ end version = ENV["SPEC_VERSION"] version = "0.1.0" if version.to_s.empty? File.write(version_rb, <<-EOF) -#:nodoc: -module Speaker - VERSION = "#{version}" -end + #:nodoc: + module Speaker + VERSION = "#{version}" + end EOF end diff --git a/spec/data/gems/speaker/speaker.gemspec b/spec/data/gems/speaker/speaker.gemspec index 8034ff2c..35ecadab 100644 --- a/spec/data/gems/speaker/speaker.gemspec +++ b/spec/data/gems/speaker/speaker.gemspec @@ -1,4 +1,5 @@ # coding: utf-8 + version = ENV["SPEC_VERSION"] version = "0.1.0" if version.to_s.empty? diff --git a/spec/gemstash/authorization_spec.rb b/spec/gemstash/authorization_spec.rb index 2a7567e6..3ac59a62 100644 --- a/spec/gemstash/authorization_spec.rb +++ b/spec/gemstash/authorization_spec.rb @@ -36,13 +36,13 @@ context "with invalid permissions" do it "raises an error" do expect { Gemstash::Authorization.authorize("abc", nil) }.to raise_error(RuntimeError) - expect { Gemstash::Authorization.authorize("abc", %w(invalid)) }.to raise_error(RuntimeError) + expect { Gemstash::Authorization.authorize("abc", %w[invalid]) }.to raise_error(RuntimeError) end end context "with 'all' permission along with other permissions" do it "raises an error" do - expect { Gemstash::Authorization.authorize("abc", %w(all yank)) }.to raise_error(RuntimeError) + expect { Gemstash::Authorization.authorize("abc", %w[all yank]) }.to raise_error(RuntimeError) end end @@ -59,7 +59,7 @@ Gemstash::Authorization.authorize("abc", "all") expect(Gemstash::Authorization["abc"].all?).to be_truthy expect(the_log).to include("Authorization 'abc' updated with access to 'all'") - Gemstash::Authorization.authorize("abc", %w(push yank)) + Gemstash::Authorization.authorize("abc", %w[push yank]) expect(Gemstash::Authorization["abc"].all?).to be_falsey expect(Gemstash::Authorization["abc"].push?).to be_truthy expect(Gemstash::Authorization["abc"].yank?).to be_truthy @@ -97,7 +97,7 @@ context "with an auth key without permission" do before do - Gemstash::Authorization.authorize("abc", %w(yank)) + Gemstash::Authorization.authorize("abc", %w[yank]) end it "raises a Gemstash::NotAuthorizedError" do @@ -108,7 +108,7 @@ context "with an auth key with permission" do before do - Gemstash::Authorization.authorize("abc", %w(push)) + Gemstash::Authorization.authorize("abc", %w[push]) end it "doesn't raise an error" do @@ -167,14 +167,14 @@ context "a mix of permissions" do it "has authorization for given auths" do - Gemstash::Authorization.authorize("abc", %w(push yank)) + Gemstash::Authorization.authorize("abc", %w[push yank]) auth = Gemstash::Authorization["abc"] expect(auth.all?).to be_falsey expect(auth.push?).to be_truthy expect(auth.yank?).to be_truthy expect(auth.fetch?).to be_falsey - Gemstash::Authorization.authorize("abc", %w(yank fetch)) + Gemstash::Authorization.authorize("abc", %w[yank fetch]) auth = Gemstash::Authorization["abc"] expect(auth.all?).to be_falsey expect(auth.push?).to be_falsey diff --git a/spec/gemstash/cli/authorize_spec.rb b/spec/gemstash/cli/authorize_spec.rb index 9a009497..1ccc8803 100644 --- a/spec/gemstash/cli/authorize_spec.rb +++ b/spec/gemstash/cli/authorize_spec.rb @@ -91,7 +91,7 @@ let(:cli_options) { { :key => "auth-key" } } before do - Gemstash::Authorization.authorize("auth-key", %w(yank)) + Gemstash::Authorization.authorize("auth-key", %w[yank]) end it "updates the permissions" do @@ -107,7 +107,7 @@ let(:cli_options) { { :key => "auth-key", :remove => true } } before do - Gemstash::Authorization.authorize("auth-key", %w(yank)) + Gemstash::Authorization.authorize("auth-key", %w[yank]) end it "removes the authorization" do @@ -130,7 +130,7 @@ let(:cli_options) { { :key => "auth-key", :remove => true } } before do - Gemstash::Authorization.authorize("auth-key", %w(yank)) + Gemstash::Authorization.authorize("auth-key", %w[yank]) end it "gives the user an error" do diff --git a/spec/gemstash/dependencies_spec.rb b/spec/gemstash/dependencies_spec.rb index 204ed1f1..3da1543d 100644 --- a/spec/gemstash/dependencies_spec.rb +++ b/spec/gemstash/dependencies_spec.rb @@ -23,11 +23,11 @@ def valid_url(url, expected_gems) }] expect(http_client).to receive(:get) {|url| - valid_url(url, %w(foo)) + valid_url(url, %w[foo]) Marshal.dump(result) } - expect(web_deps.fetch(%w(foo))).to eq(result) + expect(web_deps.fetch(%w[foo])).to eq(result) end end @@ -46,11 +46,11 @@ def valid_url(url, expected_gems) }] expect(http_client).to receive(:get) {|url| - valid_url(url, %w(foo bar)) + valid_url(url, %w[foo bar]) Marshal.dump(result) } - expect(web_deps.fetch(%w(foo bar))).to match_dependencies(result) + expect(web_deps.fetch(%w[foo bar])).to match_dependencies(result) end end @@ -69,11 +69,11 @@ def valid_url(url, expected_gems) }] expect(http_client).to receive(:get) {|url| - valid_url(url, %w(foo bar baz)) + valid_url(url, %w[foo bar baz]) Marshal.dump(result) } - expect(web_deps.fetch(%w(foo bar baz))).to match_dependencies(result) + expect(web_deps.fetch(%w[foo bar baz])).to match_dependencies(result) end end @@ -94,15 +94,15 @@ def valid_url(url, expected_gems) } expect(http_client).to receive(:get) {|url| - valid_url(url, %w(foo bar baz)) + valid_url(url, %w[foo bar baz]) Marshal.dump([foo, bar]) }.once - expect(web_deps.fetch(%w(foo bar baz))).to match_dependencies([foo, bar]) - expect(web_deps.fetch(%w(baz foo bar))).to match_dependencies([foo, bar]) - expect(web_deps.fetch(%w(foo))).to match_dependencies([foo]) - expect(web_deps.fetch(%w(bar))).to match_dependencies([bar]) - expect(web_deps.fetch(%w(baz))).to match_dependencies([]) + expect(web_deps.fetch(%w[foo bar baz])).to match_dependencies([foo, bar]) + expect(web_deps.fetch(%w[baz foo bar])).to match_dependencies([foo, bar]) + expect(web_deps.fetch(%w[foo])).to match_dependencies([foo]) + expect(web_deps.fetch(%w[bar])).to match_dependencies([bar]) + expect(web_deps.fetch(%w[baz])).to match_dependencies([]) end end @@ -121,7 +121,7 @@ def valid_url(url, expected_gems) :dependencies => [["foo", "~> 1.0"]] } - expect(db_deps.fetch(%w(foo bar baz custom))).to match_dependencies([custom]) + expect(db_deps.fetch(%w[foo bar baz custom])).to match_dependencies([custom]) end end @@ -157,15 +157,15 @@ def dependency_item(results, name, number) :dependencies => [["foo", "~> 1.1"]] } - custom2 = { + custom_2 = { :name => "custom2", :number => "0.2.0", :platform => "ruby", :dependencies => [] } - expect(db_deps.fetch(%w(custom1 custom2))). - to match_dependencies([custom1_0_0_1, custom1_0_2_1, custom2]) + expect(db_deps.fetch(%w[custom1 custom2])). + to match_dependencies([custom1_0_0_1, custom1_0_2_1, custom_2]) end end end diff --git a/spec/gemstash/gem_pusher_spec.rb b/spec/gemstash/gem_pusher_spec.rb index c09506c3..f28fb558 100644 --- a/spec/gemstash/gem_pusher_spec.rb +++ b/spec/gemstash/gem_pusher_spec.rb @@ -25,7 +25,7 @@ to raise_error(Gemstash::NotAuthorizedError) expect { Gemstash::GemPusher.new(Gemstash::ApiKeyAuthorization.new(""), gem_contents).serve }. to raise_error(Gemstash::NotAuthorizedError) - expect(deps.fetch(%w(example))).to eq([]) + expect(deps.fetch(%w[example])).to eq([]) end end @@ -33,7 +33,7 @@ it "prevents pushing" do expect { Gemstash::GemPusher.new(auth_with_invalid_auth_key, gem_contents).serve }. to raise_error(Gemstash::NotAuthorizedError) - expect(deps.fetch(%w(example))).to eq([]) + expect(deps.fetch(%w[example])).to eq([]) end end @@ -41,7 +41,7 @@ it "prevents pushing" do expect { Gemstash::GemPusher.new(auth_without_permission, gem_contents).serve }. to raise_error(Gemstash::NotAuthorizedError) - expect(deps.fetch(%w(example))).to eq([]) + expect(deps.fetch(%w[example])).to eq([]) end end @@ -56,9 +56,9 @@ }] # Fetch before, asserting cache will be invalidated - expect(deps.fetch(%w(example))).to eq([]) + expect(deps.fetch(%w[example])).to eq([]) Gemstash::GemPusher.new(auth, gem_contents).serve - expect(deps.fetch(%w(example))).to match_dependencies(results) + expect(deps.fetch(%w[example])).to match_dependencies(results) expect(storage.resource("example-0.1.0").content(:gem)).to eq(gem_contents) end @@ -86,9 +86,9 @@ }] # Fetch before, asserting cache will be invalidated - expect(deps.fetch(%w(example))).to eq([]) + expect(deps.fetch(%w[example])).to eq([]) Gemstash::GemPusher.new(auth, gem_contents).serve - expect(deps.fetch(%w(example))).to match_dependencies(results) + expect(deps.fetch(%w[example])).to match_dependencies(results) expect(storage.resource("example-0.1.0-java").content(:gem)).to eq(gem_contents) end @@ -125,7 +125,7 @@ }] Gemstash::GemPusher.new(auth, gem_contents).serve - expect(deps.fetch(%w(example))).to match_dependencies(results) + expect(deps.fetch(%w[example])).to match_dependencies(results) expect(storage.resource("example-0.1.0").content(:gem)).to eq(gem_contents) end diff --git a/spec/gemstash/gem_yanker_spec.rb b/spec/gemstash/gem_yanker_spec.rb index 65227920..7c7aff98 100644 --- a/spec/gemstash/gem_yanker_spec.rb +++ b/spec/gemstash/gem_yanker_spec.rb @@ -36,7 +36,7 @@ to raise_error(Gemstash::NotAuthorizedError) expect { Gemstash::GemYanker.new(Gemstash::ApiKeyAuthorization.new(""), gem_name, gem_slug).serve }. to raise_error(Gemstash::NotAuthorizedError) - expect(deps.fetch(%w(example))).to eq([gem_dependencies]) + expect(deps.fetch(%w[example])).to eq([gem_dependencies]) end end @@ -44,7 +44,7 @@ it "prevents yanking" do expect { Gemstash::GemYanker.new(auth_with_invalid_auth_key, gem_name, gem_slug).serve }. to raise_error(Gemstash::NotAuthorizedError) - expect(deps.fetch(%w(example))).to eq([gem_dependencies]) + expect(deps.fetch(%w[example])).to eq([gem_dependencies]) end end @@ -52,7 +52,7 @@ it "prevents yanking" do expect { Gemstash::GemYanker.new(auth_without_permission, gem_name, gem_slug).serve }. to raise_error(Gemstash::NotAuthorizedError) - expect(deps.fetch(%w(example))).to eq([gem_dependencies]) + expect(deps.fetch(%w[example])).to eq([gem_dependencies]) end end @@ -67,7 +67,7 @@ it "rejects the yank" do expect { Gemstash::GemYanker.new(auth, gem_name, "0.4.2-ruby").serve }. to raise_error(Gemstash::GemYanker::UnknownVersionError) - expect(deps.fetch(%w(example))).to eq([gem_dependencies]) + expect(deps.fetch(%w[example])).to eq([gem_dependencies]) end end @@ -81,7 +81,7 @@ it "rejects the yank" do expect { Gemstash::GemYanker.new(auth, gem_name, "0.4.2-ruby").serve }. to raise_error(Gemstash::GemYanker::YankedVersionError) - expect(deps.fetch(%w(example))).to eq([gem_dependencies]) + expect(deps.fetch(%w[example])).to eq([gem_dependencies]) end end @@ -90,9 +90,9 @@ it "yanks the gem" do # Fetch before, asserting cache will be invalidated - expect(deps.fetch(%w(example))).to eq([gem_dependencies]) + expect(deps.fetch(%w[example])).to eq([gem_dependencies]) Gemstash::GemYanker.new(auth, gem_name, gem_slug).serve - expect(deps.fetch(%w(example))).to eq([]) + expect(deps.fetch(%w[example])).to eq([]) # It doesn't actually delete expect(storage.resource("#{gem_name}-#{gem_version}").content(:gem)).to eq(gem_contents) end @@ -100,9 +100,9 @@ context "with an implicit platform" do it "yanks the gem" do - expect(deps.fetch(%w(example))).to eq([gem_dependencies]) + expect(deps.fetch(%w[example])).to eq([gem_dependencies]) Gemstash::GemYanker.new(auth, gem_name, gem_version).serve - expect(deps.fetch(%w(example))).to eq([]) + expect(deps.fetch(%w[example])).to eq([]) end end @@ -124,7 +124,7 @@ it "yanks just the specified gem version" do Gemstash::GemYanker.new(auth, gem_name, gem_slug).serve - expect(deps.fetch(%w(example))).to eq([alternate_deps]) + expect(deps.fetch(%w[example])).to eq([alternate_deps]) end end @@ -146,7 +146,7 @@ it "yanks just the specified gem version" do Gemstash::GemYanker.new(auth, gem_name, gem_slug).serve - expect(deps.fetch(%w(example))).to eq([alternate_deps]) + expect(deps.fetch(%w[example])).to eq([alternate_deps]) end end @@ -159,7 +159,7 @@ it "yanks just the specified gem version" do Gemstash::GemYanker.new(auth, gem_name, "0.1.0-java").serve - expect(deps.fetch(%w(example))).to eq([gem_dependencies]) + expect(deps.fetch(%w[example])).to eq([gem_dependencies]) end end end diff --git a/spec/gemstash/upstream_spec.rb b/spec/gemstash/upstream_spec.rb index 3f261b23..b9b963e9 100644 --- a/spec/gemstash/upstream_spec.rb +++ b/spec/gemstash/upstream_spec.rb @@ -47,7 +47,8 @@ it "fails if the uri is not valid" do expect { Gemstash::Upstream.new("something_that_is_not_an_uri") }.to raise_error( - /URL 'something_that_is_not_an_uri' is not valid/) + /URL 'something_that_is_not_an_uri' is not valid/ + ) end it "has a nil user agent if not provided" do diff --git a/spec/gemstash/web_spec.rb b/spec/gemstash/web_spec.rb index bcbfa4d6..3de443ed 100644 --- a/spec/gemstash/web_spec.rb +++ b/spec/gemstash/web_spec.rb @@ -131,7 +131,7 @@ def for(server_url, timeout = 20) end context "there are too many gems" do - let(:gems) { 201.times.map {|i| "gem-#{i}" }.join(",") } + let(:gems) { Array.new(201) {|i| "gem-#{i}" }.join(",") } it "returns a 422" do get "#{request}?gems=#{gems}", {}, rack_env @@ -185,7 +185,7 @@ def for(server_url, timeout = 20) end context "there are too many gems" do - let(:gems) { 201.times.map {|i| "gem-#{i}" }.join(",") } + let(:gems) { Array.new(201) {|i| "gem-#{i}" }.join(",") } it "returns a 422" do error = { diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index c3aec0f9..ef00b74f 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -105,7 +105,7 @@ end before do - FileUtils.chmod(0600, File.join(env_dir, ".gem/credentials")) + FileUtils.chmod(0o600, File.join(env_dir, ".gem/credentials")) Gemstash::Authorization.authorize(auth_key, "all") end @@ -116,7 +116,7 @@ context "pushing a gem" do before do - expect(deps.fetch(%w(speaker))).to match_dependencies([]) + expect(deps.fetch(%w[speaker])).to match_dependencies([]) expect { storage.resource("speaker-0.1.0").content(:gem) }.to raise_error(RuntimeError) @gemstash.env.cache.flush end @@ -124,7 +124,7 @@ it "pushes valid gems to the server", db_transaction: false do env = { "HOME" => env_dir } expect(execute("gem", ["push", "--key", "test", "--host", host, gem], env: env)).to exit_success - expect(deps.fetch(%w(speaker))).to match_dependencies([speaker_deps]) + expect(deps.fetch(%w[speaker])).to match_dependencies([speaker_deps]) expect(storage.resource("speaker-0.1.0").content(:gem)).to eq(gem_contents) expect(http_client.get("gems/speaker-0.1.0")).to eq(gem_contents) end @@ -133,7 +133,7 @@ context "searching for a gem" do before do Gemstash::GemPusher.new(auth, gem_contents).serve - expect(deps.fetch(%w(speaker))).to match_dependencies([speaker_deps]) + expect(deps.fetch(%w[speaker])).to match_dependencies([speaker_deps]) @gemstash.env.cache.flush end @@ -170,14 +170,14 @@ context "yanking a gem" do before do Gemstash::GemPusher.new(auth, gem_contents).serve - expect(deps.fetch(%w(speaker))).to match_dependencies([speaker_deps]) + expect(deps.fetch(%w[speaker])).to match_dependencies([speaker_deps]) @gemstash.env.cache.flush end it "removes valid gems from the server", db_transaction: false do env = { "HOME" => env_dir, "RUBYGEMS_HOST" => host } expect(execute("gem", ["yank", "--key", "test", gem_name, "--version", gem_version], env: env)).to exit_success - expect(deps.fetch(%w(speaker))).to match_dependencies([]) + expect(deps.fetch(%w[speaker])).to match_dependencies([]) expect { http_client.get("gems/speaker-0.1.0") }.to raise_error(Gemstash::WebError) end end @@ -193,7 +193,7 @@ before do Gemstash::GemPusher.new(auth, gem_contents).serve - expect(deps.fetch(%w(speaker))).to match_dependencies([speaker_deps]) + expect(deps.fetch(%w[speaker])).to match_dependencies([speaker_deps]) @gemstash.env.cache.flush end @@ -201,7 +201,7 @@ env = { "HOME" => env_dir, "RUBYGEMS_HOST" => host, "GEM_HOME" => env_dir, "GEM_PATH" => env_dir } expect(execute("gem", ["install", "speaker", "--clear-sources", "--source", host], dir: env_dir, env: env)). to exit_success - expect(execute(File.join(env_dir, "bin/speaker"), %w(hi), dir: env_dir, env: env)). + expect(execute(File.join(env_dir, "bin/speaker"), %w[hi], dir: env_dir, env: env)). to exit_success.and_output("Hello world, #{platform_message}\n") end end @@ -218,28 +218,28 @@ it "successfully bundles" do env = { "HOME" => dir } expect(execute("bundle", dir: dir, env: env)).to exit_success - expect(execute("bundle", %w(exec speaker hi), dir: dir, env: env)). + expect(execute("bundle", %w[exec speaker hi], dir: dir, env: env)). to exit_success.and_output("Hello world, #{platform_message}\n") end it "can bundle with full index" do env = { "HOME" => dir } - expect(execute("bundle", %w(--full-index), dir: dir, env: env)).to exit_success - expect(execute("bundle", %w(exec speaker hi), dir: dir, env: env)). + expect(execute("bundle", %w[--full-index], dir: dir, env: env)).to exit_success + expect(execute("bundle", %w[exec speaker hi], dir: dir, env: env)). to exit_success.and_output("Hello world, #{platform_message}\n") end it "can bundle with prerelease versions" do env = { "HOME" => dir, "SPEAKER_VERSION" => "= 0.2.0.pre" } expect(execute("bundle", dir: dir, env: env)).to exit_success - expect(execute("bundle", %w(exec speaker hi), dir: dir, env: env)). + expect(execute("bundle", %w[exec speaker hi], dir: dir, env: env)). to exit_success.and_output("Hello world, pre, #{platform_message}\n") end it "can bundle with prerelease versions with full index" do env = { "HOME" => dir, "SPEAKER_VERSION" => "= 0.2.0.pre" } - expect(execute("bundle", %w(--full-index), dir: dir, env: env)).to exit_success - expect(execute("bundle", %w(exec speaker hi), dir: dir, env: env)). + expect(execute("bundle", %w[--full-index], dir: dir, env: env)).to exit_success + expect(execute("bundle", %w[exec speaker hi], dir: dir, env: env)). to exit_success.and_output("Hello world, pre, #{platform_message}\n") end end @@ -262,13 +262,13 @@ it "can successfully bundle twice" do env = { "HOME" => dir } expect(execute("bundle", dir: dir, env: env)).to exit_success - expect(execute("bundle", %w(exec speaker hi), dir: dir, env: env)). + expect(execute("bundle", %w[exec speaker hi], dir: dir, env: env)). to exit_success.and_output("Hello world, #{platform_message}\n") clean_bundle bundle expect(execute("bundle", dir: dir, env: env)).to exit_success - expect(execute("bundle", %w(exec speaker hi), dir: dir, env: env)). + expect(execute("bundle", %w[exec speaker hi], dir: dir, env: env)). to exit_success.and_output("Hello world, #{platform_message}\n") end end diff --git a/spec/support/db_helpers.rb b/spec/support/db_helpers.rb index 02b0a1dc..212dcf3a 100644 --- a/spec/support/db_helpers.rb +++ b/spec/support/db_helpers.rb @@ -8,16 +8,17 @@ def insert_rubygem(name) Gemstash::Env.current.db[:rubygems].insert( :name => name, :created_at => Sequel::SQL::Constants::CURRENT_TIMESTAMP, - :updated_at => Sequel::SQL::Constants::CURRENT_TIMESTAMP) + :updated_at => Sequel::SQL::Constants::CURRENT_TIMESTAMP + ) end def insert_version(gem_id, number, platform: "ruby", indexed: true, prerelease: false) gem_name = Gemstash::Env.current.db[:rubygems][:id => gem_id][:name] - if platform == "ruby" - storage_id = "#{gem_name}-#{number}" + storage_id = if platform == "ruby" + "#{gem_name}-#{number}" else - storage_id = "#{gem_name}-#{number}-#{platform}" + "#{gem_name}-#{number}-#{platform}" end Gemstash::Env.current.db[:versions].insert( @@ -29,7 +30,8 @@ def insert_version(gem_id, number, platform: "ruby", indexed: true, prerelease: :indexed => indexed, :prerelease => prerelease, :created_at => Sequel::SQL::Constants::CURRENT_TIMESTAMP, - :updated_at => Sequel::SQL::Constants::CURRENT_TIMESTAMP) + :updated_at => Sequel::SQL::Constants::CURRENT_TIMESTAMP + ) end def insert_dependency(version_id, gem_name, requirements) @@ -38,6 +40,7 @@ def insert_dependency(version_id, gem_name, requirements) :rubygem_name => gem_name, :requirements => requirements, :created_at => Sequel::SQL::Constants::CURRENT_TIMESTAMP, - :updated_at => Sequel::SQL::Constants::CURRENT_TIMESTAMP) + :updated_at => Sequel::SQL::Constants::CURRENT_TIMESTAMP + ) end end diff --git a/spec/support/test_gemstash_server.rb b/spec/support/test_gemstash_server.rb index 78c7a562..5d8da494 100644 --- a/spec/support/test_gemstash_server.rb +++ b/spec/support/test_gemstash_server.rb @@ -10,10 +10,10 @@ def initialize(port: nil, config: nil) raise "Port is required" unless port raise "Config is required" unless config @port = port - args = %w(--config -) - args += %w(--workers 0) - args += %w(--threads 0:4) - args += %w(--environment test) + args = %w[--config -] + args += %w[--workers 0] + args += %w[--threads 0:4] + args += %w[--environment test] args += ["--port", port.to_s] args << File.expand_path("../test_gemstash_server.ru", __FILE__) config = Gemstash::Configuration.new(config: config) From 839db481a85015f64476176d0a55ffe4f07eb52f Mon Sep 17 00:00:00 2001 From: Matthew Albani Date: Wed, 17 Jan 2018 16:37:56 -0800 Subject: [PATCH 3/5] disable cop Security/YAMLLoad --- .rubocop-bundler.yml | 3 +++ lib/gemstash/configuration.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.rubocop-bundler.yml b/.rubocop-bundler.yml index f664e18a..eb7cb996 100644 --- a/.rubocop-bundler.yml +++ b/.rubocop-bundler.yml @@ -118,6 +118,9 @@ Metrics/LineLength: Security/MarshalLoad: Enabled: false +Security/YAMLLoad: + Enabled: false + #Ignore certain test cases Bundler/DuplicatedGem: Exclude: diff --git a/lib/gemstash/configuration.rb b/lib/gemstash/configuration.rb index c0926f8d..9e2d94ae 100644 --- a/lib/gemstash/configuration.rb +++ b/lib/gemstash/configuration.rb @@ -73,7 +73,7 @@ def default_file def parse_config(file) if file.end_with?(".erb") - YAML.safe_load(ERB.new(File.read(file)).result) || {} + YAML.load(ERB.new(File.read(file)).result) || {} else YAML.load_file(file) || {} end From 9e0242486f33f46bcc8943b885245a6b3cdc866b Mon Sep 17 00:00:00 2001 From: Matthew Albani Date: Thu, 18 Jan 2018 09:22:26 -0800 Subject: [PATCH 4/5] dont follow rubocop recommendation on the "with large data" test as it seems to make things worse add a bit of output to "with large data" test so travis does not timeout allow jruby to wait longer before timing out --- .rubocop-bundler.yml | 5 +++++ spec/concurrency_spec.rb | 38 ++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/.rubocop-bundler.yml b/.rubocop-bundler.yml index eb7cb996..58abf19e 100644 --- a/.rubocop-bundler.yml +++ b/.rubocop-bundler.yml @@ -129,3 +129,8 @@ Bundler/DuplicatedGem: Style/GlobalVars: Exclude: - spec/support/test_gemstash_server.ru + +#changing this causes the jruby build to wedge +Style/ConditionalAssignment: + Exclude: + - spec/concurrency_spec.rb diff --git a/spec/concurrency_spec.rb b/spec/concurrency_spec.rb index 27def448..a4291edb 100644 --- a/spec/concurrency_spec.rb +++ b/spec/concurrency_spec.rb @@ -102,27 +102,29 @@ def check_for_errors_and_deadlocks(threads) threads = [] possible_content = [ - ("One" * 100_000).freeze, - ("Two" * 100_000).freeze, - ("Three" * 100_000).freeze, - ("Four" * 100_000).freeze + ("One" * 10_000).freeze, + ("Two" * 10_000).freeze, + ("Three" * 10_000).freeze, + ("Four" * 10_000).freeze ].freeze - + count = 0 50.times do - threads << if rand(2) == 0 - write_thread("large") do |resource| - large_content = possible_content[rand(possible_content.size)] - resource.save({ file: large_content }, example: true, content: large_content) - end - else - read_thread("large") do |resource| - raise "Property mismatch" unless resource.properties[:example] - raise "Property mismatch" unless possible_content.include?(resource.properties[:content]) - raise "Content mismatch" unless possible_content.include?(resource.content(:file)) - end - end + # so travis doesnt timeout from no output + print "." if ((count += 1) % 5).zero? + if rand(2) == 0 + threads << write_thread("large") do |resource| + large_content = possible_content[rand(possible_content.size)] + resource.save({ file: large_content }, example: true, content: large_content) + end + else + threads << read_thread("large") do |resource| + raise "Property mismatch" unless resource.properties[:example] + raise "Property mismatch" unless possible_content.include?(resource.properties[:content]) + raise "Content mismatch" unless possible_content.include?(resource.content(:file)) + end + end end - + print "done building data" check_for_errors_and_deadlocks(threads) end end From 6d9e7120a2a66be72c0e26dbbcbc5b7d77ff4592 Mon Sep 17 00:00:00 2001 From: Matthew Albani Date: Fri, 19 Jan 2018 12:38:41 -0800 Subject: [PATCH 5/5] use block_given? instead of if block and &block --- spec/concurrency_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/concurrency_spec.rb b/spec/concurrency_spec.rb index a4291edb..8ba8171c 100644 --- a/spec/concurrency_spec.rb +++ b/spec/concurrency_spec.rb @@ -3,7 +3,7 @@ describe "gemstash concurrency tests" do let(:timeout) { 5 } - def write_thread(resource_id, content = "unchanging", &block) + def write_thread(resource_id, content = "unchanging") env = Gemstash::Env.current Thread.new do @@ -12,7 +12,7 @@ def write_thread(resource_id, content = "unchanging", &block) storage = Gemstash::Storage.for("concurrent_test") resource = storage.resource(resource_id.to_s) - if block + if block_given? yield(resource) else resource.save({ file: "Example content: #{content}" }, example: true, content: content) @@ -20,7 +20,7 @@ def write_thread(resource_id, content = "unchanging", &block) end end - def read_thread(resource_id, &block) + def read_thread(resource_id) env = Gemstash::Env.current Thread.new do @@ -30,7 +30,7 @@ def read_thread(resource_id, &block) resource = storage.resource(resource_id.to_s) if resource.exist?(:file) - if block + if block_given? yield(resource) else raise "Property mismatch" unless resource.properties[:example]