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>
This commit is contained in:
parent
0e390765e3
commit
f4428aa600
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user