-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement authentication/authorization verifier
- Loading branch information
Showing
12 changed files
with
191 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
spec/controllers/authentication_verification_test_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'rails_helper' | ||
|
||
describe AuthenticationVerificationTestController, type: :controller do | ||
describe "#authentication_not_performed" do | ||
it "does raise error" do | ||
expect{ get :authentication_not_performed }.to raise_error ActiveEntry::AuthenticationNotPerformedError | ||
end | ||
end | ||
|
||
describe "#authentication_performed" do | ||
it "does not raise error" do | ||
expect{ get :authentication_performed }.to_not raise_error | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
spec/controllers/authorization_verification_test_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'rails_helper' | ||
|
||
describe AuthorizationVerificationTestController, type: :controller do | ||
describe "#authorization_not_performed" do | ||
it "does raise error" do | ||
expect{ get :authorization_not_performed }.to raise_error ActiveEntry::AuthorizationNotPerformedError | ||
end | ||
end | ||
|
||
describe "#authorization_performed" do | ||
it "does not raise error" do | ||
expect{ get :authorization_performed }.to_not raise_error | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
spec/dummy/app/controllers/authentication_verification_test_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class AuthenticationVerificationTestController < ApplicationController | ||
after_action :verify_authentication! | ||
before_action :authenticate!, only: :authentication_performed | ||
|
||
def authentication_not_performed | ||
head :no_content | ||
end | ||
|
||
def authentication_performed_authenticated? | ||
true | ||
end | ||
def authentication_performed | ||
head :no_content | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
spec/dummy/app/controllers/authorization_verification_test_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class AuthorizationVerificationTestController < ApplicationController | ||
after_action :verify_authorization! | ||
before_action :authorize!, only: :authorization_performed | ||
|
||
def authorization_not_performed | ||
head :no_content | ||
end | ||
|
||
def authorization_performed_authorized? | ||
true | ||
end | ||
def authorization_performed | ||
head :no_content | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require "rails_helper" | ||
|
||
describe "Authentication verification" do | ||
let(:dummy_class) { Class.new { include ActiveEntry } } | ||
let(:dummy_obj) { dummy_class.new } | ||
|
||
before { dummy_class.define_method(:action_name) { "index" } } | ||
|
||
it 'raises `AuthenticationNotPerformedError` if #authenticate! is not called' do | ||
expect{ dummy_obj.verify_authentication! }.to raise_error ActiveEntry::AuthenticationNotPerformedError | ||
end | ||
|
||
it 'does not raise error if @_authentication_done is true' do | ||
dummy_obj.instance_variable_set :@_authentication_done, true | ||
expect{ dummy_obj.verify_authentication! }.to_not raise_error | ||
end | ||
|
||
it 'does not raise error if #authenticate! is called' do | ||
dummy_class.define_method(:authenticated?) { true } | ||
|
||
expect do | ||
dummy_obj.authenticate! | ||
dummy_obj.verify_authentication! | ||
end.to_not raise_error | ||
end | ||
|
||
describe '#authenticate!' do | ||
it "sets @_authentication_done" do | ||
dummy_class.define_method(:authenticated?) { true } | ||
dummy_obj.authenticate! | ||
expect(dummy_obj.instance_variable_get(:@_authentication_done)).to be true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require "rails_helper" | ||
|
||
describe "Authorization verification" do | ||
let(:dummy_class) { Class.new { include ActiveEntry } } | ||
let(:dummy_obj) { dummy_class.new } | ||
|
||
before { dummy_class.define_method(:action_name) { "index" } } | ||
|
||
it 'raises `AuthorizationNotPerformedError` if #authorize! is not called' do | ||
expect{ dummy_obj.verify_authorization! }.to raise_error ActiveEntry::AuthorizationNotPerformedError | ||
end | ||
|
||
it 'does not raise error if @_authorization_done is true' do | ||
dummy_obj.instance_variable_set :@_authorization_done, true | ||
expect{ dummy_obj.verify_authorization! }.to_not raise_error | ||
end | ||
|
||
it 'does not raise error if #authenticate! is called' do | ||
dummy_class.define_method(:authorized?) { true } | ||
|
||
expect do | ||
dummy_obj.authorize! | ||
dummy_obj.verify_authorization! | ||
end.to_not raise_error | ||
end | ||
|
||
describe '#authorize!' do | ||
it "sets @_authorization_done" do | ||
dummy_class.define_method(:authorized?) { true } | ||
dummy_obj.authorize! | ||
expect(dummy_obj.instance_variable_get(:@_authorization_done)).to be true | ||
end | ||
end | ||
end |