@ -71,7 +71,7 @@ func TestLinuxDNSMode(t *testing.T) {
{
{
name : "resolved_alone_without_ping" ,
name : "resolved_alone_without_ping" ,
env : env ( resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ) ,
env : env ( resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ) ,
wantLog : "dns: [rc=resolved nm=no ret=systemd-resolved]",
wantLog : "dns: ResolvConfMode error: dbus property not found\ndns: [rc=resolved nm=no resolv-conf-mode=error ret=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
{
{
@ -79,7 +79,7 @@ func TestLinuxDNSMode(t *testing.T) {
env : env (
env : env (
resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ,
resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ,
resolvedRunning ( ) ) ,
resolvedRunning ( ) ) ,
wantLog : "dns: [resolved-ping=yes rc=resolved nm=no re t=systemd-resolved]",
wantLog : "dns: [resolved-ping=yes rc=resolved nm=no re solv-conf-mode=fortests re t=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
{
{
@ -88,7 +88,7 @@ func TestLinuxDNSMode(t *testing.T) {
resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ,
resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ,
resolvedRunning ( ) ,
resolvedRunning ( ) ,
nmRunning ( "1.2.3" , false ) ) ,
nmRunning ( "1.2.3" , false ) ) ,
wantLog : "dns: [resolved-ping=yes rc=resolved nm=yes nm-resolved=no re t=systemd-resolved]",
wantLog : "dns: [resolved-ping=yes rc=resolved nm=yes nm-resolved=no re solv-conf-mode=fortests re t=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
{
{
@ -106,7 +106,7 @@ func TestLinuxDNSMode(t *testing.T) {
resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ,
resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ,
resolvedRunning ( ) ,
resolvedRunning ( ) ,
nmRunning ( "1.27.0" , true ) ) ,
nmRunning ( "1.27.0" , true ) ) ,
wantLog : "dns: [resolved-ping=yes rc=resolved nm=yes nm-resolved=yes nm-safe=no re t=systemd-resolved]",
wantLog : "dns: [resolved-ping=yes rc=resolved nm=yes nm-resolved=yes nm-safe=no re solv-conf-mode=fortests re t=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
{
{
@ -115,7 +115,7 @@ func TestLinuxDNSMode(t *testing.T) {
resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ,
resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ,
resolvedRunning ( ) ,
resolvedRunning ( ) ,
nmRunning ( "1.22.0" , true ) ) ,
nmRunning ( "1.22.0" , true ) ) ,
wantLog : "dns: [resolved-ping=yes rc=resolved nm=yes nm-resolved=yes nm-safe=no re t=systemd-resolved]",
wantLog : "dns: [resolved-ping=yes rc=resolved nm=yes nm-resolved=yes nm-safe=no re solv-conf-mode=fortests re t=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
// Regression tests for extreme corner cases below.
// Regression tests for extreme corner cases below.
@ -141,7 +141,7 @@ func TestLinuxDNSMode(t *testing.T) {
"nameserver 127.0.0.53" ,
"nameserver 127.0.0.53" ,
"nameserver 127.0.0.53" ) ,
"nameserver 127.0.0.53" ) ,
resolvedRunning ( ) ) ,
resolvedRunning ( ) ) ,
wantLog : "dns: [resolved-ping=yes rc=resolved nm=no re t=systemd-resolved]",
wantLog : "dns: [resolved-ping=yes rc=resolved nm=no re solv-conf-mode=fortests re t=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
{
{
@ -156,7 +156,7 @@ func TestLinuxDNSMode(t *testing.T) {
"# run \"systemd-resolve --status\" to see details about the actual nameservers." ,
"# run \"systemd-resolve --status\" to see details about the actual nameservers." ,
"nameserver 127.0.0.53" ) ,
"nameserver 127.0.0.53" ) ,
resolvedRunning ( ) ) ,
resolvedRunning ( ) ) ,
wantLog : "dns: [resolved-ping=yes rc=resolved nm=no re t=systemd-resolved]",
wantLog : "dns: [resolved-ping=yes rc=resolved nm=no re solv-conf-mode=fortests re t=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
{
{
@ -171,7 +171,7 @@ func TestLinuxDNSMode(t *testing.T) {
"# 127.0.0.53 is the systemd-resolved stub resolver." ,
"# 127.0.0.53 is the systemd-resolved stub resolver." ,
"# run \"systemd-resolve --status\" to see details about the actual nameservers." ,
"# run \"systemd-resolve --status\" to see details about the actual nameservers." ,
"nameserver 127.0.0.53" ) ) ,
"nameserver 127.0.0.53" ) ) ,
wantLog : "dns: [rc=resolved nm=no ret=systemd-resolved]",
wantLog : "dns: ResolvConfMode error: dbus property not found\ndns: [rc=resolved nm=no resolv-conf-mode=error ret=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
{
{
@ -183,7 +183,7 @@ func TestLinuxDNSMode(t *testing.T) {
"options edns0 trust-ad" ) ,
"options edns0 trust-ad" ) ,
resolvedRunning ( ) ,
resolvedRunning ( ) ,
nmRunning ( "1.32.12" , true ) ) ,
nmRunning ( "1.32.12" , true ) ) ,
wantLog : "dns: [resolved-ping=yes rc=nm nm-resolved=yes nm-safe=no re t=systemd-resolved]",
wantLog : "dns: [resolved-ping=yes rc=nm nm-resolved=yes nm-safe=no re solv-conf-mode=fortests re t=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
{
{
@ -194,7 +194,7 @@ func TestLinuxDNSMode(t *testing.T) {
"nameserver 127.0.0.53" ,
"nameserver 127.0.0.53" ,
"options edns0 trust-ad" ) ,
"options edns0 trust-ad" ) ,
nmRunning ( "1.32.12" , true ) ) ,
nmRunning ( "1.32.12" , true ) ) ,
wantLog : "dns: [rc=nm nm-resolved=yes nm-safe=no ret=systemd-resolved]",
wantLog : "dns: ResolvConfMode error: dbus property not found\ndns: [rc=nm nm-resolved=yes nm-safe=no resolv-conf-mode=error ret=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
{
{
@ -217,7 +217,7 @@ func TestLinuxDNSMode(t *testing.T) {
"nameserver 127.0.0.53" ,
"nameserver 127.0.0.53" ,
"options edns0 trust-ad" ) ,
"options edns0 trust-ad" ) ,
resolvedRunning ( ) ) ,
resolvedRunning ( ) ) ,
wantLog : "dns: [resolved-ping=yes rc=nm nm-resolved=yes nm=no re t=systemd-resolved]",
wantLog : "dns: [resolved-ping=yes rc=nm nm-resolved=yes nm=no re solv-conf-mode=fortests re t=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
{
{
@ -228,7 +228,7 @@ func TestLinuxDNSMode(t *testing.T) {
"search lan" ,
"search lan" ,
"nameserver 127.0.0.53" ) ,
"nameserver 127.0.0.53" ) ,
resolvedRunning ( ) ) ,
resolvedRunning ( ) ) ,
wantLog : "dns: [resolved-ping=yes rc=nm nm-resolved=yes nm=no re t=systemd-resolved]",
wantLog : "dns: [resolved-ping=yes rc=nm nm-resolved=yes nm=no re solv-conf-mode=fortests re t=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
{
{
@ -236,8 +236,9 @@ func TestLinuxDNSMode(t *testing.T) {
// before we read its file.
// before we read its file.
env : env ( resolvedStartOnPingAndThen (
env : env ( resolvedStartOnPingAndThen (
resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ,
resolvDotConf ( "# Managed by systemd-resolved" , "nameserver 127.0.0.53" ) ,
resolvedDbusProperty ( ) ,
) ) ,
) ) ,
wantLog : "dns: [resolved-ping=yes rc=resolved nm=no re t=systemd-resolved]",
wantLog : "dns: [resolved-ping=yes rc=resolved nm=no re solv-conf-mode=fortests re t=systemd-resolved]",
want : "systemd-resolved" ,
want : "systemd-resolved" ,
} ,
} ,
}
}
@ -306,9 +307,16 @@ type dbusService struct {
hook func ( ) // if non-nil, run on ping
hook func ( ) // if non-nil, run on ping
}
}
type dbusProperty struct {
name , path string
iface , member string
hook func ( ) ( string , error ) // what to return
}
type envBuilder struct {
type envBuilder struct {
fs memFS
fs memFS
dbus [ ] dbusService
dbus [ ] dbusService
dbusProperties [ ] dbusProperty
nmUsingResolved bool
nmUsingResolved bool
nmVersion string
nmVersion string
resolvconfStyle string
resolvconfStyle string
@ -345,6 +353,14 @@ func env(opts ...envOption) newOSConfigEnv {
}
}
return errors . New ( "dbus service not found" )
return errors . New ( "dbus service not found" )
} ,
} ,
dbusReadString : func ( name , path , iface , member string ) ( string , error ) {
for _ , svc := range b . dbusProperties {
if svc . name == name && svc . path == path && svc . iface == iface && svc . member == member {
return svc . hook ( )
}
}
return "" , errors . New ( "dbus property not found" )
} ,
nmIsUsingResolved : func ( ) error {
nmIsUsingResolved : func ( ) error {
if ! b . nmUsingResolved {
if ! b . nmUsingResolved {
return errors . New ( "networkmanager not using resolved" )
return errors . New ( "networkmanager not using resolved" )
@ -365,9 +381,16 @@ func resolvDotConf(ss ...string) envOption {
} )
} )
}
}
// resolvedRunning returns an option that makes resolved reply to a dbusPing.
// resolvedRunning returns an option that makes resolved reply to a dbusPing
// and the ResolvConfMode property.
func resolvedRunning ( ) envOption {
func resolvedRunning ( ) envOption {
return resolvedStartOnPingAndThen ( /* nothing */ )
return resolvedStartOnPingAndThen ( resolvedDbusProperty ( ) )
}
// resolvedDbusProperty returns an option that responds to the ResolvConfMode
// property that resolved exposes.
func resolvedDbusProperty ( ) envOption {
return setDbusProperty ( "org.freedesktop.resolve1" , "/org/freedesktop/resolve1" , "org.freedesktop.resolve1.Manager" , "ResolvConfMode" , "fortests" )
}
}
// resolvedStartOnPingAndThen returns an option that makes resolved be
// resolvedStartOnPingAndThen returns an option that makes resolved be
@ -400,3 +423,17 @@ func resolvconf(s string) envOption {
b . resolvconfStyle = s
b . resolvconfStyle = s
} )
} )
}
}
func setDbusProperty ( name , path , iface , member , value string ) envOption {
return envOpt ( func ( b * envBuilder ) {
b . dbusProperties = append ( b . dbusProperties , dbusProperty {
name : name ,
path : path ,
iface : iface ,
member : member ,
hook : func ( ) ( string , error ) {
return value , nil
} ,
} )
} )
}