Skip to content

Commit

Permalink
Default credentials option to false
Browse files Browse the repository at this point in the history
[Fixes #95]
  • Loading branch information
cyu committed Jul 15, 2017
1 parent 6ff9134 commit dabc6d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/rack/cors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Cors
VARY_HEADER_KEY = 'Vary'.freeze
DEFAULT_VARY_HEADERS = ['Origin'].freeze

RACK_LOGGER = 'rack.logger'.freeze

def initialize(app, opts={}, &block)
@app = app
@debug_mode = !!opts[:debug]
Expand Down Expand Up @@ -125,8 +127,8 @@ def select_logger(env)
elsif defined?(Rails) && Rails.logger
Rails.logger

elsif env['rack.logger']
env['rack.logger']
elsif env[RACK_LOGGER]
env[RACK_LOGGER]

else
::Logger.new(STDOUT).tap { |logger| logger.level = ::Logger::Severity::DEBUG }
Expand Down Expand Up @@ -248,6 +250,9 @@ def append_header(headers)
end

class Resources

attr_reader :resources

def initialize
@origins = []
@resources = []
Expand Down Expand Up @@ -311,7 +316,7 @@ def initialize(public_resource, path, opts={})
raise CorsMisconfigurationError if public_resource && opts[:credentials]

self.path = path
self.credentials = opts[:credentials].nil? ? !public_resource : opts[:credentials]
self.credentials = public_resource ? false : (opts[:credentials] == true)
self.max_age = opts[:max_age] || 1728000
self.pattern = compile(path)
self.if_proc = opts[:if]
Expand Down
11 changes: 11 additions & 0 deletions test/unit/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,15 @@

resources.first.allow_origin?('file://').must_equal true
end

it 'should default credentials option to false' do
cors = Rack::Cors.new(Proc.new {}) do
allow do
origins 'example.net'
resource '/', :headers => :any
end
end
resources = cors.send :all_resources
resources.first.resources.first.credentials.must_equal false
end
end

0 comments on commit dabc6d1

Please # to comment.