Skip to content

Commit

Permalink
Testing for DomainOwnershipService
Browse files Browse the repository at this point in the history
  • Loading branch information
suprjinx committed Sep 11, 2024
1 parent f42ba46 commit 12e7833
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/app_reg_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"id": "example.com",
"fullyQualifiedDomainName": "example.com",
"ownerDelegatedRequestToTeam": true,
"ownerDelegatedRequestsToTeam": true,
"autoApprovedGroups": "group1",
"autoApprovedServiceAccounts": "[email protected]"
}
Expand Down
6 changes: 4 additions & 2 deletions app/lib/services/domain_ownership_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ def initialize
def get_domain_info(fqdn)
rslt = client.get("/api/v1beta1/domain-names/#{fqdn}").body
convert(rslt)
rescue Faraday::ResourceNotFound => e
nil
end

private

def convert(input)
if !input || input["isDeleted"]
def convert(domain_info)
if !domain_info || domain_info["isDeleted"]
return nil
end

Expand Down
17 changes: 17 additions & 0 deletions test/lib/services/domain_ownership_service_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
require "test_helper"

class DomainOwnershipServiceTest < ActiveSupport::TestCase
setup do
@subject = Services::DomainOwnershipService.new
end

test "#get_domain_info fetches from configured api server" do
domain_info = @subject.get_domain_info(domains(:owner_match).fqdn)
assert_not_nil domain_info
assert_equal "group1", domain_info.groups
assert_equal "[email protected]", domain_info.users
assert_equal "example.com", domain_info.fqdn
assert domain_info.group_delegation
end

test "#get_domain_info returns nil for unmatched fqdn" do
domain_info = @subject.get_domain_info(domains(:group_match).fqdn)
assert_nil domain_info
end
end

0 comments on commit 12e7833

Please sign in to comment.