Skip to content

Commit

Permalink
Merge pull request #179 from landongrindheim/resolve-TODOs
Browse files Browse the repository at this point in the history
Resolve outstanding TODOs
  • Loading branch information
jsmestad committed Jul 24, 2019
2 parents e7279a8 + b9bdacc commit 70547a6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 36 deletions.
5 changes: 0 additions & 5 deletions spec/warden/hooks_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# encoding: utf-8
# frozen_string_literal: true
RSpec.describe "standard authentication hooks" do

before(:all) do
load_strategies
end

describe "after_set_user" do
before(:each) do
RAM = Warden::Manager unless defined?(RAM)
Expand Down
36 changes: 12 additions & 24 deletions spec/warden/manager_spec.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
# encoding: utf-8
# frozen_string_literal: true
RSpec.describe Warden::Manager do

before(:all) do
load_strategies
end

it "should insert a Proxy object into the rack env" do
env = env_with_params
setup_rack(success_app).call(env)
expect(env["warden"]).to be_an_instance_of(Warden::Proxy)
end

describe "thrown auth" do
before(:each) do
@basic_app = lambda{|env| [200,{'Content-Type' => 'text/plain'},'OK']}
@authd_app = lambda do |e|
if e['warden'].authenticated?
[200,{'Content-Type' => 'text/plain'},"OK"]
else
[401,{'Content-Type' => 'text/plain'},"Fail From The App"]
end
end
@env = Rack::MockRequest.
env_for('/', 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => 'GET')
end # before(:each)

describe "Failure" do
it "should respond with a 401 response if the strategy fails authentication" do
env = env_with_params("/", :foo => "bar")
app = lambda do |_env|
_env['warden'].authenticate(:failz)
throw(:warden, :action => :unauthenticated)
end
result = setup_rack(app, :failure_app => @fail_app).call(env) # TODO: What is @fail_app?
result = setup_rack(app).call(env)
expect(result.first).to eq(401)
end

Expand All @@ -43,7 +25,10 @@
_env['warden'].authenticate(:failz)
throw(:warden)
end
result = setup_rack(app, :failure_app => @fail_app).call(env) # TODO: What is @fail_app?
fail_app = lambda do |_env|
[401, {"Content-Type" => "text/plain"}, ["You Fail!"]]
end
result = setup_rack(app, :failure_app => fail_app).call(env)
expect(result.last).to eq(["You Fail!"])
end

Expand All @@ -53,7 +38,7 @@
_env['warden'].authenticate(:failz)
throw(:warden)
end
setup_rack(app, :failure_app => @fail_app).call(env) # TODO: What is @fail_app?
setup_rack(app).call(env)
expect(env["warden.options"][:message]).to eq("The Fails Strategy Has Failed You")
end

Expand All @@ -74,7 +59,10 @@
_env['warden'].authenticate(:pass)
throw(:warden)
end
result = setup_rack(app, :failure_app => @fail_app).call(env)
fail_app = lambda do |_env|
[401, {"Content-Type" => "text/plain"}, ["You Fail!"]]
end
result = setup_rack(app, :failure_app => fail_app).call(env)
expect(result.first).to eq(401)
expect(result.last).to eq(["You Fail!"])
end
Expand All @@ -85,7 +73,7 @@
_env['warden'].authenticate(:pass)
throw(:warden)
end
result = setup_rack(app, :failure_app => @fail_app).call(env) # TODO: What is @fail_app?
result = setup_rack(app).call(env)
expect(result.first).to eq(401)
expect(env["warden.options"][:attempted_path]).to eq("/access/path")
end
Expand All @@ -96,7 +84,7 @@
_env['warden'].authenticate(:pass)
throw(:warden, action: :different_action)
end
result = setup_rack(app, :failure_app => @fail_app).call(env)
result = setup_rack(app).call(env)
expect(result.first).to eq(401)
expect(env["warden.options"][:action]).to eq(:different_action)
end
Expand Down
2 changes: 0 additions & 2 deletions spec/warden/proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -885,8 +885,6 @@ def def_app(&blk)

describe "dynamic default_strategies" do
before(:all) do
load_strategies

class ::DynamicDefaultStrategies
def initialize(app, &blk)
@app, @blk = app, blk
Expand Down
9 changes: 4 additions & 5 deletions spec/warden/strategies/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ def authenticate!; end
expect(strategy).not_to be_performed
end

it "should set the scope" do
it "should set the scope when initialized with one" do
RAS.add(:foobar) do
def authenticate!
expect(self.scope).to eq(:user) # TODO: Not being called at all. What's this?
end
def authenticate!; end
end
_strategy = RAS[:foobar].new(env_with_params, :user)
strategy = RAS[:foobar].new(env_with_params, :user)
expect(strategy.scope).to eq(:user)
end

it "should allow you to set a message" do
Expand Down

0 comments on commit 70547a6

Please sign in to comment.