Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ can change what that program does, so the details are strict:
include an injection attempt through each of them.
- `proto = "=http,https"` stops a malformed base URL from reaching any other
protocol; redirects are not followed.
- `globoff` stops `{}` or `[]` in a base URL from being expanded into several
requests: one report is one request.
- The key is never on a command line, so it does not show up in `ps`.
- On Windows `curl.exe` is taken from `System32`, or else from the directories
on `PATH` — never from the current directory. It runs with
Expand Down
17 changes: 17 additions & 0 deletions test/test_trace_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ static void curlConfigFixesEveryOptionAndQuotesEveryValue() {
shared.application = "My\nGame";
std::string expected =
"url = \"https://trace.example.org/api/metrics\"\n"
"globoff\n"
"proto = \"=http,https\"\n"
"header = \"Content-Type: application/json; charset=utf-8\"\n"
"header = \"Expect:\"\n"
Expand Down Expand Up @@ -1071,6 +1072,21 @@ static void aNewlineInTheBaseUrlCannotAddACurlOption() {
}
}

static void aBaseUrlIsNeverExpandedIntoSeveralRequests() {
StubServer server;
Log log;
// Left to curl's URL globbing, this is two requests, to /a and to /b, and
// two answers run together into one status that cannot be read.
trace_client::TraceClient client(server.baseUrl() + "/{a,b}", "MyGame", "1.2.3", "k", true, log.logger());
client.report("startup");
client.close();
std::vector<Request> got = server.received();
CHECK_EQ(1u, got.size());
if (got.empty()) return;
CHECK_EQ(std::string("/{a,b}/api/metrics"), got[0].path);
CHECK_EQ(0u, log.count("[trace]"));
}

static void queueIsBoundedAndDropsRatherThanGrows() {
StubServer server;
server.hold(); // the sender waits on the first report
Expand Down Expand Up @@ -1817,6 +1833,7 @@ int main() {
{"isValidInstallIdAcceptsOnlyTheDocumentedCharacters", isValidInstallIdAcceptsOnlyTheDocumentedCharacters},
{"nothingTheProgramPassesCanChangeWhereOrWhatCurlSends", nothingTheProgramPassesCanChangeWhereOrWhatCurlSends},
{"aNewlineInTheBaseUrlCannotAddACurlOption", aNewlineInTheBaseUrlCannotAddACurlOption},
{"aBaseUrlIsNeverExpandedIntoSeveralRequests", aBaseUrlIsNeverExpandedIntoSeveralRequests},
{"queueIsBoundedAndDropsRatherThanGrows", queueIsBoundedAndDropsRatherThanGrows},
{"closeSendsWhatWasJustQueuedBeforeStopping", closeSendsWhatWasJustQueuedBeforeStopping},
{"destructorClosesToo", destructorClosesToo},
Expand Down
1 change: 1 addition & 0 deletions trace_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ inline std::string curlConfig(const Shared &shared, const std::string &body) {
timeout << timeoutWholeSeconds();
std::string config;
config += "url = " + curlQuote(shared.endpoint) + "\n";
config += "globoff\n"; // {} and [] in a URL would otherwise mean several requests
config += "proto = \"=http,https\"\n";
config += "header = \"Content-Type: application/json; charset=utf-8\"\n";
config += "header = \"Expect:\"\n"; // no 100-continue round trip for a larger body
Expand Down
Loading