curl-fuzzer C++ reference
Loading...
Searching...
No Matches
smtp_mock_server.h
Go to the documentation of this file.
1/*
2 * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al.
3 *
4 * SPDX-License-Identifier: curl
5 */
6
9
10#ifndef PROTO_FUZZER_SMTP_MOCK_SERVER_H_
11#define PROTO_FUZZER_SMTP_MOCK_SERVER_H_
12
13#include <cstddef>
14#include <memory>
15#include <string_view>
16
18
19namespace proto_fuzzer {
20
43class SmtpMockServer : public PingpongMockServer {
44 public:
45 explicit SmtpMockServer(curl::fuzzer::proto::SmtpProbeMode mode = curl::fuzzer::proto::SMTP_PROBE_DEFAULT);
46
47 ~SmtpMockServer() override;
48
49 void ObserveState() override;
50
51 SmtpMockServer(const SmtpMockServer&) = delete;
52 SmtpMockServer& operator=(const SmtpMockServer&) = delete;
53
54 // Apply the harness-owned client controls after ordinary scenario options.
55 void ConfigureClient(CURL* easy) const;
56
57 protected:
58 std::unique_ptr<MockConnection> CreateConnection() override;
59
60 void HandleLine(std::string_view line) override;
61
62 void ResetProtocolState() override;
63
64 void QueueShutdownReply() override;
65
66 private:
68 static constexpr std::string_view kEndOfBody = "\r\n.\r\n";
69
71 static constexpr std::string_view kShutdownReply = "221 mock closing SMTP connection\r\n";
72
73 static int FirstReplyCode(std::string_view response);
74
75 bool AllowsRecipientFailures() const;
76
77 // Return whether the selected probe asks curl to issue STARTTLS.
78 bool IsStartTlsMode() const;
79
82 std::size_t recipient_count_;
84 std::size_t rcpt_command_count_;
88 bool auth_exchange_active_;
90 curl::fuzzer::proto::SmtpProbeMode mode_;
92 bool tls_upgrade_started_;
93};
94
95} // namespace proto_fuzzer
96
97#endif // PROTO_FUZZER_SMTP_MOCK_SERVER_H_
SmtpMockServer(curl::fuzzer::proto::SmtpProbeMode mode=curl::fuzzer::proto::SMTP_PROBE_DEFAULT)
Begin without a borrowed protobuf or open socketpair.
~SmtpMockServer() override
Release the server-owned socketpair half after curl has returned its client descriptor.
std::unique_ptr< MockConnection > CreateConnection() override
Create the default plaintext transport for the SMTP exchange.
void HandleLine(std::string_view line) override
Advance one reply for every complete command.
void ResetProtocolState() override
Reset SMTP's recipient bookkeeping for a new drive.
void ConfigureClient(CURL *easy) const
Apply only closed, harness-owned client controls.
void ObserveState() override
Retain protocol outcomes in coverage and introspector builds.
void QueueShutdownReply() override
Queue a 221 before the shared transport half-closes.
PingpongMockServer — shared line-oriented command/response transport for the mail-style protocol peer...