From f4428aa60043b6b39ad4b34e68e756524c2b3885 Mon Sep 17 00:00:00 2001 From: lif <1835304752@qq.com> Date: Wed, 1 Apr 2026 08:02:04 +0800 Subject: [PATCH] fix(client): return error from rdapQuery when no expiration event found (#1603) * fix: return error from rdapQuery when no expiration event found When an RDAP response has no expiration event, rdapQuery returned a zero-value ExpirationDate with nil error. This prevented GetDomainExpiration from falling back to WHOIS, causing failures for TLDs like .net where RDAP may omit the expiration event. Signed-off-by: majiayu000 <1835304752@qq.com> * fix: include hostname in RDAP error and add .net domain tests Add .net domain test cases to TestRdapQuery and TestGetDomainExpiration to cover the fallback path when RDAP lacks an expiration event (#1570). Include hostname in the error message for easier debugging. Signed-off-by: majiayu000 <1835304752@qq.com> --------- Signed-off-by: majiayu000 <1835304752@qq.com> --- client/client.go | 3 +++ client/client_test.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/client/client.go b/client/client.go index 825cab42..00a2af44 100644 --- a/client/client.go +++ b/client/client.go @@ -528,6 +528,9 @@ func rdapQuery(hostname string) (*whois.Response, error) { break } } + if response.ExpirationDate.IsZero() { + return nil, fmt.Errorf("no expiration event found in RDAP response for %s", hostname) + } return &response, nil } diff --git a/client/client_test.go b/client/client_test.go index aac17183..a6021c1c 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -55,6 +55,13 @@ func TestRdapQuery(t *testing.T) { } else if response.ExpirationDate.Unix() <= 0 { t.Error("expected to have a valid expiry date, got", response.ExpirationDate.Unix()) } + // .net domain: rdapQuery must either return a valid expiration or an error, + // but never silently return a zero-value expiration date (the bug in #1570) + if response, err := rdapQuery("google.net"); err != nil { + t.Logf("rdapQuery returned error for .net domain (fallback to WHOIS expected): %s", err) + } else if response.ExpirationDate.IsZero() { + t.Error("rdapQuery returned a zero expiration date without an error for .net domain") + } } func TestGetDomainExpiration(t *testing.T) { @@ -83,6 +90,12 @@ func TestGetDomainExpiration(t *testing.T) { } else if domainExpiration <= 0 { t.Error("expected domain expiration to be higher than 0") } + // .net domain: should succeed via RDAP or WHOIS fallback (#1570) + if domainExpiration, err := GetDomainExpiration("google.net"); err != nil { + t.Errorf("expected error to be nil for .net domain, but got: `%s`", err) + } else if domainExpiration <= 0 { + t.Error("expected domain expiration to be higher than 0 for .net domain") + } } func TestPing(t *testing.T) {