fix: ensure ipv4 is checked, not sometimes ipv6
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
See coop-cloud/organising#490
This commit is contained in:
parent
379915587c
commit
422c642949
|
@ -7,11 +7,16 @@ import (
|
||||||
|
|
||||||
// EnsureIPv4 ensures that an ipv4 address is set for a domain name
|
// EnsureIPv4 ensures that an ipv4 address is set for a domain name
|
||||||
func EnsureIPv4(domainName string) (string, error) {
|
func EnsureIPv4(domainName string) (string, error) {
|
||||||
ipv4, err := net.ResolveIPAddr("ip", domainName)
|
ipv4, err := net.ResolveIPAddr("ip4", domainName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE(d1): e.g. when there is only an ipv6 record available
|
||||||
|
if ipv4 == nil {
|
||||||
|
return "", fmt.Errorf("unable to resolve ipv4 address for %s", domainName)
|
||||||
|
}
|
||||||
|
|
||||||
return ipv4.String(), nil
|
return ipv4.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package dns
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"gotest.tools/v3/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEnsureDomainsResolveSameIPv4(t *testing.T) {
|
func TestEnsureDomainsResolveSameIPv4(t *testing.T) {
|
||||||
|
@ -11,9 +13,10 @@ func TestEnsureDomainsResolveSameIPv4(t *testing.T) {
|
||||||
serverName string
|
serverName string
|
||||||
shouldValidate bool
|
shouldValidate bool
|
||||||
}{
|
}{
|
||||||
// NOTE(d1): DNS records get checked, so use something we control. if
|
// NOTE(d1): DNS records get checked, so use something that is maintained
|
||||||
// you're here because of a failing test, try `dig +short <domain>` to
|
// within the federation. if you're here because of a failing test, try
|
||||||
// ensure stuff matches first!
|
// `dig +short <domain>` to ensure stuff matches first! If flakyness
|
||||||
|
// becomes an issue we can look into mocking
|
||||||
{"docs.coopcloud.tech", "coopcloud.tech", true},
|
{"docs.coopcloud.tech", "coopcloud.tech", true},
|
||||||
{"docs.coopcloud.tech", "swarm.autonomic.zone", true},
|
{"docs.coopcloud.tech", "swarm.autonomic.zone", true},
|
||||||
|
|
||||||
|
@ -36,3 +39,26 @@ func TestEnsureDomainsResolveSameIPv4(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEnsureIpv4(t *testing.T) {
|
||||||
|
// NOTE(d1): DNS records get checked, so use something that is maintained
|
||||||
|
// within the federation. if you're here because of a failing test, try `dig
|
||||||
|
// +short <domain>` to ensure stuff matches first! If flakyness becomes an
|
||||||
|
// issue we can look into mocking
|
||||||
|
domainName := "collabora.ostrom.collective.tools"
|
||||||
|
serverName := "ostrom.collective.tools"
|
||||||
|
|
||||||
|
for i := 0; i < 15; i++ {
|
||||||
|
domainIpv4, err := EnsureIPv4(domainName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
serverIpv4, err := EnsureIPv4(serverName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, domainIpv4, serverIpv4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue