forked from InternationalColorConsortium/iccDEV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiccIisIsapiSmoke.cpp
More file actions
115 lines (94 loc) · 3.12 KB
/
Copy pathiccIisIsapiSmoke.cpp
File metadata and controls
115 lines (94 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <httpext.h>
#include <windows.h>
#include <cstdio>
#include <string>
namespace {
struct MockSession {
std::string status;
std::string headers;
std::string body;
};
using GetExtensionVersionFn = BOOL (WINAPI *)(HSE_VERSION_INFO*);
using HttpExtensionProcFn = DWORD (WINAPI *)(LPEXTENSION_CONTROL_BLOCK);
BOOL WINAPI MockWriteClient(HCONN connId, LPVOID buffer, LPDWORD bytes, DWORD)
{
if (!connId || !buffer || !bytes) {
return FALSE;
}
auto* session = reinterpret_cast<MockSession*>(connId);
session->body.append(reinterpret_cast<const char*>(buffer), *bytes);
return TRUE;
}
BOOL WINAPI MockServerSupportFunction(HCONN connId,
DWORD request,
LPVOID buffer,
LPDWORD,
LPDWORD)
{
if (!connId) {
return FALSE;
}
auto* session = reinterpret_cast<MockSession*>(connId);
if (request == HSE_REQ_SEND_RESPONSE_HEADER_EX) {
auto* headerInfo = reinterpret_cast<HSE_SEND_HEADER_EX_INFO*>(buffer);
if (!headerInfo) {
return FALSE;
}
session->status.assign(headerInfo->pszStatus, headerInfo->cchStatus);
session->headers.assign(headerInfo->pszHeader, headerInfo->cchHeader);
return TRUE;
}
return TRUE;
}
int RunSmoke(const char* dllPath)
{
HMODULE module = LoadLibraryA(dllPath);
if (!module) {
std::fprintf(stderr, "LoadLibrary failed for %s (error=%lu)\n", dllPath, GetLastError());
return 1;
}
auto getVersion =
reinterpret_cast<GetExtensionVersionFn>(GetProcAddress(module, "GetExtensionVersion"));
auto httpProc =
reinterpret_cast<HttpExtensionProcFn>(GetProcAddress(module, "HttpExtensionProc"));
if (!getVersion || !httpProc) {
std::fprintf(stderr, "Missing expected IIS exports in %s\n", dllPath);
FreeLibrary(module);
return 1;
}
HSE_VERSION_INFO versionInfo{};
if (!getVersion(&versionInfo)) {
std::fprintf(stderr, "GetExtensionVersion failed (error=%lu)\n", GetLastError());
FreeLibrary(module);
return 1;
}
MockSession session;
EXTENSION_CONTROL_BLOCK ecb{};
ecb.cbSize = sizeof(ecb);
ecb.dwVersion = HSE_VERSION;
ecb.ConnID = reinterpret_cast<HCONN>(&session);
ecb.lpszMethod = const_cast<LPSTR>("GET");
ecb.lpszQueryString = const_cast<LPSTR>("mode=health");
ecb.ServerSupportFunction = MockServerSupportFunction;
ecb.WriteClient = MockWriteClient;
const DWORD status = httpProc(&ecb);
std::printf("Description: %s\n", versionInfo.lpszExtensionDesc);
std::printf("Status code: %lu\n", status);
std::printf("HTTP status: %s\n", session.status.c_str());
std::printf("Headers:\n%s", session.headers.c_str());
std::printf("Body:\n%s", session.body.c_str());
const bool ok = status == HSE_STATUS_SUCCESS &&
session.status == "200 OK" &&
session.body.find("ok") != std::string::npos;
FreeLibrary(module);
return ok ? 0 : 1;
}
} // namespace
int main(int argc, char** argv)
{
if (argc != 2) {
std::fprintf(stderr, "Usage: %s <path-to-iccIisIsapi.dll>\n", argv[0]);
return 2;
}
return RunSmoke(argv[1]);
}