Repository: amplify-education/serverless-domain-manager (ts)

Issue:
Hosted Zone name matching broken in v7.3.1
<!--- Please keep this note for the community --->

### Community Note

* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
* Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
* If you are interested in working on this issue or have submitted a pull request, please leave a comment

<!--- Thank you for keeping this note for the community --->

## Bug Report

**Error Description**
Custom domain creation fails when the hosted zone and the domain are the same.

For example, if an API has the domain `api.example.com` and the hosted zone is `api.example.com.`.

The following error is thrown: `Could not find hosted zone 'api.example.com'`

This bug has been introduced in v7.3.1; it works OK in v7.3.0

**Command Run**
`sls create_domain`

**Console Output**
```sh
Error: Unable to create domain '[REDACTED]':
Could not find hosted zone '[REDACTED]'
    at ServerlessCustomDomain.<anonymous> (/[REDACTED]/node_modules/serverless-domain-manager/dist/src/index.js:258:23)
    at Generator.throw (<anonymous>)
    at rejected (/[REDACTED]/node_modules/serverless-domain-manager/dist/src/index.js:6:65)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
```

**Domain Manager Configuration**
Replace this with your own `serverless.yml` file (anonymized, of course) to help us better resolve your issue.
```yaml
custom:
  customDomain:
    domainName: api.example.com
    createRoute53Record: true
```

**Versions**
- Domain Manager version(s): v7.3.1
- Node/npm version: Node 18
- Serverless Version: v3.38
- Lambda Code Javascript

**Possible Solution**
<!--- Only if you have suggestions on a fix for the bug -->

**Additional context/Screenshots**



Pull request description:
Hosted zone filtering fix
<!--- Information about referencing Github Issues: https://help.github.com/articles/basic-writing-and-formatting-syntax/#referencing-issues-and-pull-requests --->
Fixes #607 

**Description of Issue Fixed**
Hosted zone filtering fix

**Changes proposed in this pull request**:

* Hosted zone filtering fix
* Updated tests

<!--- Please remember to allow edits from maintainers: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork --->


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 239a1ac..f9cccbf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,10 +4,15 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
 
+## [7.3.2] - 2023-12-07
+
+### Fixed 
+- Fixed hosted zone filtering, when the domain `api.mydomain.com` equals the host name `api.mydomain.com`.
+
 ## [7.3.1] - 2023-12-01
 
 ### Fixed 
-- Fixed hosted zone filtering.
+- Fixed hosted zone filtering, when the domain `serverlessdevapi.mydomain.com` contains the host name `api.mydomain.com`.
 
 ## [7.3.0] - 2023-11-30
 
diff --git a/package.json b/package.json
index 557e01c..52e3f58 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "serverless-domain-manager",
-  "version": "7.3.1",
+  "version": "7.3.2",
   "engines": {
     "node": ">=14"
   },
diff --git a/src/aws/route53-wrapper.ts b/src/aws/route53-wrapper.ts
index f93f817..269d827 100644
--- a/src/aws/route53-wrapper.ts
+++ b/src/aws/route53-wrapper.ts
@@ -69,7 +69,7 @@ class Route53Wrapper {
             })
             .filter((hostedZone) => {
                 const hostedZoneName = hostedZone.Name.replace(/\.$/, "");
-                return domainNameHost.endsWith(hostedZoneName);
+                return domain.givenDomainName === hostedZoneName || domainNameHost.endsWith(hostedZoneName);
             })
             .sort((zone1, zone2) => zone2.Name.length - zone1.Name.length)
             .shift();


Test patch:
diff --git a/test/unit-tests/aws/route53-wrapper.test.ts b/test/unit-tests/aws/route53-wrapper.test.ts
index 0f9f3c4..6378754 100644
--- a/test/unit-tests/aws/route53-wrapper.test.ts
+++ b/test/unit-tests/aws/route53-wrapper.test.ts
@@ -169,13 +169,13 @@ describe("Route53 wrapper checks", () => {
                     Name: "api.test_domain",
                 }, {
                     CallerReference: "",
-                    Config: {PrivateZone: true},
-                    Id: "dummy_host_id",
-                    Name: "test_domain",
+                    Config: {PrivateZone: false},
+                    Id: testId,
+                    Name: "devapi.test_domain",
                 }, {
                     CallerReference: "",
                     Config: {PrivateZone: false},
-                    Id: testId,
+                    Id: "dummy_host_id",
                     Name: "test_domain",
                 },
             ]