From 697fe929849e51d36e1bbdfa432deb35dbdf4526 Mon Sep 17 00:00:00 2001 From: Eduard Bagdasaryan Date: Sat, 25 Oct 2025 19:51:51 +0000 Subject: [PATCH] Reduce testHttpRequest dependencies (#2252) No functionality changes are expected. --- src/Makefile.am | 238 ++++----------------------- src/acl/FilledChecklist.cc | 37 +---- src/acl/FilledChecklist.h | 14 +- src/tests/Stub.am | 3 + src/tests/stub_ACLFilledChecklist.cc | 26 +++ src/tests/stub_access_log.cc | 2 +- src/tests/stub_acl.cc | 9 + src/tests/stub_adaptation_History.cc | 35 ++++ src/tests/stub_libanyp.cc | 1 + src/tests/stub_libdns.cc | 16 ++ src/tests/stub_libformat.cc | 5 + 11 files changed, 137 insertions(+), 249 deletions(-) create mode 100644 src/tests/stub_ACLFilledChecklist.cc create mode 100644 src/tests/stub_adaptation_History.cc create mode 100644 src/tests/stub_libdns.cc diff --git a/src/Makefile.am b/src/Makefile.am index 5d85a96981..39650e494f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1929,241 +1929,67 @@ tests_testHttpReply_LDFLAGS = $(LIBADD_DL) check_PROGRAMS += tests/testHttpRequest tests_testHttpRequest_SOURCES = \ - $(DELAY_POOL_SOURCE) \ - $(DNSSOURCE) \ - $(HTCPSOURCE) \ - $(IPC_SOURCE) \ - $(SNMP_SOURCE) \ - $(WIN32_SOURCE) \ - AccessLogEntry.cc \ - AuthReg.h \ - BodyPipe.cc \ - tests/stub_CacheDigest.cc \ - CacheDigest.h \ - CachePeer.cc \ - CachePeer.h \ - CachePeers.cc \ - CachePeers.h \ - ClientInfo.h \ - tests/stub_CollapsedForwarding.cc \ - ConfigOption.cc \ + tests/testHttpRequest.cc \ + tests/testHttpRequestMethod.cc +nodist_tests_testHttpRequest_SOURCES = \ + $(TESTSOURCES) \ + tests/stub_ACLFilledChecklist.cc \ + tests/stub_CachePeer.cc \ ConfigParser.cc \ - CpuAffinityMap.cc \ - CpuAffinityMap.h \ - CpuAffinitySet.cc \ - CpuAffinitySet.h \ tests/stub_ETag.cc \ - tests/stub_EventLoop.cc \ - ExternalACLEntry.cc \ - FadingCounter.cc \ - FwdState.cc \ - FwdState.h \ - HappyConnOpener.cc \ - HappyConnOpener.h \ - HeaderMangling.cc \ - HeaderMangling.h \ - HttpBody.cc \ - HttpBody.h \ - tests/stub_HttpControlMsg.cc \ + tests/stub_HelperChildConfig.cc \ HttpHdrCc.cc \ - HttpHdrCc.h \ HttpHdrContRange.cc \ HttpHdrRange.cc \ HttpHdrSc.cc \ HttpHdrScTarget.cc \ HttpHeader.cc \ - HttpHeader.h \ - HttpHeaderFieldStat.h \ HttpHeaderTools.cc \ - HttpHeaderTools.h \ - HttpReply.cc \ + tests/stub_HttpReply.cc \ HttpRequest.cc \ - tests/testHttpRequest.cc \ - tests/testHttpRequestMethod.cc \ - tests/stub_HttpUpgradeProtocolAccess.cc \ - tests/stub_Instance.cc \ - IoStats.h \ - tests/stub_IpcIoFile.cc \ - LogTags.cc \ MasterXaction.cc \ - MasterXaction.h \ MemBuf.cc \ - MemObject.cc \ - MemStore.cc \ Notes.cc \ - Notes.h \ - Parsing.cc \ - PeerPoolMgr.cc \ - PeerPoolMgr.h \ - Pipeline.cc \ - Pipeline.h \ - RefreshPattern.h \ - RemovalPolicy.cc \ RequestFlags.cc \ - RequestFlags.h \ - ResolvedPeers.cc \ - ResolvedPeers.h \ - SquidMath.cc \ - SquidMath.h \ - StatCounters.cc \ - StatCounters.h \ StatHist.cc \ - StatHist.h \ - StoreFileSystem.cc \ - StoreIOState.cc \ - StoreSwapLogData.cc \ StrList.cc \ - StrList.h \ String.cc \ - Transients.cc \ + tests/stub_access_log.cc \ + tests/stub_acl.cc \ + tests/stub_adaptation_History.cc \ tests/stub_cache_cf.cc \ - cache_cf.h \ - cache_manager.cc \ - tests/stub_carp.cc \ - carp.h \ - cbdata.cc \ - clientStream.cc \ - tests/stub_client_db.cc \ - client_side.cc \ - client_side.h \ - client_side_reply.cc \ - client_side_request.cc \ - dlink.cc \ - dlink.h \ - errorpage.cc \ - event.cc \ - external_acl.cc \ + tests/stub_cache_manager.cc \ + tests/stub_cbdata.cc \ + tests/stub_client_side.cc \ + tests/stub_debug.cc \ + tests/stub_event.cc \ tests/stub_fatal.cc \ - fatal.h \ - fd.cc \ - fd.h \ - fde.cc \ - fqdncache.cc \ - fqdncache.h \ - fs_io.cc \ - fs_io.h \ - helper.cc \ - hier_code.h \ - http.cc \ - icp_v2.cc \ - icp_v3.cc \ - int.cc \ - int.h \ - internal.cc \ - internal.h \ - tests/stub_ipc_Forwarder.cc \ - ipcache.cc \ - tests/stub_libauth.cc \ - tests/stub_libauth_acls.cc \ - tests/stub_libdiskio.cc \ + tests/stub_libdns.cc \ tests/stub_liberror.cc \ - tests/stub_libeui.cc \ - tests/stub_libmem.cc \ - tests/stub_libsecurity.cc \ - tests/stub_libstore.cc \ - tests/stub_main_cc.cc \ - mem_node.cc \ - mime.cc \ - mime.h \ + tests/stub_libformat.cc \ + tests/stub_liblog.cc \ + tests/stub_libtime.cc \ mime_header.cc \ - mime_header.h \ - multicast.cc \ - multicast.h \ - neighbors.cc \ - neighbors.h \ - pconn.cc \ - peer_digest.cc \ - peer_proxy_negotiate_auth.cc \ - peer_proxy_negotiate_auth.h \ - peer_select.cc \ - peer_sourcehash.cc \ - peer_sourcehash.h \ - peer_userhash.cc \ - peer_userhash.h \ - tests/stub_redirect.cc \ - redirect.h \ - refresh.cc \ - refresh.h \ - repl_modules.h \ - stat.cc \ - stat.h \ - stmem.cc \ - store.cc \ - store_client.cc \ - tests/stub_store_digest.cc \ - store_digest.h \ - store_io.cc \ - store_key_md5.cc \ - store_key_md5.h \ - store_log.cc \ - store_log.h \ - store_rebuild.cc \ - store_rebuild.h \ - tests/stub_store_stats.cc \ - store_swapin.cc \ - store_swapin.h \ - store_swapout.cc \ - tools.cc \ - tools.h \ - tests/stub_tunnel.cc \ - tunnel.h \ - urn.cc \ - urn.h \ - tests/stub_wccp2.cc \ - wccp2.h \ - wordlist.cc \ - wordlist.h -nodist_tests_testHttpRequest_SOURCES = \ - $(BUILT_SOURCES) \ - tests/stub_libtime.cc + tests/stub_neighbors.cc \ + tests/stub_store.cc \ + tests/stub_store_stats.cc tests_testHttpRequest_LDADD = \ - libsquid.la \ - clients/libclients.la \ - servers/libservers.la \ - helper/libhelper.la \ - ftp/libftp.la \ - http/libhttp.la \ - acl/libacls.la \ - acl/libstate.la \ - acl/libapi.la \ - parser/libparser.la \ - fs/libfs.la \ - $(SSL_LIBS) \ - ipc/libipc.la \ - proxyp/libproxyp.la \ - parser/libparser.la \ - dns/libdns.la \ base/libbase.la \ - mgr/libmgr.la \ - html/libhtml.la \ - anyp/libanyp.la \ - $(SNMP_LIBS) \ - icmp/libicmp.la \ - comm/libcomm.la \ - ip/libip.la \ - log/liblog.la \ - format/libformat.la \ - store/libstore.la \ sbuf/libsbuf.la \ - debug/libdebug.la \ - $(REPL_OBJS) \ - $(ADAPTATION_LIBS) \ - $(top_builddir)/lib/libmisccontainers.la \ + SquidConfig.o \ + ip/libip.la \ + parser/libparser.la \ + mem/libmem.la \ + http/libhttp.la \ + anyp/libanyp.la \ $(top_builddir)/lib/libmiscencoding.la \ $(top_builddir)/lib/libmiscutil.la \ - $(LIBCAP_LIBS) \ - $(LIBGNUTLS_LIBS) \ - $(LIBHEIMDAL_KRB5_LIBS) \ - $(REGEXLIB) \ - $(SSLLIB) \ - $(LIBCPPUNIT_LIBS) \ - $(LIBSYSTEMD_LIBS) \ $(COMPAT_LIB) \ - $(LIBGSS_LIBS) \ - $(LIBMIT_KRB5_LIBS) \ + $(LIBCPPUNIT_LIBS) \ + $(LIBGNUTLS_LIBS) \ $(LIBNETFILTER_CONNTRACK_LIBS) \ $(LIBNETTLE_LIBS) \ - $(LIBPSAPI_LIBS) \ + $(SSLLIB) \ $(XTRA_LIBS) tests_testHttpRequest_LDFLAGS = $(LIBADD_DL) diff --git a/src/acl/FilledChecklist.cc b/src/acl/FilledChecklist.cc index 59e338214b..8519ff5dbb 100644 --- a/src/acl/FilledChecklist.cc +++ b/src/acl/FilledChecklist.cc @@ -24,24 +24,7 @@ CBDATA_CLASS_INIT(ACLFilledChecklist); -ACLFilledChecklist::ACLFilledChecklist() : - dst_rdns(nullptr), -#if USE_AUTH - auth_user_request (nullptr), -#endif -#if SQUID_SNMP - snmp_community(nullptr), -#endif - requestErrorType(ERR_MAX), - conn_(nullptr), - fd_(-1), - destinationDomainChecked_(false), - sourceDomainChecked_(false) -{ - my_addr.setEmpty(); - src_addr.setEmpty(); - dst_addr.setEmpty(); -} +ACLFilledChecklist::ACLFilledChecklist() = default; ACLFilledChecklist::~ACLFilledChecklist() { @@ -198,24 +181,8 @@ ACLFilledChecklist::markSourceDomainChecked() * (XXX) or eventually/asynchronously. After this callback obligations are * fulfilled, checkCallback() deletes the checklist object (i.e. "this"). */ -ACLFilledChecklist::ACLFilledChecklist(const acl_access *A, HttpRequest *http_request): - dst_rdns(nullptr), -#if USE_AUTH - auth_user_request(nullptr), -#endif -#if SQUID_SNMP - snmp_community(nullptr), -#endif - requestErrorType(ERR_MAX), - conn_(nullptr), - fd_(-1), - destinationDomainChecked_(false), - sourceDomainChecked_(false) +ACLFilledChecklist::ACLFilledChecklist(const acl_access * const A, HttpRequest * const http_request) { - my_addr.setEmpty(); - src_addr.setEmpty(); - dst_addr.setEmpty(); - changeAcl(A); setRequest(http_request); } diff --git a/src/acl/FilledChecklist.h b/src/acl/FilledChecklist.h index a58995390e..f500f0e8e4 100644 --- a/src/acl/FilledChecklist.h +++ b/src/acl/FilledChecklist.h @@ -98,7 +98,7 @@ public: Ip::Address dst_addr; Ip::Address my_addr; SBuf dst_peer_name; - char *dst_rdns; + char *dst_rdns = nullptr; HttpRequest::Pointer request; @@ -106,7 +106,7 @@ public: Auth::UserRequest::Pointer auth_user_request; #endif #if SQUID_SNMP - char *snmp_community; + char *snmp_community = nullptr; #endif // TODO: RefCount errors; do not ignore them because their "owner" is gone! @@ -125,16 +125,16 @@ public: ExternalACLEntryPointer extacl_entry; - err_type requestErrorType; + err_type requestErrorType = ERR_MAX; private: - ConnStateData *conn_; ///< hack: client-to-Squid connection manager (if any) - int fd_; /**< may be available when conn_ is not */ + ConnStateData *conn_ = nullptr; ///< hack: client-to-Squid connection manager (if any) + int fd_ = -1; /**< may be available when conn_ is not */ HttpReply::Pointer reply_; ///< response added by updateReply() or nil - bool destinationDomainChecked_; - bool sourceDomainChecked_; + bool destinationDomainChecked_ = false; + bool sourceDomainChecked_ = false; /// not implemented; will cause link failures if used ACLFilledChecklist(const ACLFilledChecklist &); /// not implemented; will cause link failures if used diff --git a/src/tests/Stub.am b/src/tests/Stub.am index 2f9d15d279..67448d3144 100644 --- a/src/tests/Stub.am +++ b/src/tests/Stub.am @@ -9,6 +9,7 @@ ## This file is generated by scripts/source-maintenance.sh. STUB_SOURCE = \ + tests/stub_ACLFilledChecklist.cc \ tests/stub_CacheDigest.cc \ tests/stub_CachePeer.cc \ tests/stub_CollapsedForwarding.cc \ @@ -33,6 +34,7 @@ STUB_SOURCE = \ tests/stub_UdsOp.cc \ tests/stub_access_log.cc \ tests/stub_acl.cc \ + tests/stub_adaptation_History.cc \ tests/stub_cache_cf.cc \ tests/stub_cache_manager.cc \ tests/stub_carp.cc \ @@ -61,6 +63,7 @@ STUB_SOURCE = \ tests/stub_libauth_acls.cc \ tests/stub_libcomm.cc \ tests/stub_libdiskio.cc \ + tests/stub_libdns.cc \ tests/stub_liberror.cc \ tests/stub_libeui.cc \ tests/stub_libformat.cc \ diff --git a/src/tests/stub_ACLFilledChecklist.cc b/src/tests/stub_ACLFilledChecklist.cc new file mode 100644 index 0000000000..bfa41d8c13 --- /dev/null +++ b/src/tests/stub_ACLFilledChecklist.cc @@ -0,0 +1,26 @@ +/* + * Copyright (C) 1996-2025 The Squid Software Foundation and contributors + * + * Squid software is distributed under GPLv2+ license and includes + * contributions from numerous individuals and organizations. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + +#include "squid.h" + +#define STUB_API "acl/FilledChecklist.cc" +#include "tests/STUB.h" + +#include "ExternalACLEntry.h" + +#include "acl/FilledChecklist.h" +// These stubs are not in tests/stub_acl.cc because ACLFilledChecklist requires +// X509_free() and other heavy or difficult-to-stub dependencies that other +// tests/stub_acl.cc users (e.g., testConfigParser) may not otherwise need. +ACLFilledChecklist::ACLFilledChecklist() STUB +ACLFilledChecklist::ACLFilledChecklist(const acl_access *, HttpRequest *) STUB +ACLFilledChecklist::~ACLFilledChecklist() STUB +void ACLFilledChecklist::syncAle(HttpRequest *, const char *) const STUB +void ACLFilledChecklist::updateAle(const AccessLogEntry::Pointer &) STUB +void ACLFilledChecklist::updateReply(const HttpReply::Pointer &) STUB +void ACLFilledChecklist::verifyAle() const STUB diff --git a/src/tests/stub_access_log.cc b/src/tests/stub_access_log.cc index f8798798ee..d73443d433 100644 --- a/src/tests/stub_access_log.cc +++ b/src/tests/stub_access_log.cc @@ -12,7 +12,7 @@ #define STUB_API "access.log.cc" #include "tests/STUB.h" -HierarchyLogEntry::HierarchyLogEntry() STUB +HierarchyLogEntry::HierarchyLogEntry() STUB_NOP void HierarchyLogEntry::notePeerRead() STUB void HierarchyLogEntry::notePeerWrite() STUB diff --git a/src/tests/stub_acl.cc b/src/tests/stub_acl.cc index 3963b9bd1b..eff1f52a32 100644 --- a/src/tests/stub_acl.cc +++ b/src/tests/stub_acl.cc @@ -14,7 +14,16 @@ #include "tests/STUB.h" #include "acl/forward.h" +#include "acl/Tree.h" #include "acl/Gadgets.h" size_t aclParseAclList(ConfigParser &, ACLList **, const char *) STUB_RETVAL(0) +void aclDestroyAclList(ACLList **) STUB +const Acl::Tree &Acl::ToTree(const TreePointer *) STUB_RETREF(Acl::Tree) + +#include "acl/Checklist.h" +ACLChecklist::ACLChecklist() STUB +ACLChecklist::~ACLChecklist() STUB +const Acl::Answer &ACLChecklist::fastCheck() STUB_RETREF(Acl::Answer) +const Acl::Answer &ACLChecklist::fastCheck(const ACLList *) STUB_RETREF(Acl::Answer) diff --git a/src/tests/stub_adaptation_History.cc b/src/tests/stub_adaptation_History.cc new file mode 100644 index 0000000000..d3da81a282 --- /dev/null +++ b/src/tests/stub_adaptation_History.cc @@ -0,0 +1,35 @@ +/* + * Copyright (C) 1996-2025 The Squid Software Foundation and contributors + * + * Squid software is distributed under GPLv2+ license and includes + * contributions from numerous individuals and organizations. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + +#include "squid.h" + +#define STUB_API "adaptation/libadaptation.la" +#include "tests/STUB.h" + +#if USE_ADAPTATION +#include "adaptation/History.h" +#endif +#if ICAP_CLIENT +#include "adaptation/icap/History.h" +#endif + +#if ICAP_CLIENT +int IcapLogfileStatus = LOG_DISABLE; +Adaptation::Icap::History::History() STUB +#endif + +#if USE_ADAPTATION +Adaptation::History::History(): + lastMeta(hoReply), + allMeta(hoReply), + theNextServices("") +{ + STUB_NOP +} +#endif + diff --git a/src/tests/stub_libanyp.cc b/src/tests/stub_libanyp.cc index d6c992c614..7983e667bf 100644 --- a/src/tests/stub_libanyp.cc +++ b/src/tests/stub_libanyp.cc @@ -19,6 +19,7 @@ void AnyP::Uri::host(const char *) STUB static SBuf nil; const SBuf &AnyP::Uri::path() const STUB_RETVAL(nil) void AnyP::Uri::addRelativePath(const char *) STUB +char *urlCanonicalCleanWithoutRequest(const SBuf &, const HttpRequestMethod &, const AnyP::UriScheme &) STUB_RETVAL(nullptr) const SBuf &AnyP::Uri::SlashPath() { static SBuf slash("/"); diff --git a/src/tests/stub_libdns.cc b/src/tests/stub_libdns.cc new file mode 100644 index 0000000000..b64f42e534 --- /dev/null +++ b/src/tests/stub_libdns.cc @@ -0,0 +1,16 @@ +/* + * Copyright (C) 1996-2025 The Squid Software Foundation and contributors + * + * Squid software is distributed under GPLv2+ license and includes + * contributions from numerous individuals and organizations. + * Please see the COPYING and CONTRIBUTORS files for details. + */ + +#include "squid.h" + +#define STUB_API "dns/libdns.la" +#include "tests/STUB.h" + +#include "dns/LookupDetails.h" + +std::ostream &Dns::LookupDetails::print(std::ostream &os) const STUB_RETVAL(os) diff --git a/src/tests/stub_libformat.cc b/src/tests/stub_libformat.cc index ce3d727e9f..2cae3b9b38 100644 --- a/src/tests/stub_libformat.cc +++ b/src/tests/stub_libformat.cc @@ -8,12 +8,17 @@ #include "squid.h" #include "format/Format.h" +#include "format/Quoting.h" #define STUB_API "stub_libformat.cc" #include "tests/STUB.h" +const SBuf Format::Dash("-"); + void Format::Format::assemble(MemBuf &, const AccessLogEntryPointer &, int) const STUB bool Format::Format::parse(char const*) STUB_RETVAL(false) Format::Format::Format(char const*) STUB Format::Format::~Format() STUB +char *Format::QuoteUrlEncodeUsername(const char *) STUB_RETVAL(nullptr) +char *Format::QuoteMimeBlob(const char *) STUB_RETVAL(nullptr) -- 2.47.3