chromium/net/dns/dns_config_service_linux_unittest.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "net/dns/dns_config_service_linux.h"

#include <arpa/inet.h>
#include <resolv.h>

#include <memory>
#include <optional>
#include <utility>
#include <vector>

#include "base/cancelable_callback.h"
#include "base/check.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/sys_byteorder.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "base/test/test_waitable_event.h"
#include "net/base/ip_address.h"
#include "net/base/test_completion_callback.h"
#include "net/dns/dns_config.h"
#include "net/dns/dns_config_service.h"
#include "net/dns/nsswitch_reader.h"
#include "net/dns/public/dns_protocol.h"
#include "net/test/test_with_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace net {

namespace {

// MAXNS is normally 3, but let's test 4 if possible.
const char* const kNameserversIPv4[] =;

const char* const kNameserversIPv6[] =;

const std::vector<NsswitchReader::ServiceSpecification> kBasicNsswitchConfig =;

void DummyConfigCallback(const DnsConfig& config) {}

// Fills in |res| with sane configuration.
void InitializeResState(res_state res) {}

void InitializeExpectedConfig(DnsConfig* config) {}

class CallbackHelper {};

// Helper to allow blocking on some point in the ThreadPool.
class BlockingHelper {};

class TestScopedResState : public ScopedResState {};

class TestResolvReader : public ResolvReader {};

class TestNsswitchReader : public NsswitchReader {};

class DnsConfigServiceLinuxTest : public ::testing::Test,
                                  public WithTaskEnvironment {};

// Regression test to verify crash does not occur if DnsConfigServiceLinux
// instance is destroyed without calling WatchConfig()
TEST_F(DnsConfigServiceLinuxTest, CreateAndDestroy) {}

TEST_F(DnsConfigServiceLinuxTest, ConvertResStateToDnsConfig) {}

TEST_F(DnsConfigServiceLinuxTest, RejectEmptyNameserver) {}

TEST_F(DnsConfigServiceLinuxTest, AcceptNonEmptyNameserver) {}

// Regression test to verify crash does not occur if DnsConfigServiceLinux
// instance is destroyed while SerialWorker jobs have posted to worker pool.
TEST_F(DnsConfigServiceLinuxTest, DestroyWhileJobsWorking) {}

// Regression test to verify crash does not occur if DnsConfigServiceLinux
// instance is destroyed on another thread.
TEST_F(DnsConfigServiceLinuxTest, DestroyOnDifferentThread) {}

TEST_F(DnsConfigServiceLinuxTest, AcceptsBasicNsswitchConfig) {}

TEST_F(DnsConfigServiceLinuxTest,
       IgnoresBasicNsswitchConfigIfResolvConfigUnhandled) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsNsswitchWithoutFiles) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsWithExtraFiles) {}

TEST_F(DnsConfigServiceLinuxTest, IgnoresRedundantActions) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsInconsistentActions) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsWithBadFilesSuccessAction) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsWithBadFilesNotFoundAction) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsNsswitchWithoutDns) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsWithBadDnsSuccessAction) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsNsswitchWithMisorderedServices) {}

TEST_F(DnsConfigServiceLinuxTest, AcceptsIncompatibleNsswitchServicesAfterDns) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsNsswitchMdns) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsNsswitchMdns4) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsNsswitchMdns6) {}

TEST_F(DnsConfigServiceLinuxTest, AcceptsNsswitchMdnsMinimal) {}

// mdns*_minimal is often paired with [!UNAVAIL=RETURN] or [NOTFOUND=RETURN]
// actions. Ensure that is accepted.
TEST_F(DnsConfigServiceLinuxTest, AcceptsNsswitchMdnsMinimalWithCommonActions) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsWithBadMdnsMinimalUnavailableAction) {}

TEST_F(DnsConfigServiceLinuxTest, AcceptsNsswitchMyHostname) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsWithBadMyHostnameNotFoundAction) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsNsswitchResolve) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsNsswitchNis) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsWithBadNisNotFoundAction) {}

TEST_F(DnsConfigServiceLinuxTest, RejectsNsswitchUnknown) {}

TEST_F(DnsConfigServiceLinuxTest, FreshReadsAfterAdditionalTriggers) {}

}  // namespace

}  // namespace net