1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #2212 from thaJeztah/fix_duplicate_ndots

Fix duplicate ndots:0, and improve validation
This commit is contained in:
Flavio Crisciani 2018-06-29 10:28:22 -07:00 committed by GitHub
commit abc4c5c5d8
2 changed files with 38 additions and 8 deletions

View file

@ -369,11 +369,13 @@ dnsOpt:
return fmt.Errorf("invalid ndots option %v", option)
}
if num, err := strconv.Atoi(parts[1]); err != nil {
return fmt.Errorf("invalid number for ndots option %v", option)
} else if num > 0 {
return fmt.Errorf("invalid number for ndots option: %v", parts[1])
} else if num >= 0 {
// if the user sets ndots, use the user setting
sb.ndotsSet = true
break dnsOpt
} else {
return fmt.Errorf("invalid number for ndots option: %v", num)
}
}
}

View file

@ -62,8 +62,8 @@ func TestDNSOptions(t *testing.T) {
currRC, err := resolvconf.GetSpecific(sb.(*sandbox).config.resolvConfPath)
require.NoError(t, err)
dnsOptionsList := resolvconf.GetOptions(currRC.Content)
assert.Equal(t, 1, len(dnsOptionsList), "There should be only 1 option instead:", dnsOptionsList)
assert.Equal(t, "ndots:0", dnsOptionsList[0], "The option must be ndots:0 instead:", dnsOptionsList[0])
assert.Equal(t, 1, len(dnsOptionsList))
assert.Equal(t, "ndots:0", dnsOptionsList[0])
sb.(*sandbox).config.dnsOptionsList = []string{"ndots:5"}
err = sb.(*sandbox).setupDNS()
@ -71,14 +71,42 @@ func TestDNSOptions(t *testing.T) {
currRC, err = resolvconf.GetSpecific(sb.(*sandbox).config.resolvConfPath)
require.NoError(t, err)
dnsOptionsList = resolvconf.GetOptions(currRC.Content)
assert.Equal(t, 1, len(dnsOptionsList), "There should be only 1 option instead:", dnsOptionsList)
assert.Equal(t, "ndots:5", dnsOptionsList[0], "The option must be ndots:5 instead:", dnsOptionsList[0])
assert.Equal(t, 1, len(dnsOptionsList))
assert.Equal(t, "ndots:5", dnsOptionsList[0])
err = sb.(*sandbox).rebuildDNS()
require.NoError(t, err)
currRC, err = resolvconf.GetSpecific(sb.(*sandbox).config.resolvConfPath)
require.NoError(t, err)
dnsOptionsList = resolvconf.GetOptions(currRC.Content)
assert.Equal(t, 1, len(dnsOptionsList), "There should be only 1 option instead:", dnsOptionsList)
assert.Equal(t, "ndots:5", dnsOptionsList[0], "The option must be ndots:5 instead:", dnsOptionsList[0])
assert.Equal(t, 1, len(dnsOptionsList))
assert.Equal(t, "ndots:5", dnsOptionsList[0])
sb2, err := c.(*controller).NewSandbox("cnt2", nil)
require.NoError(t, err)
defer sb2.Delete()
sb2.(*sandbox).startResolver(false)
sb2.(*sandbox).config.dnsOptionsList = []string{"ndots:0"}
err = sb2.(*sandbox).setupDNS()
require.NoError(t, err)
err = sb2.(*sandbox).rebuildDNS()
require.NoError(t, err)
currRC, err = resolvconf.GetSpecific(sb2.(*sandbox).config.resolvConfPath)
require.NoError(t, err)
dnsOptionsList = resolvconf.GetOptions(currRC.Content)
assert.Equal(t, 1, len(dnsOptionsList))
assert.Equal(t, "ndots:0", dnsOptionsList[0])
sb2.(*sandbox).config.dnsOptionsList = []string{"ndots:foobar"}
err = sb2.(*sandbox).setupDNS()
require.NoError(t, err)
err = sb2.(*sandbox).rebuildDNS()
require.EqualError(t, err, "invalid number for ndots option: foobar")
sb2.(*sandbox).config.dnsOptionsList = []string{"ndots:-1"}
err = sb2.(*sandbox).setupDNS()
require.NoError(t, err)
err = sb2.(*sandbox).rebuildDNS()
require.EqualError(t, err, "invalid number for ndots option: -1")
}