chromium/net/dns/host_resolver_cache_unittest.cc

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

#include "net/dns/host_resolver_cache.h"

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/test/simple_test_clock.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/time/time.h"
#include "net/base/connection_endpoint_metadata.h"
#include "net/base/connection_endpoint_metadata_test_util.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/schemeful_site.h"
#include "net/dns/host_resolver_internal_result.h"
#include "net/dns/host_resolver_internal_result_test_util.h"
#include "net/dns/public/dns_query_type.h"
#include "net/dns/public/host_resolver_source.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace net {

namespace {

ElementsAre;
Eq;
IsEmpty;
Ne;
Optional;
Pair;
Pointee;

MATCHER(IsNotStale, "") {}

MATCHER_P(IsNotStale, result_matcher, "") {}

// Fudge TimeDelta matching by a couple milliseconds because it is not important
// whether something is considered expired at or just after expiration because
// TTLs come at second-wide precision anyway.
MATCHER_P(TimeDeltaIsApproximately, approximate_expectation, "") {}

MATCHER_P2(IsStale, expired_by_matcher, expected_stale_by_generation, "") {}

MATCHER_P3(IsStale,
           result_matcher,
           expired_by_matcher,
           expected_stale_by_generation,
           "") {}

class HostResolverCacheTest : public ::testing::Test {};

TEST_F(HostResolverCacheTest, CacheAResult) {}

TEST_F(HostResolverCacheTest, CacheAaaaResult) {}

TEST_F(HostResolverCacheTest, CacheHttpsResult) {}

// Domain names containing scheme/port are not expected to be handled any
// differently from other domain names. That is, if an entry is cached with
// a domain name containing scheme or port, it can only be looked up using the
// exact same domain name containing scheme and port. Testing the case simply
// because such things were handled differently in a previous version of the
// cache.
TEST_F(HostResolverCacheTest, RespectsSchemeAndPortInName) {}

TEST_F(HostResolverCacheTest, CacheHttpsAliasResult) {}

TEST_F(HostResolverCacheTest, CacheCnameAliasResult) {}

TEST_F(HostResolverCacheTest, CacheWildcardAlias) {}

TEST_F(HostResolverCacheTest, CacheErrorResult) {}

TEST_F(HostResolverCacheTest, ResultsCanBeUpdated) {}

TEST_F(HostResolverCacheTest, UpdateCanReplaceWildcard) {}

TEST_F(HostResolverCacheTest, WildcardUpdateCanReplaceSpecifics) {}

TEST_F(HostResolverCacheTest, LookupNameIsCanonicalized) {}

TEST_F(HostResolverCacheTest, LookupIgnoresExpiredResults) {}

TEST_F(HostResolverCacheTest, ExpiredResultsCanBeUpdated) {}

TEST_F(HostResolverCacheTest, LookupIgnoresResultsMarkedStale) {}

TEST_F(HostResolverCacheTest, MarkedStaleResultsCanBeUpdated) {}

TEST_F(HostResolverCacheTest, RespectsNetworkAnonymizationKey) {}

// Newly added entries are always considered to be the most up-to-date
// information, so if an unexpired entry is updated with an expired entry, the
// entry should now be expired.
TEST_F(HostResolverCacheTest, UpdateToStale) {}

// If a wildcard lookup matches multiple result entries, all insecure, expect
// lookup to return the most recently set result.
TEST_F(HostResolverCacheTest, PreferMoreRecentInsecureResult) {}

// If a wildcard lookup matches multiple result entries, all secure, expect
// lookup to return the most recently set result.
TEST_F(HostResolverCacheTest, PreferMoreRecentSecureResult) {}

// If a wildcard lookup matches multiple result entries of mixed secureness,
// expect lookup to return the most recently set secure result.
TEST_F(HostResolverCacheTest, PreferMoreSecureResult) {}

// Even though LookupStale() can return stale results, if a wildcard lookup
// matches multiple result entries, expect the lookup to prefer a non-stale
// result.
TEST_F(HostResolverCacheTest, LookupStalePrefersNonStaleResult) {}

// Same as LookupStalePrefersNonStaleResult except lookup criteria specifies
// insecure. Expect same general behavior (prefers non-stale result) but
// exercises slightly different logic because, if no secure results exist, no
// other results need to be considered once a non-stale result is found
TEST_F(HostResolverCacheTest, InsecureLookupStalePrefersNonStaleResult) {}

TEST_F(HostResolverCacheTest, LookupStalePrefersLeastStaleByGeneration) {}

TEST_F(HostResolverCacheTest, LookupStalePrefersLeastStaleByExpiration) {}

TEST_F(HostResolverCacheTest, LookupStalePrefersMostSecure) {}

// Same as LookupStalePrefersMostSecure except results are not stale. Expect
// same general behavior (secure result preferred) but exercises slightly
// different logic because no other results need to be considered once a
// non-stale secure result is found.
TEST_F(HostResolverCacheTest, LookupStalePrefersMostSecureNonStale) {}

TEST_F(HostResolverCacheTest, LookupStalePrefersMoreRecent) {}

TEST_F(HostResolverCacheTest, EvictStaleResults) {}

TEST_F(HostResolverCacheTest, EvictSoonestToExpireResult) {}

// If multiple results are equally soon-to-expire, expect least secure option to
// be evicted.
TEST_F(HostResolverCacheTest, EvictLeastSecureResult) {}

// If multiple results are equally soon-to-expire and equally (in)secure, expect
// oldest option to be evicted.
TEST_F(HostResolverCacheTest, EvictOldestResult) {}

// Even newly-added results that trigger eviction are themselves eligible for
// eviction if best candidate.
TEST_F(HostResolverCacheTest, EvictLatestResult) {}

TEST_F(HostResolverCacheTest, SerializeAndDeserialize) {}

TEST_F(HostResolverCacheTest, TransientAnonymizationKeyNotSerialized) {}

TEST_F(HostResolverCacheTest, DeserializePrefersExistingResults) {}

TEST_F(HostResolverCacheTest, DeserializeStopsBeforeEviction) {}

TEST_F(HostResolverCacheTest, SerializeForLogging) {}

}  // namespace
}  // namespace net