Skip to content

Commit

Permalink
update test to use db Domain
Browse files Browse the repository at this point in the history
  • Loading branch information
suprjinx committed Sep 6, 2024
1 parent 49c2eda commit 212fa87
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions test/lib/services/domain_ownership_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 212fa87

Please sign in to comment.