From 12e78333c94e5e2fd4d1dbf9c1c8d1c157541781 Mon Sep 17 00:00:00 2001 From: Geoff Wilson Date: Wed, 11 Sep 2024 17:36:44 -0400 Subject: [PATCH] Testing for DomainOwnershipService --- .devcontainer/app_reg_db.json | 2 +- app/lib/services/domain_ownership_service.rb | 6 ++++-- .../services/domain_ownership_service_test.rb | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.devcontainer/app_reg_db.json b/.devcontainer/app_reg_db.json index c5a452e..3f08c71 100644 --- a/.devcontainer/app_reg_db.json +++ b/.devcontainer/app_reg_db.json @@ -3,7 +3,7 @@ { "id": "example.com", "fullyQualifiedDomainName": "example.com", - "ownerDelegatedRequestToTeam": true, + "ownerDelegatedRequestsToTeam": true, "autoApprovedGroups": "group1", "autoApprovedServiceAccounts": "john.doe@example.com" } diff --git a/app/lib/services/domain_ownership_service.rb b/app/lib/services/domain_ownership_service.rb index 33bd7fc..80db2e4 100644 --- a/app/lib/services/domain_ownership_service.rb +++ b/app/lib/services/domain_ownership_service.rb @@ -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 diff --git a/test/lib/services/domain_ownership_service_test.rb b/test/lib/services/domain_ownership_service_test.rb index a3c856f..e87481b 100644 --- a/test/lib/services/domain_ownership_service_test.rb +++ b/test/lib/services/domain_ownership_service_test.rb @@ -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 "john.doe@example.com", 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