diff --git a/Gemfile b/Gemfile index 3b38a5e..203c757 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ end group :test do gem "rspec" - gem "rubocop", "0.36.0" + gem "rubocop", "0.38.0" gem "coveralls", require: false gem "certificate_authority", require: false end diff --git a/lib/rails/auth/acl.rb b/lib/rails/auth/acl.rb index c4e6302..d98ff32 100644 --- a/lib/rails/auth/acl.rb +++ b/lib/rails/auth/acl.rb @@ -26,7 +26,7 @@ def initialize(acl, matchers: {}) acl.each_with_index do |entry| resources = entry["resources"] - fail ParseError, "no 'resources' key present in entry: #{entry.inspect}" unless resources + raise ParseError, "no 'resources' key present in entry: #{entry.inspect}" unless resources predicates = parse_predicates(entry, matchers.merge(DEFAULT_MATCHERS)) @@ -73,8 +73,8 @@ def parse_predicates(entry, matchers) next if name == "resources" matcher_class = matchers[name.to_sym] - fail ArgumentError, "no matcher for #{name}" unless matcher_class - fail TypeError, "expected Class for #{name}" unless matcher_class.is_a?(Class) + raise ArgumentError, "no matcher for #{name}" unless matcher_class + raise TypeError, "expected Class for #{name}" unless matcher_class.is_a?(Class) predicates[name.freeze] = matcher_class.new(options.freeze).freeze end diff --git a/lib/rails/auth/acl/matchers/allow_all.rb b/lib/rails/auth/acl/matchers/allow_all.rb index f3f512e..cc51df3 100644 --- a/lib/rails/auth/acl/matchers/allow_all.rb +++ b/lib/rails/auth/acl/matchers/allow_all.rb @@ -6,7 +6,7 @@ module Matchers # Allows unauthenticated clients to access to a given resource class AllowAll def initialize(enabled) - fail ArgumentError, "enabled must be true/false" unless [true, false].include?(enabled) + raise ArgumentError, "enabled must be true/false" unless [true, false].include?(enabled) @enabled = enabled end diff --git a/lib/rails/auth/acl/middleware.rb b/lib/rails/auth/acl/middleware.rb index 91349a8..88a7906 100644 --- a/lib/rails/auth/acl/middleware.rb +++ b/lib/rails/auth/acl/middleware.rb @@ -15,14 +15,14 @@ def self.from_acl_config(app, **args) # # @return [Rails::Auth::ACL::Middleware] new ACL middleware instance def initialize(app, acl: nil) - fail ArgumentError, "no acl given" unless acl + raise ArgumentError, "no acl given" unless acl @app = app @acl = acl end def call(env) - fail NotAuthorizedError, "unauthorized request" unless @acl.match(env) + raise NotAuthorizedError, "unauthorized request" unless @acl.match(env) @app.call(env) end end diff --git a/lib/rails/auth/acl/resource.rb b/lib/rails/auth/acl/resource.rb index bbe5545..ff9d205 100644 --- a/lib/rails/auth/acl/resource.rb +++ b/lib/rails/auth/acl/resource.rb @@ -18,11 +18,11 @@ class Resource # @param [Hash] :predicates matchers for this resource # def initialize(options, predicates) - fail TypeError, "expected Hash for options" unless options.is_a?(Hash) - fail TypeError, "expected Hash for predicates" unless predicates.is_a?(Hash) + raise TypeError, "expected Hash for options" unless options.is_a?(Hash) + raise TypeError, "expected Hash for predicates" unless predicates.is_a?(Hash) unless (extra_keys = options.keys - VALID_OPTIONS).empty? - fail ParseError, "unrecognized key in ACL resource: #{extra_keys.first}" + raise ParseError, "unrecognized key in ACL resource: #{extra_keys.first}" end @http_methods = extract_methods(options["method"]) @@ -63,7 +63,7 @@ def extract_methods(methods) return nil if methods.include?("ALL") methods.each do |method| - fail ParseError, "invalid HTTP method: #{method}" unless HTTP_METHODS.include?(method) + raise ParseError, "invalid HTTP method: #{method}" unless HTTP_METHODS.include?(method) end methods.freeze diff --git a/lib/rails/auth/credentials.rb b/lib/rails/auth/credentials.rb index cdee4d8..00c7a3c 100644 --- a/lib/rails/auth/credentials.rb +++ b/lib/rails/auth/credentials.rb @@ -25,7 +25,7 @@ def credentials(env) def add_credential(env, type, credential) credentials = env[CREDENTIALS_ENV_KEY] ||= {} - fail ArgumentError, "credential #{type} already added to request" if credentials.key?(type) + raise ArgumentError, "credential #{type} already added to request" if credentials.key?(type) credentials[type] = credential env diff --git a/lib/rails/auth/error_page/middleware.rb b/lib/rails/auth/error_page/middleware.rb index 0c66a58..e3a949e 100644 --- a/lib/rails/auth/error_page/middleware.rb +++ b/lib/rails/auth/error_page/middleware.rb @@ -4,7 +4,7 @@ module ErrorPage # Render an error page in the event Rails::Auth::NotAuthorizedError is raised class Middleware def initialize(app, page_body: nil) - fail TypeError, "page_body must be a String" unless page_body.is_a?(String) + raise TypeError, "page_body must be a String" unless page_body.is_a?(String) @app = app @page_body = page_body.freeze diff --git a/lib/rails/auth/rspec/helper_methods.rb b/lib/rails/auth/rspec/helper_methods.rb index 37f3e7f..062d7a5 100644 --- a/lib/rails/auth/rspec/helper_methods.rb +++ b/lib/rails/auth/rspec/helper_methods.rb @@ -30,7 +30,7 @@ def x509_certificate_hash(**args) # Warn if methods are improperly used unless path.chars[0] == "/" - fail ArgumentError, "expected #{path} to start with '/'" + raise ArgumentError, "expected #{path} to start with '/'" end env = { diff --git a/lib/rails/auth/x509/certificate.rb b/lib/rails/auth/x509/certificate.rb index 9f049e4..91cf54a 100644 --- a/lib/rails/auth/x509/certificate.rb +++ b/lib/rails/auth/x509/certificate.rb @@ -9,7 +9,7 @@ class Certificate def initialize(certificate) unless certificate.is_a?(OpenSSL::X509::Certificate) - fail TypeError, "expecting OpenSSL::X509::Certificate, got #{certificate.class}" + raise TypeError, "expecting OpenSSL::X509::Certificate, got #{certificate.class}" end @certificate = certificate.freeze diff --git a/lib/rails/auth/x509/middleware.rb b/lib/rails/auth/x509/middleware.rb index fd90ec1..79f641b 100644 --- a/lib/rails/auth/x509/middleware.rb +++ b/lib/rails/auth/x509/middleware.rb @@ -19,7 +19,7 @@ class Middleware # # @return [Rails::Auth::X509::Middleware] new X509 middleware instance def initialize(app, cert_filters: {}, ca_file: nil, truststore: nil, require_cert: false, logger: nil) - fail ArgumentError, "no ca_file given" unless ca_file + raise ArgumentError, "no ca_file given" unless ca_file @app = app @logger = logger @@ -57,11 +57,11 @@ def extract_credential(env) return Rails::Auth::X509::Certificate.new(cert) else log("Verify FAILED", cert) - fail CertificateVerifyFailed, "verify failed: #{subject(cert)}" if @require_cert + raise CertificateVerifyFailed, "verify failed: #{subject(cert)}" if @require_cert end end - fail CertificateVerifyFailed, "no client certificate in request" if @require_cert + raise CertificateVerifyFailed, "no client certificate in request" if @require_cert nil end diff --git a/spec/rails/auth/error_page/middleware_spec.rb b/spec/rails/auth/error_page/middleware_spec.rb index ba26517..fc9f14a 100644 --- a/spec/rails/auth/error_page/middleware_spec.rb +++ b/spec/rails/auth/error_page/middleware_spec.rb @@ -15,7 +15,7 @@ end context "access denied" do - let(:app) { ->(_env) { fail(Rails::Auth::NotAuthorizedError, "not authorized!") } } + let(:app) { ->(_env) { raise(Rails::Auth::NotAuthorizedError, "not authorized!") } } it "renders the error page" do code, _env, body = middleware.call(request)