-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtests_rpc.cpp
388 lines (318 loc) · 14 KB
/
tests_rpc.cpp
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#include "pch.h"
#include <3fd/core/runtime.h>
#include <3fd/core/callstacktracer.h>
#include <3fd/core/configuration.h>
#include <3fd/rpc/rpc_helpers.h>
#include <3fd/rpc/rpc_helpers.h>
#include "rpc_test_shared.h"
#ifdef _WIN64
# include "AcmeTesting_x64.h"
#else
# include "AcmeTesting_w32.h"
#endif
#include <thread>
#include <wincrypt.h>
#define UNDEF_SPN "RPC SERVER SPN IS UNDEFINED"
#define UNDEF_SRV_LOC "RPC SERVER LOCATION IS UNDEFINED"
// Server Principal Name (normally the FQDN of the user running the RPC server)
const char *keyForSPN = "testRpcServerPrincipalName";
#if defined SCENARIO_SINGLE_BOX_LOCAL_SEC || defined SCENARIO_SINGLE_BOX_AD_SEC
const char *keyForServerLocation = "testRpcServerSingleBox"; // localhost
#elif defined SCENARIO_REMOTE_WITH_AD_SEC
const char *keyForServerLocation = "testRpcServerWithADSec"; // FQDN of RPC server
#endif
////////////////////////////
// RPC Memory Allocation
////////////////////////////
void * __RPC_USER MIDL_user_allocate(size_t qtBytes)
{
return (void __RPC_FAR *)malloc(qtBytes);
}
void __RPC_USER MIDL_user_free(void *ptr)
{
free(ptr);
}
namespace _3fd
{
namespace integration_tests
{
using namespace core;
using namespace rpc;
void HandleException();
/// <summary>
/// Proxy for AcmeTesting RPC server.
/// </summary>
class AcmeRpcClient : public rpc::RpcClient
{
public:
using RpcClient::RpcClient;
// RPC Invert
void Invert(pair &onePair)
{
Call("Invert", [&onePair](rpc_binding_handle_t bindHandle)
{
::Invert(bindHandle, &onePair);
});
}
// RPC Operate
double Operate(double left, double right)
{
double result;
Call("Operate", [left, right, &result](rpc_binding_handle_t bindHandle)
{
::Operate(bindHandle, left, right, &result);
});
return result;
}
// RPC ChangeCase
string ChangeCase(const char *text)
{
/* When the stubs have been generated for OSF compliance the
output string parameter must fulfill the memory allocation
of the buffer carrying the text: */
std::array<unsigned char, 256> output;
Call("ChangeCase", [text, &output](rpc_binding_handle_t bindHandle)
{
::ChangeCase(bindHandle, (unsigned char *)text, output.data());
});
return string((char *)output.data());
}
// RPC WriteOnStorage
void WriteOnStorage()
{
Call("WriteOnStorage", [](rpc_binding_handle_t bindHandle)
{
::WriteOnStorage(bindHandle);
});
}
// RPC Shutdown
uint32_t Shutdown()
{
uint32_t timeout;
Call("WriteOnStorage", [&timeout](rpc_binding_handle_t bindHandle)
{
timeout = ::Shutdown(bindHandle);
});
return timeout;
}
};
/// <summary>
/// Test case for RPC client without authentication.
/// </summary>
class Framework_RpcNoAuth_TestCase : public ::testing::Test
{
public:
static void SetUpTestCase()
{
//system("pause"); // wait until RPC server becomes available
}
};
/// <summary>
/// Tests RPC client issuing requests without authentication.
/// </summary>
TEST_F(Framework_RpcNoAuth_TestCase, ClientRun_RequestTest)
{
// Ensures proper initialization/finalization of the framework
FrameworkInstance _framework;
CALL_STACK_TRACE;
uint32_t timeout(0);
try
{
AcmeRpcClient client1(
ProtocolSequence::Local,
objectsUuidsImpl1[5],
AppConfig::GetSettings().application.GetString(keyForServerLocation, UNDEF_SRV_LOC)
);
pair expPair = { 2, 1 };
pair myPair = { 1, 2 };
client1.Invert(myPair);
EXPECT_TRUE(memcmp(&expPair, &myPair, sizeof myPair) == 0);
EXPECT_EQ(696.0, client1.Operate(6.0, 116.0));
EXPECT_EQ("SQUIRREL", client1.ChangeCase("squirrel"));
AcmeRpcClient client2(
ProtocolSequence::Local,
objectsUuidsImpl2[5],
AppConfig::GetSettings().application.GetString(keyForServerLocation, UNDEF_SRV_LOC)
);
EXPECT_EQ(696.0, client2.Operate(606.0, 90.0));
EXPECT_EQ("squirrel", client2.ChangeCase("SQUIRREL"));
timeout = client2.Shutdown();
}
catch (...)
{
HandleException();
}
/* Awaits for the setup and start of the RPC server in the
next test, using data measured in the server side... */
std::this_thread::sleep_for(std::chrono::milliseconds(timeout));
}
// The set of options for each test template instantiation
struct AuthnTestOptions
{
ProtocolSequence protocolSequence;
const char *objectUUID1;
const char *objectUUID2;
AuthenticationLevel authenticationLevel;
AuthenticationSecurity authenticationSecurity;
ImpersonationLevel impersonationLevel;
};
/// <summary>
/// Test case for RPC client with NTLM/Kerberos/Negotiate authentication.
/// </summary>
/// <seealso cref="::testing::TestWithParam{AuthnTestOptions}" />
class Framework_RpcAuthn_TestCase :
public ::testing::TestWithParam<AuthnTestOptions>
{
public:
static void SetUpTestCase()
{
//system("pause"); // wait until RPC server becomes available
}
};
/// <summary>
/// Tests RPC client issuing requests for several scenarios of
/// protocol sequence and authentication level.
/// </summary>
TEST_P(Framework_RpcAuthn_TestCase, ClientRun_RequestTest)
{
// Ensures proper initialization/finalization of the framework
FrameworkInstance _framework;
CALL_STACK_TRACE;
uint32_t timeout(0);
try
{
AcmeRpcClient client1(
GetParam().protocolSequence,
GetParam().objectUUID1,
AppConfig::GetSettings().application.GetString(keyForServerLocation, UNDEF_SRV_LOC),
GetParam().authenticationSecurity,
GetParam().authenticationLevel,
GetParam().impersonationLevel,
AppConfig::GetSettings().application.GetString(keyForSPN, UNDEF_SPN) // not used for NTLM
);
pair expPair = { 2, 1 };
pair myPair = { 1, 2 };
client1.Invert(myPair);
EXPECT_TRUE(memcmp(&expPair, &myPair, sizeof myPair) == 0);
EXPECT_EQ(696.0, client1.Operate(6.0, 116.0));
EXPECT_EQ("SQUIRREL", client1.ChangeCase("squirrel"));
AcmeRpcClient client2(
GetParam().protocolSequence,
GetParam().objectUUID2,
AppConfig::GetSettings().application.GetString(keyForServerLocation, UNDEF_SRV_LOC),
GetParam().authenticationSecurity,
GetParam().authenticationLevel,
GetParam().impersonationLevel,
AppConfig::GetSettings().application.GetString(keyForSPN, UNDEF_SPN) // not used for NTLM
);
EXPECT_EQ(696.0, client2.Operate(606.0, 90.0));
EXPECT_EQ("squirrel", client2.ChangeCase("SQUIRREL"));
client2.WriteOnStorage();
timeout = client2.Shutdown();
}
catch (...)
{
HandleException();
}
/* Awaits for the setup and start of the RPC server in the
next test, using data measured in the server side... */
std::this_thread::sleep_for(std::chrono::milliseconds(timeout));
}
auto testOptions = ::testing::Values(
#ifdef SCENARIO_SINGLE_BOX_LOCAL_SEC
AuthnTestOptions{ ProtocolSequence::Local, objectsUuidsImpl1[6], objectsUuidsImpl2[6], AuthenticationLevel::Integrity, AuthenticationSecurity::NTLM, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::Local, objectsUuidsImpl1[7], objectsUuidsImpl2[7], AuthenticationLevel::Privacy, AuthenticationSecurity::NTLM, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::Local, objectsUuidsImpl1[8], objectsUuidsImpl2[8], AuthenticationLevel::Integrity, AuthenticationSecurity::TryKerberos, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::Local, objectsUuidsImpl1[9], objectsUuidsImpl2[9], AuthenticationLevel::Privacy, AuthenticationSecurity::TryKerberos, ImpersonationLevel::Impersonate }
#elif defined SCENARIO_SINGLE_BOX_AD_SEC
AuthnTestOptions{ ProtocolSequence::Local, objectsUuidsImpl1[6], objectsUuidsImpl2[6], AuthenticationLevel::Integrity, AuthenticationSecurity::NTLM, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::Local, objectsUuidsImpl1[7], objectsUuidsImpl2[7], AuthenticationLevel::Privacy, AuthenticationSecurity::NTLM, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::Local, objectsUuidsImpl1[8], objectsUuidsImpl2[8], AuthenticationLevel::Integrity, AuthenticationSecurity::TryKerberos, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::Local, objectsUuidsImpl1[9], objectsUuidsImpl2[9], AuthenticationLevel::Privacy, AuthenticationSecurity::TryKerberos, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::Local, objectsUuidsImpl1[10], objectsUuidsImpl2[10], AuthenticationLevel::Integrity, AuthenticationSecurity::RequireMutualAuthn, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::Local, objectsUuidsImpl1[11], objectsUuidsImpl2[11], AuthenticationLevel::Privacy, AuthenticationSecurity::RequireMutualAuthn, ImpersonationLevel::Impersonate }
#elif defined SCENARIO_REMOTE_WITH_AD_SEC
AuthnTestOptions{ ProtocolSequence::TCP, objectsUuidsImpl1[6], objectsUuidsImpl2[6], AuthenticationLevel::Integrity, AuthenticationSecurity::NTLM, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::TCP, objectsUuidsImpl1[7], objectsUuidsImpl2[7], AuthenticationLevel::Privacy, AuthenticationSecurity::NTLM, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::TCP, objectsUuidsImpl1[8], objectsUuidsImpl2[8], AuthenticationLevel::Integrity, AuthenticationSecurity::TryKerberos, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::TCP, objectsUuidsImpl1[9], objectsUuidsImpl2[9], AuthenticationLevel::Privacy, AuthenticationSecurity::TryKerberos, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::TCP, objectsUuidsImpl1[10], objectsUuidsImpl2[10], AuthenticationLevel::Integrity, AuthenticationSecurity::RequireMutualAuthn, ImpersonationLevel::Impersonate },
AuthnTestOptions{ ProtocolSequence::TCP, objectsUuidsImpl1[11], objectsUuidsImpl2[11], AuthenticationLevel::Privacy, AuthenticationSecurity::RequireMutualAuthn, ImpersonationLevel::Impersonate }
#endif
);
/* Implementation of test template takes care of switching
protocol sequences and authentication level: */
INSTANTIATE_TEST_CASE_P(
SwitchProtAndAuthLevel,
Framework_RpcAuthn_TestCase,
testOptions
);
/// <summary>
/// Test case for RPC client with SCHANNEL authentication.
/// </summary>
/// <seealso cref="::testing::TestWithParam{SchannelTestOptions}" />
class Framework_RpcSchannel_TestCase :
public ::testing::TestWithParam<SchannelTestOptions>
{
public:
static void SetUpTestCase()
{
//system("pause"); // wait until RPC server becomes available
}
};
/// <summary>
/// Tests RPC client issuing requests for several scenarios of
/// protocol sequence and authentication level using Schannel SSP.
/// </summary>
TEST_P(Framework_RpcSchannel_TestCase, ClientRun_RequestTest)
{
// Ensures proper initialization/finalization of the framework
FrameworkInstance _framework;
CALL_STACK_TRACE;
uint32_t timeout(0);
try
{
CertInfo certInfo(
CERT_SYSTEM_STORE_LOCAL_MACHINE,
"My",
"MySelfSignedCert4DevTestsClient",
GetParam().useStrongSec
);
AcmeRpcClient client1(
GetParam().objectUUID1,
AppConfig::GetSettings().application.GetString(keyForServerLocation, UNDEF_SRV_LOC),
certInfo,
GetParam().authenticationLevel
);
pair expPair = { 2, 1 };
pair myPair = { 1, 2 };
client1.Invert(myPair);
EXPECT_TRUE(memcmp(&expPair, &myPair, sizeof myPair) == 0);
EXPECT_EQ(696.0, client1.Operate(6.0, 116.0));
EXPECT_EQ("SQUIRREL", client1.ChangeCase("squirrel"));
AcmeRpcClient client2(
GetParam().objectUUID2,
AppConfig::GetSettings().application.GetString(keyForServerLocation, UNDEF_SRV_LOC),
certInfo,
GetParam().authenticationLevel
);
EXPECT_EQ(696.0, client2.Operate(606.0, 90.0));
EXPECT_EQ("squirrel", client2.ChangeCase("SQUIRREL"));
timeout = client2.Shutdown();
}
catch (...)
{
HandleException();
}
/* Awaits for the setup and start of the RPC server in the
next test, using data measured in the server side... */
std::this_thread::sleep_for(std::chrono::milliseconds(timeout));
}
// Implementation of test template takes care of switching parameters:
INSTANTIATE_TEST_CASE_P(
SwitchProtAndAuthLevel,
Framework_RpcSchannel_TestCase,
paramsForSchannelTests // shared by both client & server side
);
}// end of namespace integration_tests
}// end of namespace _3fd