diff --git a/.gitignore b/.gitignore index 402e6c2..83a9588 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ pkg/* coverage tmp/ Gemfile.lock +.vagrant diff --git a/.rubocop.yml b/.rubocop.yml index 27ed16e..89c4dbc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,8 @@ AllCops: - 'tmp/**/*' - Gemfile DisplayCopNames: true - TargetRubyVersion: 2.3 + TargetRubyVersion: 3.4 + NewCops: enable Style/GuardClause: Enabled: false @@ -13,7 +14,7 @@ Metrics/AbcSize: Max: 38 # Configuration parameters: AllowURI. -Metrics/LineLength: +Layout/LineLength: Max: 225 # Configuration parameters: CountKeywordArgs. @@ -31,19 +32,16 @@ Metrics/ClassLength: Max: 174 Metrics/CyclomaticComplexity: - Max: 7 + Max: 9 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 76 Metrics/PerceivedComplexity: - Max: 8 + Max: 9 # Configuration parameters: EnforcedStyle, SupportedStyles. -Style/MethodName: +Naming/MethodName: Exclude: - lib/proxy_pac_rb/environment.rb - -Style/GuardClause: - Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4fe0df7..ff067b3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,27 +1,90 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-06-04 19:50:00 +0000 using RuboCop version 0.49.1. +# on 2025-02-03 22:23:49 UTC using RuboCop version 1.71.1. # 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 # versions of RuboCop, may require this file to be generated again. -# Offense count: 82 -# Cop supports --auto-correct. +# Offense count: 6 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/AddRuntimeDependency: + Exclude: + - 'proxy_pac_rb.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/DeprecatedAttributeAssignment: + Exclude: + - 'proxy_pac_rb.gemspec' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'proxy_pac_rb.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequireMFA: + Exclude: + - 'proxy_pac_rb.gemspec' + +# Offense count: 1 +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'proxy_pac_rb.gemspec' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyleAlignWith, Severity. +# SupportedStylesAlignWith: start_of_line, begin +Layout/BeginEndAlignment: + Exclude: + - 'lib/proxy_pac_rb/rspec/helpers.rb' + - 'lib/proxy_pac_rb/rspec/matchers/proxy.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/ClosingHeredocIndentation: + Exclude: + - 'proxy_pac_rb.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/EmptyLineAfterGuardClause: + Exclude: + - 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb' + +# Offense count: 84 +# This cop supports safe autocorrection (--autocorrect). Layout/EmptyLineAfterMagicComment: Enabled: false -# Offense count: 87 -# Configuration parameters: EnforcedStyle, SupportedStyles. +# Offense count: 5 +# Configuration parameters: EnforcedStyle. # SupportedStyles: native, lf, crlf Layout/EndOfLine: - Enabled: false + Exclude: + - 'Vagrantfile' + - 'lib/proxy_pac_rb.rb' + - 'lib/proxy_pac_rb/environment.rb' + - 'lib/proxy_pac_rb/runtimes.rb' + - 'spec/rack/proxy_pac_linter_spec.rb' # Offense count: 27 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent -Layout/IndentHeredoc: +# This cop supports safe autocorrection (--autocorrect). +Layout/HeredocIndentation: Exclude: - 'lib/proxy_pac_rb/cli/init_proxy_pac.rb' - 'lib/proxy_pac_rb/proxy_pac_js.rb' @@ -34,36 +97,266 @@ Layout/IndentHeredoc: - 'spec/rspec/readability_spec.rb' - 'spec/rspec/validitiy_spec.rb' -# Offense count: 17 -# Configuration parameters: CountComments, ExcludedMethods. +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented +Layout/LineEndStringConcatenationIndentation: + Exclude: + - 'lib/proxy_pac_rb/runtimes.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/RescueEnsureAlignment: + Exclude: + - 'lib/proxy_pac_rb/rspec/helpers.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowInHeredoc. +Layout/TrailingWhitespace: + Exclude: + - '.simplecov' + +# Offense count: 4 +# Configuration parameters: AllowedParentClasses. +Lint/MissingSuper: + Exclude: + - 'lib/proxy_pac_rb/rspec/matchers/proxy.rb' + - 'lib/proxy_pac_rb/runtimes/miniracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyrhino.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Lint/RedundantCopDisableDirective: + Exclude: + - 'lib/proxy_pac_rb/environment.rb' + - 'lib/proxy_pac_rb/javascript.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/RedundantRequireStatement: + Exclude: + - 'lib/proxy_pac_rb.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Lint/SendWithMixinArgument: + Exclude: + - 'Rakefile' + +# Offense count: 1 +# Configuration parameters: AllowComments, AllowNil. +Lint/SuppressedException: + Exclude: + - 'lib/proxy_pac_rb/environment.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: strict, consistent +Lint/SymbolConversion: + Exclude: + - 'lib/proxy_pac_rb/basic_configuration.rb' + +# Offense count: 18 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +# AllowedMethods: refine Metrics/BlockLength: Max: 178 +# Offense count: 4 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 9 + +# Offense count: 1 +# Configuration parameters: AllowedMethods, AllowedPatterns, Max. +Metrics/PerceivedComplexity: + Exclude: + - 'lib/proxy_pac_rb/runtimes/miniracer.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, BlockForwardingName. +# SupportedStyles: anonymous, explicit +Naming/BlockForwarding: + Exclude: + - 'lib/proxy_pac_rb/javascript.rb' + - 'lib/proxy_pac_rb/rspec.rb' + +# Offense count: 47 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +Naming/HeredocDelimiterNaming: + Exclude: + - 'lib/proxy_pac_rb/cli/init_proxy_pac.rb' + - 'lib/proxy_pac_rb/proxy_pac_js.rb' + - 'spec/api/proxy_pac_compressor_spec.rb' + - 'spec/api/proxy_pac_dumper_spec.rb' + - 'spec/api/proxy_pac_file_spec.rb' + - 'spec/api/proxy_pac_linter_spec.rb' + - 'spec/api/proxy_pac_loader_spec.rb' + - 'spec/api/proxy_pac_parser_spec.rb' + - 'spec/parser_spec.rb' + - 'spec/rack/proxy_pac_compressor_spec.rb' + - 'spec/rack/proxy_pac_linter_spec.rb' + - 'spec/rspec/compare_proxy_pac_files_spec.rb' + - 'spec/rspec/parse_proxy_pac_spec.rb' + - 'spec/rspec/readability_spec.rb' + - 'spec/rspec/validitiy_spec.rb' + +# Offense count: 1 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'lib/proxy_pac_rb/proxy_pac_file.rb' + +# Offense count: 8 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: PreferredName. +Naming/RescuedExceptionsVariableName: + Exclude: + - 'lib/proxy_pac_rb/cli/find_proxy.rb' + - 'lib/proxy_pac_rb/javascript_compiler.rb' + - 'lib/proxy_pac_rb/proxy_pac_linter.rb' + - 'lib/proxy_pac_rb/proxy_pac_loader.rb' + - 'lib/proxy_pac_rb/proxy_pac_parser.rb' + - 'lib/proxy_pac_rb/rack/proxy_pac_compressor.rb' + - 'lib/proxy_pac_rb/rspec/matchers/base_matcher.rb' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. +# SupportedStyles: snake_case, normalcase, non_integer +# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 +Naming/VariableNumber: + Exclude: + - 'spec/api/proxy_pac_file_spec.rb' + +# Offense count: 14 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowOnlyRestArgument, UseAnonymousForwarding, RedundantRestArgumentNames, RedundantKeywordRestArgumentNames, RedundantBlockArgumentNames. +# RedundantRestArgumentNames: args, arguments +# RedundantKeywordRestArgumentNames: kwargs, options, opts +# RedundantBlockArgumentNames: blk, block, proc +Style/ArgumentsForwarding: + Exclude: + - 'lib/proxy_pac_rb/basic_configuration.rb' + - 'lib/proxy_pac_rb/parser.rb' + - 'lib/proxy_pac_rb/rspec.rb' + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyrhino.rb' + # Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: MinBranchesCount. +Style/CaseLikeIf: + Exclude: + - 'lib/proxy_pac_rb/runtimes/miniracer.rb' + +# Offense count: 7 +Style/DocumentDynamicEvalDefinition: + Exclude: + - 'lib/proxy_pac_rb/runtimes/miniracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyrhino.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: compact, expanded Style/EmptyMethod: Exclude: - 'lib/proxy_pac_rb/runtime.rb' +# Offense count: 32 +# This cop supports safe autocorrection (--autocorrect). +Style/Encoding: + Enabled: false + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Style/EvalWithLocation: + Exclude: + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + - 'lib/proxy_pac_rb/runtimes/rubyrhino.rb' + +# Offense count: 11 +# This cop supports safe autocorrection (--autocorrect). +Style/ExpandPathArguments: + Exclude: + - 'bin/pprb' + - 'lib/proxy_pac_rb/cli/init_proxy_pac.rb' + - 'lib/proxy_pac_rb/main.rb' + - 'proxy_pac_rb.gemspec' + - 'script/config.ru' + - 'script/console' + - 'spec/spec_helper.rb' + - 'templates/test_framework/rspec/spec_helper.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowedVars. +Style/FetchEnvVar: + Exclude: + - 'lib/proxy_pac_rb/runtimes.rb' + +# Offense count: 22 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns. +# SupportedStyles: annotated, template, unannotated +Style/FormatStringToken: + EnforcedStyle: unannotated + # Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: when_needed, always, never +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: Exclude: - - 'Vagrantfile' + - '**/*.arb' + - '.simplecov' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/HashExcept: + Exclude: + - 'lib/proxy_pac_rb/rspec.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). +Style/IfUnlessModifier: + Exclude: + - 'lib/proxy_pac_rb/encoding.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: InverseMethods, InverseBlocks. Style/InverseMethods: Exclude: - 'lib/proxy_pac_rb/rspec.rb' +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/MapIntoArray: + Exclude: + - 'lib/proxy_pac_rb/rack/proxy_pac_compressor.rb' + - 'lib/proxy_pac_rb/rack/proxy_pac_linter.rb' + +# Offense count: 1 +Style/MissingRespondToMissing: + Exclude: + - 'lib/proxy_pac_rb/javascript.rb' + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'spec/spec_helper.rb' + # Offense count: 7 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: Exclude: @@ -74,18 +367,73 @@ Style/PercentLiteralDelimiters: - 'spec/environment_spec.rb' - 'templates/test_framework/rspec/support/aruba.rb' +# Offense count: 5 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantBegin: + Exclude: + - 'lib/proxy_pac_rb/cli/find_proxy.rb' + - 'lib/proxy_pac_rb/environment.rb' + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + +# Offense count: 7 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantConstantBase: + Exclude: + - 'proxy_pac_rb.gemspec' + - 'script/console' + - 'spec/spec_helper.rb' + - 'templates/test_framework/rspec/spec_helper.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantStringEscape: + Exclude: + - 'spec/api/proxy_pac_compressor_spec.rb' + - 'spec/rack/proxy_pac_compressor_spec.rb' + +# Offense count: 6 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'lib/proxy_pac_rb/proxy_pac_linter.rb' + - 'lib/proxy_pac_rb/proxy_pac_loader.rb' + - 'lib/proxy_pac_rb/proxy_pac_parser.rb' + - 'lib/proxy_pac_rb/rack/proxy_pac_compressor.rb' + - 'lib/proxy_pac_rb/rspec/helpers.rb' + - 'lib/proxy_pac_rb/runtimes/rubyracer.rb' + +# Offense count: 11 +# This cop supports safe autocorrection (--autocorrect). +Style/StderrPuts: + Exclude: + - 'lib/proxy_pac_rb/cli/compress_proxy_pac.rb' + - 'lib/proxy_pac_rb/cli/find_proxy.rb' + - 'lib/proxy_pac_rb/cli/lint_proxy_pac.rb' + - 'lib/proxy_pac_rb/cli/show.rb' + - 'lib/proxy_pac_rb/cli_validator.rb' + - 'lib/proxy_pac_rb/parser.rb' + +# Offense count: 6 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - '.simplecov' + # Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: MinSize, SupportedStyles. +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: MinSize. # SupportedStyles: percent, brackets Style/SymbolArray: EnforcedStyle: brackets -# Offense count: 4 -# Cop supports --auto-correct. -Style/YodaCondition: +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: Exclude: - - 'lib/proxy_pac_rb/proxy_pac_file.rb' - - 'lib/proxy_pac_rb/rack/proxy_pac_compressor.rb' - - 'lib/proxy_pac_rb/rack/proxy_pac_linter.rb' - - 'lib/proxy_pac_rb/rspec/helpers.rb' + - 'lib/proxy_pac_rb/proxy_pac_compressor.rb' diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..47b322c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.4.1 diff --git a/Gemfile b/Gemfile index ed7218c..807996d 100644 --- a/Gemfile +++ b/Gemfile @@ -13,15 +13,15 @@ group :debug do end group :development, :test do - gem 'middleman', '~> 4.1', require: false - gem 'aruba', '~>0.14.2', require: false + gem 'middleman', require: false + gem 'aruba', require: false gem 'awesome_print', require: 'ap' - gem 'bundler', '~> 1.3', require: false + gem 'bundler', require: false gem 'command_exec', require: false gem 'coveralls', require: false gem 'cucumber', require: false gem 'erubis' - gem 'fedux_org-stdlib', '~>0.11.17', require: false + gem 'fedux_org-stdlib', require: false gem 'filegen' gem 'foreman', require: false gem 'fuubar', require: false @@ -49,11 +49,18 @@ group :profile do end group :runtimes do - group :therubyracer do - gem 'therubyracer', require: 'v8' + # mini_racer & therubyracer can't sit in the same gemfile + # uncomment the needed one and comment the other + # + group :mini_racer do + gem 'mini_racer', require: 'mini_racer' end + # group :therubyracer do + # gem 'therubyracer', require: 'v8' + # end + group :therubyrhino do - gem 'therubyrhino', require: 'rhino' + gem 'therubyrhino', require: 'rhino', platform: :jruby end end diff --git a/README.md b/README.md index 25e2c1f..ed100ba 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@ [![Downloads](http://img.shields.io/gem/dt/proxy_pac_rb.svg?style=flat)](http://rubygems.org/gems/proxy_pac_rb) -`proxy_pac_rb` is a gem to compress, lint and parse [proxy auto-config](http://en.wikipedia.org/wiki/Proxy_auto-config) files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well. `proxy_pac_rb` uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: [therubyracer](https://rubygems.org/gems/therubyracer) or [therubyrhino](https://rubygems.org/gems/therubyrhino/). +`proxy_pac_rb` is a gem to compress, lint and parse [proxy auto-config](http://en.wikipedia.org/wiki/Proxy_auto-config +) files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well +. `proxy_pac_rb` uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: [miniracer](https://github.com/rubyjs/mini_racer), [therubyracer](https://rubygems.org/gems/therubyracer) or [therubyrhino](https://rubygems.org/gems/therubyrhino/). Big thanks to [sstephenson](https://github.com/sstephenson)'s [execjs](https://github.com/sstephenson/execjs) for the runtime wrapper code and to @@ -35,6 +37,7 @@ After installing the `proxy_pac_rb` gem you must install a JavaScript runtime. C * [therubyracer](https://rubygems.org/gems/therubyracer) Google V8 embedded within Ruby * [therubyrhino](https://rubygems.org/gems/therubyrhino/) Mozilla Rhino embedded within JRuby +* [miniracer](https://github.com/rubyjs/mini_racer) Minimal, modern embedded V8 for Ruby ## Usage diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..f707086 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +# -*- mode: ruby -*- +# vi: set ft=ruby : + +RUBY_V = File.read('./.ruby-version').chomp +Vagrant.configure('2') do |config| + config.vm.box = 'bento/debian-12' + config.vm.network 'forwarded_port', guest: 3000, host: 3033, host_ip: 'localhost' + # change to 'virtualbox' if you use it in place of vmware + config.vm.provider 'vmware_desktop' do |vb| + vb.memory = '1024' + vb.gui = false + end + config.vm.provision 'shell', inline: <<-SHELL + # for nodejs repository + # see https://github.com/nodesource/distributions#debian-and-ubuntu-based-distributions + sudo apt-get install -y ca-certificates curl gnupg + NODE_MAJOR=22 + curl -fsSL https://deb.nodesource.com/setup_$NODE_MAJOR.x -o nodesource_setup.sh + sudo -E bash nodesource_setup.sh + # update the apt repositories + sudo apt-get update + # update the system + sudo apt-get -y dist-upgrade + # install ruby prerequisite + sudo apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev \ + libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev \ + libcurl4-openssl-dev libffi-dev \ + nodejs yarn + # cleanup + sudo apt-get autoremove -y + sudo apt-get clean -y + SHELL + + config.vm.provision :shell, privileged: false, inline: <<~SCRIPT + if [ ! -d ~/.rbenv ]; then + git clone https://github.com/rbenv/rbenv.git ~/.rbenv + echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc + echo 'eval "$(rbenv init -)"' >> ~/.bashrc + fi + git -C /home/vagrant/.rbenv pull + + if [ ! -d ~/.rbenv/plugins/ruby-build ]; then + git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build + echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc + fi + git -C /home/vagrant/.rbenv/plugins/ruby-build pull + export PATH="$HOME/.rbenv/bin:$PATH" + export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH" + + eval "$(rbenv init -)" + if [ ! -e .rbenv/versions/#{RUBY_V} ]; then + rbenv install #{RUBY_V} + rbenv global #{RUBY_V} + gem update --system --no-doc + rbenv rehash + fi + cd /vagrant + # if [ ! -e /home/vagrant/.rbenv/shims/bundle ]; then + gem update --system --no-doc + rbenv rehash + # fi + bundle install + SCRIPT +end diff --git a/lib/proxy_pac_rb.rb b/lib/proxy_pac_rb.rb index 7920d02..ffa31d5 100644 --- a/lib/proxy_pac_rb.rb +++ b/lib/proxy_pac_rb.rb @@ -28,6 +28,7 @@ require 'proxy_pac_rb/runtime' require 'proxy_pac_rb/runtimes/rubyracer' require 'proxy_pac_rb/runtimes/rubyrhino' +require 'proxy_pac_rb/runtimes/miniracer' require 'proxy_pac_rb/runtimes' require 'proxy_pac_rb/parser' require 'proxy_pac_rb/javascript' diff --git a/lib/proxy_pac_rb/rspec/matchers/base_matcher.rb b/lib/proxy_pac_rb/rspec/matchers/base_matcher.rb index 15412fd..07a88e8 100644 --- a/lib/proxy_pac_rb/rspec/matchers/base_matcher.rb +++ b/lib/proxy_pac_rb/rspec/matchers/base_matcher.rb @@ -166,14 +166,14 @@ def failure_message_when_negated end # @private - # rubocop:disable Style/PredicateName + # rubocop:disable Naming/PredicateName def self.has_default_failure_messages?(matcher) matcher.method(:failure_message).owner == self && matcher.method(:failure_message_when_negated).owner == self rescue NameError false end - # rubocop:enable Style/PredicateName + # rubocop:enable Naming/PredicateName end include DefaultFailureMessages diff --git a/lib/proxy_pac_rb/runtimes.rb b/lib/proxy_pac_rb/runtimes.rb index 77ba0b4..cbe252b 100644 --- a/lib/proxy_pac_rb/runtimes.rb +++ b/lib/proxy_pac_rb/runtimes.rb @@ -2,6 +2,7 @@ module ProxyPacRb # JavaScript Runtimes module Runtimes + MiniRacer = MiniRacerRuntime.new RubyRacer = RubyRacerRuntime.new RubyRhino = RubyRhinoRuntime.new @@ -33,6 +34,7 @@ def names def runtimes @runtimes ||= [ + MiniRacer, RubyRacer, RubyRhino ] diff --git a/lib/proxy_pac_rb/runtimes/miniracer.rb b/lib/proxy_pac_rb/runtimes/miniracer.rb new file mode 100644 index 0000000..3900208 --- /dev/null +++ b/lib/proxy_pac_rb/runtimes/miniracer.rb @@ -0,0 +1,104 @@ +# frozen_string_literal: true +module ProxyPacRb + # Mini Racer Runtime + # little adaptation from execjs gem. + # All credits go to execjs gem author + class MiniRacerRuntime < Runtime + # Context + class Context < Runtime::Context + def initialize(_runtime, source = '', _environment = nil) + source = encode(source) + + self.context = ::MiniRacer::Context.new + translate { context.eval(source) } + end + + def include(environment) + environment.available_methods.each do |name| + context.attach(name.to_s, environment.method(name)) + end + end + + def exec(source, options = {}) + source = encode(source) + + # rubocop:disable Security/Eval, Style/EvalWithLocation + eval "(function(){#{source}})()", options if /\S/ =~ source + # rubocop:enable Security/Eval, Style/EvalWithLocation + end + + def eval(source, _options = {}) + source = encode(source) + + return nil unless /\S/ =~ source + + translate { context.eval("(#{source})") } + end + + def call(properties, *args) + translate { context.eval("#{properties}.apply(this, #{::JSON.generate(args)})") } + end + + private + + def strip_functions!(value) + if Array === value + value.map! do |v| + if MiniRacer::JavaScriptFunction === value + nil + else + strip_functions!(v) + end + end + elsif Hash === value + value.each do |k, v| + if MiniRacer::JavaScriptFunction === v + value.delete k + else + value[k] = strip_functions!(v) + end + end + value + elsif MiniRacer::JavaScriptFunction === value + nil + else + value + end + end + + def translate + strip_functions! yield + rescue MiniRacer::RuntimeError => e + ex = ProgramError.new e.message + if backtrace = e.backtrace # rubocop:disable Lint/AssignmentInCondition + backtrace = backtrace.map do |line| + if line =~ /JavaScript at/ + line.sub('JavaScript at ', '') + .sub('', '(proxypac)') + .strip + else + line + end + end + ex.set_backtrace backtrace + end + raise ex + rescue MiniRacer::ParseError => e + ex = RuntimeError.new e.message + ex.set_backtrace(['(proxypac):1'] + e.backtrace) + raise ex + end + end + + def name + 'mini_racer (V8)' + end + + def available? + require 'mini_racer' + true + rescue LoadError + false + end + end +end diff --git a/proxy_pac_rb.gemspec b/proxy_pac_rb.gemspec index e9187f0..ce3490d 100644 --- a/proxy_pac_rb.gemspec +++ b/proxy_pac_rb.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |spec| spec.homepage = 'https://github.com/dg-vrnetze/proxy_pac_rb' spec.summary = 'Compress, lint and parse proxy auto-config files from commandline, rack-compatible applications and custom ruby code.' spec.description = <<-DESC -"proxy_pac_rb" is a gem to compress, lint and parse proxy auto-config files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well. "proxy_pac_rb" uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: therubyracer or therubyrhino +"proxy_pac_rb" is a gem to compress, lint and parse proxy auto-config files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well. "proxy_pac_rb" uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: miniracer, therubyracer or therubyrhino DESC spec.license = 'MIT' @@ -21,12 +21,12 @@ DESC spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_runtime_dependency 'addressable', '~>2.3' - spec.add_runtime_dependency 'activesupport', '>=4.1', '<5.2' + spec.add_runtime_dependency 'addressable' + spec.add_runtime_dependency 'activesupport', '>=4.1' spec.add_runtime_dependency 'uglifier', '>= 2.7.1' - spec.add_runtime_dependency 'excon', '~> 0.45.3' - spec.add_runtime_dependency 'contracts', '~> 0.9' - spec.add_runtime_dependency 'thor', '~> 0.19' + spec.add_runtime_dependency 'excon' + spec.add_runtime_dependency 'contracts' + spec.add_runtime_dependency 'thor' - spec.required_ruby_version = '~> 2.3' + spec.required_ruby_version = '>= 2.3' end diff --git a/spec/rack/proxy_pac_compressor_spec.rb b/spec/rack/proxy_pac_compressor_spec.rb index 3c054d7..45bcbc2 100644 --- a/spec/rack/proxy_pac_compressor_spec.rb +++ b/spec/rack/proxy_pac_compressor_spec.rb @@ -37,7 +37,7 @@ end context 'when invalid proxy pac is given' do - let(:compressed_content) { %{Unexpected token: string (§$ )} } + let(:compressed_content) { %{Unexpected token: string (!$ )} } let(:app) do a = Class.new(Sinatra::Base) do @@ -48,7 +48,7 @@ get '/' do <<~EOS.chomp function FindProxyForURL(url, host) { - return $"§$ "DIRECT"; + return $"!$ "DIRECT"; } EOS end