Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/rails/auth/acl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/auth/acl/matchers/allow_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/rails/auth/acl/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/rails/auth/acl/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/auth/credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/auth/error_page/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/auth/rspec/helper_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/auth/x509/certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/rails/auth/x509/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/rails/auth/error_page/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down