Skip to content

[management] Extend nameserver match domain validation #3864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2025

Conversation

bcmmbaga
Copy link
Contributor

Describe your changes

Issue ticket number and link

Closes #2021

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

@Copilot Copilot AI review requested due to automatic review settings May 22, 2025 13:39
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors domain validation to support single-label domains, top-level domains (prefixed with “.”), and wildcard domains, and updates tests accordingly.

  • validateDomain now handles TLDs and *.-wildcards and removes the two-label minimum
  • Introduced maxLabelLen, invalidDomainName, and a domainPattern regex (currently unused)
  • Added new test cases for single-label, TLD, and wildcard domains in nameserver_test.go

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
management/server/nameserver.go Extended validateDomain for TLDs & wildcards; added constants
management/server/nameserver_test.go Added tests for single-label, .com, and *.example; renamed cases
Comments suppressed due to low confidence (4)

management/server/nameserver.go:6

  • The regexp import is no longer used (the domainPattern regex isn’t referenced). Consider removing the import and the unused domainPattern constant to keep the code clean.
"regexp"

management/server/nameserver.go:23

  • The domainPattern constant is defined but never used. Either integrate it into validateDomain or remove it to prevent confusion.
domainPattern = `^(?i)[\.*a-z0-9]+([\-\.]{1}[a-z0-9]+)*[*.a-z]{1,}$`

management/server/nameserver_test.go:921

  • There’s no test case covering the behavior of a single-label domain without a dot or wildcard (e.g., "com"). Add a test to assert whether such domains should pass or fail.
// removed test for single-label "com"

management/server/nameserver.go:338

  • The original check enforcing a minimum of two labels for non-TLD domains was removed, so single-label domains like "com" will now be accepted. Verify whether this change matches the intended validation rules.
if !valid {

@bcmmbaga bcmmbaga force-pushed the update-ns-domain-validation branch from 3d89cd4 to 3e3268d Compare May 22, 2025 20:03
Copy link

@bcmmbaga bcmmbaga requested a review from Copilot May 22, 2025 20:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors domain validation logic and extends test coverage for various domain formats.

  • Removed the minimum label count check and centralized the error return in validateDomain.
  • Updated (but currently unused) domainPattern regex for domain matching.
  • Expanded TestValidateDomain with new scenarios (single-label, trailing dot, wildcard, leading dot, dot-only).

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
management/server/nameserver.go Refactored validateDomain, added invalidDomainName var, updated domainPattern
management/server/nameserver_test.go Extended and reordered test cases in TestValidateDomain
Comments suppressed due to low confidence (2)

management/server/nameserver.go:23

  • [nitpick] Rename invalidDomainName to ErrInvalidDomainName to follow Go conventions for error variable names.
var invalidDomainName = errors.New("invalid domain name")

management/server/nameserver_test.go:908

  • The test expects example. to pass, but dns.IsDomainName may reject trailing dots; verify the intention or adjust the test to match the actual validation behavior.
domain:  "example.",

@mlsmaycon mlsmaycon merged commit 2a89d6e into main May 22, 2025
63 of 66 checks passed
@mlsmaycon mlsmaycon deleted the update-ns-domain-validation branch May 22, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nameserver cannot be scoped to TLD
2 participants