Because:
- it's the last thing outside 'daemon/' that uses libnetwork's
resolvconf package
- there's better coverage of the host resolv.conf transformations
in the resolvconf package's unit tests
- there are integration tests that don't modify the test host's
resolv.conf file in 'integration/networking/resolvconf_test.go'
Signed-off-by: Rob Murray <rob.murray@docker.com>
| ... | ... |
@@ -23,7 +23,6 @@ import ( |
| 23 | 23 |
"testing" |
| 24 | 24 |
"time" |
| 25 | 25 |
|
| 26 |
- "github.com/docker/docker/daemon/libnetwork/resolvconf" |
|
| 27 | 26 |
"github.com/docker/docker/integration-cli/cli" |
| 28 | 27 |
"github.com/docker/docker/integration-cli/cli/build" |
| 29 | 28 |
"github.com/docker/docker/integration-cli/daemon" |
| ... | ... |
@@ -1323,85 +1322,6 @@ func (s *DockerCLIRunSuite) TestRunDNSRepeatOptions(c *testing.T) {
|
| 1323 | 1323 |
} |
| 1324 | 1324 |
} |
| 1325 | 1325 |
|
| 1326 |
-func (s *DockerCLIRunSuite) TestRunDNSOptionsBasedOnHostResolvConf(c *testing.T) {
|
|
| 1327 |
- // Not applicable on Windows as testing Unix specific functionality |
|
| 1328 |
- testRequires(c, testEnv.IsLocalDaemon, DaemonIsLinux) |
|
| 1329 |
- |
|
| 1330 |
- origResolvConf, err := os.ReadFile("/etc/resolv.conf")
|
|
| 1331 |
- if os.IsNotExist(err) {
|
|
| 1332 |
- c.Fatalf("/etc/resolv.conf does not exist")
|
|
| 1333 |
- } |
|
| 1334 |
- |
|
| 1335 |
- hostNameservers := resolvconf.GetNameservers(origResolvConf, resolvconf.IP) |
|
| 1336 |
- hostSearch := resolvconf.GetSearchDomains(origResolvConf) |
|
| 1337 |
- |
|
| 1338 |
- out := cli.DockerCmd(c, "run", "--dns=127.0.0.1", "busybox", "cat", "/etc/resolv.conf").Combined() |
|
| 1339 |
- |
|
| 1340 |
- if actualNameservers := resolvconf.GetNameservers([]byte(out), resolvconf.IP); actualNameservers[0] != "127.0.0.1" {
|
|
| 1341 |
- c.Fatalf("expected '127.0.0.1', but says: %q", actualNameservers[0])
|
|
| 1342 |
- } |
|
| 1343 |
- |
|
| 1344 |
- actualSearch := resolvconf.GetSearchDomains([]byte(out)) |
|
| 1345 |
- if len(actualSearch) != len(hostSearch) {
|
|
| 1346 |
- c.Fatalf("expected %q search domain(s), but it has: %q", len(hostSearch), len(actualSearch))
|
|
| 1347 |
- } |
|
| 1348 |
- for i := range actualSearch {
|
|
| 1349 |
- if actualSearch[i] != hostSearch[i] {
|
|
| 1350 |
- c.Fatalf("expected %q domain, but says: %q", actualSearch[i], hostSearch[i])
|
|
| 1351 |
- } |
|
| 1352 |
- } |
|
| 1353 |
- |
|
| 1354 |
- out = cli.DockerCmd(c, "run", "--dns-search=mydomain", "busybox", "cat", "/etc/resolv.conf").Combined() |
|
| 1355 |
- |
|
| 1356 |
- actualNameservers := resolvconf.GetNameservers([]byte(out), resolvconf.IP) |
|
| 1357 |
- if len(actualNameservers) != len(hostNameservers) {
|
|
| 1358 |
- c.Fatalf("expected %q nameserver(s), but it has: %q", len(hostNameservers), len(actualNameservers))
|
|
| 1359 |
- } |
|
| 1360 |
- for i := range actualNameservers {
|
|
| 1361 |
- if actualNameservers[i] != hostNameservers[i] {
|
|
| 1362 |
- c.Fatalf("expected %q nameserver, but says: %q", actualNameservers[i], hostNameservers[i])
|
|
| 1363 |
- } |
|
| 1364 |
- } |
|
| 1365 |
- |
|
| 1366 |
- if actualSearch = resolvconf.GetSearchDomains([]byte(out)); actualSearch[0] != "mydomain" {
|
|
| 1367 |
- c.Fatalf("expected 'mydomain', but says: %q", actualSearch[0])
|
|
| 1368 |
- } |
|
| 1369 |
- |
|
| 1370 |
- // test with file |
|
| 1371 |
- tmpResolvConf := []byte("search example.com\nnameserver 12.34.56.78\nnameserver 127.0.0.1")
|
|
| 1372 |
- if err := os.WriteFile("/etc/resolv.conf", tmpResolvConf, 0o644); err != nil {
|
|
| 1373 |
- c.Fatal(err) |
|
| 1374 |
- } |
|
| 1375 |
- // put the old resolvconf back |
|
| 1376 |
- defer func() {
|
|
| 1377 |
- if err := os.WriteFile("/etc/resolv.conf", origResolvConf, 0o644); err != nil {
|
|
| 1378 |
- c.Fatal(err) |
|
| 1379 |
- } |
|
| 1380 |
- }() |
|
| 1381 |
- |
|
| 1382 |
- resolvConf, err := os.ReadFile("/etc/resolv.conf")
|
|
| 1383 |
- if os.IsNotExist(err) {
|
|
| 1384 |
- c.Fatalf("/etc/resolv.conf does not exist")
|
|
| 1385 |
- } |
|
| 1386 |
- |
|
| 1387 |
- hostSearch = resolvconf.GetSearchDomains(resolvConf) |
|
| 1388 |
- |
|
| 1389 |
- out = cli.DockerCmd(c, "run", "busybox", "cat", "/etc/resolv.conf").Combined() |
|
| 1390 |
- if actualNameservers = resolvconf.GetNameservers([]byte(out), resolvconf.IP); actualNameservers[0] != "12.34.56.78" || len(actualNameservers) != 1 {
|
|
| 1391 |
- c.Fatalf("expected '12.34.56.78', but has: %v", actualNameservers)
|
|
| 1392 |
- } |
|
| 1393 |
- |
|
| 1394 |
- actualSearch = resolvconf.GetSearchDomains([]byte(out)) |
|
| 1395 |
- if len(actualSearch) != len(hostSearch) {
|
|
| 1396 |
- c.Fatalf("expected %q search domain(s), but it has: %q", len(hostSearch), len(actualSearch))
|
|
| 1397 |
- } |
|
| 1398 |
- for i := range actualSearch {
|
|
| 1399 |
- if actualSearch[i] != hostSearch[i] {
|
|
| 1400 |
- c.Fatalf("expected %q domain, but says: %q", actualSearch[i], hostSearch[i])
|
|
| 1401 |
- } |
|
| 1402 |
- } |
|
| 1403 |
-} |
|
| 1404 |
- |
|
| 1405 | 1326 |
// Test to see if a non-root user can resolve a DNS name. Also |
| 1406 | 1327 |
// check if the container resolv.conf file has at least 0644 perm. |
| 1407 | 1328 |
func (s *DockerCLIRunSuite) TestRunNonRootUserResolvName(c *testing.T) {
|