-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add better auth error propogation from interactor to controller; plus…
… unit test (#23) * Add better auth error propogation from interactor to controller; added interactor unit test * Use a concern to make interactors fail on error
- Loading branch information
Showing
7 changed files
with
49 additions
and
8 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 was deleted.
Oops, something went wrong.
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,11 @@ | ||
module FailOnError | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
around do |interactor| | ||
interactor.call | ||
rescue => e | ||
context.fail!(error: e) | ||
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
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,33 @@ | ||
require "test_helper" | ||
|
||
class AuthorizeRequestTest < ActiveSupport::TestCase | ||
def setup | ||
@domain = domains(:group_match) | ||
@identity = Identity.new(subject: @domain.owner) | ||
@cr = CertIssueRequest.new(common_name: @domain.fqdn) | ||
@interactor = AuthorizeRequest | ||
end | ||
|
||
test "successful call" do | ||
request = CertIssueRequest.new(common_name: @domain.fqdn) | ||
srv = Minitest::Mock.new | ||
srv.expect :authorize!, nil, [ @identity, @cr ] | ||
Services::DomainOwnershipService.stub :new, srv do | ||
context = @interactor.call(identity: @identity, request: @cr) | ||
assert context.success? | ||
end | ||
end | ||
|
||
test "unsuccessful call" do | ||
request = CertIssueRequest.new(common_name: @domain.fqdn) | ||
srv = Services::DomainOwnershipService.new | ||
Services::DomainOwnershipService.stub :new, srv do | ||
err = ->(_, _) { raise AuthError.new "no can do" } | ||
srv.stub :authorize!, err do | ||
context = @interactor.call(identity: @identity, request: @cr) | ||
assert_not context.success? | ||
assert_kind_of AuthError, context.error | ||
end | ||
end | ||
end | ||
end |