#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "services/network/mdns_responder.h"
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "mojo/public/cpp/bindings/connector.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/ip_address.h"
#include "net/base/net_errors.h"
#include "net/dns/dns_names_util.h"
#include "net/dns/dns_query.h"
#include "net/dns/dns_response.h"
#include "net/dns/mock_mdns_socket_factory.h"
#include "net/dns/public/dns_protocol.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/mdns_responder.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace network {
namespace {
_;
AnyNumber;
AtLeast;
Invoke;
NiceMock;
Return;
ServiceError;
const net::IPAddress kPublicAddrs[2] = …;
const net::IPAddress kPublicAddrsIpv6[2] = …;
const base::TimeDelta kDefaultTtl = …;
const int kNumAnnouncementsPerInterface = …;
const int kNumMaxRetriesPerResponse = …;
const char kMdnsNameGeneratorServiceInstanceName[] = …;
std::string CreateMdnsQuery(uint16_t query_id,
const std::string& dotted_name,
uint16_t qtype = net::dns_protocol::kTypeA) { … }
std::string CreateResolutionResponse(
const base::TimeDelta& ttl,
const std::map<std::string, net::IPAddress>& name_addr_map) { … }
std::string CreateNegativeResponse(
const std::map<std::string, net::IPAddress>& name_addr_map) { … }
std::string CreateResponseToMdnsNameGeneratorServiceQuery(
const base::TimeDelta& ttl,
const std::set<std::string>& names) { … }
std::string CreateResponseToMdnsNameGeneratorServiceQueryWithCacheFlush(
const std::set<std::string>& names) { … }
class MockFailingMdnsSocketFactory : public net::MDnsSocketFactory { … };
}
TEST(CreateMdnsResponseTest, SingleARecordAnswer) { … }
TEST(CreateMdnsResponseTest, SingleARecordGoodbye) { … }
TEST(CreateMdnsResponseTest, SingleQuadARecordAnswer) { … }
TEST(CreateMdnsResponseTest, SingleNsecRecordAnswer) { … }
TEST(CreateMdnsResponseTest,
SingleTxtRecordAnswerToMdnsNameGeneratorServiceQuery) { … }
class SimpleNameGenerator : public MdnsResponderManager::NameGenerator { … };
class MdnsResponderTest : public testing::Test { … };
TEST_F(MdnsResponderTest, PersistentNameAddressMapForTheSameClient) { … }
TEST_F(MdnsResponderTest, NameAddressMapCanBeRemovedByOwningClient) { … }
TEST_F(MdnsResponderTest,
NameAddressMapCanOnlyBeRemovedWhenReachingZeroRefcount) { … }
TEST_F(MdnsResponderTest, ClientsHaveIsolatedNameSpaceForAddresses) { … }
TEST_F(MdnsResponderTest,
CreatingNameForAddressOnlySendsAnnouncementForNewName) { … }
TEST_F(MdnsResponderTest,
CreatingNamesForSameAddressButTwoClientsSendsDistinctAnnouncements) { … }
TEST_F(MdnsResponderTest,
RemovingNameForAddressOnlySendsResponseWithZeroTtlForExistingName) { … }
TEST_F(MdnsResponderTest, SendResponseToQueryForOwnedName) { … }
TEST_F(MdnsResponderTest, SendNoResponseToQueryForRemovedName) { … }
TEST_F(MdnsResponderTest, SendNegativeResponseToQueryForNonAddressRecord) { … }
TEST_F(MdnsResponderTest,
SendResponseToMdnsNameGeneratorServiceQueryWithAllExistingNames) { … }
TEST_F(MdnsResponderTest,
HostClosesMojoConnectionWhenCreatingNameForInvalidAddress) { … }
TEST_F(MdnsResponderTest,
HostClosesMojoConnectionAfterObservingAddressNameConflict) { … }
TEST_F(MdnsResponderTest,
StopRespondingToGeneratorServiceQueryAfterObservingTxtNameConflict) { … }
TEST_F(MdnsResponderTest,
NoConflictResolutionIfCacheFlushBitSetInExternalResponse) { … }
TEST_F(MdnsResponderTest,
CancelResponseToGeneratorServiceQueryAfterObservingTxtNameConflict) { … }
TEST_F(MdnsResponderTest,
SendGoodbyeForMdnsNameGeneratorServiceAfterManagerDestroyed) { … }
TEST_F(MdnsResponderTest,
NoGoodbyeForMdnsNameGeneratorServiceIfNoPreviousServiceResponseSent) { … }
TEST_F(MdnsResponderTest, ResponderHostDoesCleanUpAfterMojoConnectionError) { … }
TEST_F(MdnsResponderTest, ClosesBindingWhenNoSocketHanlderStarted) { … }
TEST_F(MdnsResponderTest, AnnouncementRetriedAfterSendFailure) { … }
TEST_F(MdnsResponderTest, AnnouncementsAreRateLimitedPerResponse) { … }
TEST_F(MdnsResponderTest, GoodbyesAreRateLimitedPerResponse) { … }
TEST_F(MdnsResponderTest, AnnouncementsAndGoodbyesAreRateLimitedPerResponse) { … }
TEST_F(MdnsResponderTest,
MdnsNameGeneratorServiceResponsesAreRateLimitedPerRecord) { … }
TEST_F(MdnsResponderTest, ResolutionResponsesAreRateLimitedPerRecord) { … }
TEST_F(MdnsResponderTest, NegativeResponsesAreRateLimitedPerRecord) { … }
TEST_F(MdnsResponderTest,
ResolutionAndNegativeResponsesAreRateLimitedPerRecord) { … }
TEST_F(MdnsResponderTest, ResponsesToProbesAreNotRateLimited) { … }
TEST_F(MdnsResponderTest, RateLimitSchemesDoNotInterfere) { … }
TEST_F(MdnsResponderTest, LongDelayedAnnouncementIsNotScheduled) { … }
TEST_F(MdnsResponderTest, ScheduledSendsAreCancelledAfterManagerDestroyed) { … }
TEST_F(MdnsResponderTest, ManagerCanRestartAfterAllSocketHandlersFailToRead) { … }
TEST_F(MdnsResponderTest, IncompleteSendBlocksFollowingSends) { … }
}