-
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.
- Loading branch information
Showing
1 changed file
with
14 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,44 +2,34 @@ | |
|
||
class DomainOwnershipServiceTest < ActiveSupport::TestCase | ||
def setup | ||
@identity = Identity.new(subject: "[email protected]", groups: [ "admin_group" ]) | ||
@domain = Domain.new(owner: "[email protected]", group_delegation: false, groups: [ "admin_group" ]) | ||
@domain = domains(:group_match) | ||
@identity = Identity.new(subject: @domain.owner) | ||
@cr = CertIssueRequest.new(common_name: @domain.fqdn) | ||
@ds = Services::DomainOwnershipService.new | ||
end | ||
|
||
test "#authorize! with matching owner" do | ||
ds = Services::DomainOwnershipService.new | ||
ds.stub :get_domain_name, @domain do | ||
assert_nil(ds.authorize!(@identity, CertIssueRequest.new)) | ||
end | ||
assert_nil(@ds.authorize!(@identity, @cr)) | ||
end | ||
|
||
test "#authorize! with non-matching owner" do | ||
ds = Services::DomainOwnershipService.new | ||
@domain.owner = "[email protected]" | ||
ds.stub :get_domain_name, @domain do | ||
assert_raises(AuthError) do | ||
ds.authorize!(@identity, CertIssueRequest.new) | ||
end | ||
@identity.subject = "[email protected]" | ||
assert_raises(AuthError) do | ||
@ds.authorize!(@identity, @cr) | ||
end | ||
end | ||
|
||
test "#authorize! with matching group" do | ||
ds = Services::DomainOwnershipService.new | ||
@domain.owner = "[email protected]" | ||
@domain.group_delegation = true | ||
ds.stub :get_domain_name, @domain do | ||
assert_nil(ds.authorize!(@identity, CertIssueRequest.new)) | ||
end | ||
@domain.update(owner: "[email protected]") | ||
@identity.groups = @domain.groups | ||
assert_nil(@ds.authorize!(@identity, @cr)) | ||
end | ||
|
||
test "#authorize! with non-matching group" do | ||
ds = Services::DomainOwnershipService.new | ||
@domain.owner = "[email protected]" | ||
@domain.update(owner: "[email protected]") | ||
@identity.groups = [ "different_group" ] | ||
ds.stub :get_domain_name, @domain do | ||
assert_raises(AuthError) do | ||
ds.authorize!(@identity, CertIssueRequest.new) | ||
end | ||
assert_raises(AuthError) do | ||
@ds.authorize!(@identity, @cr) | ||
end | ||
end | ||
end |