-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_ldap_authenticator.cpp
More file actions
593 lines (494 loc) · 21.1 KB
/
test_ldap_authenticator.cpp
File metadata and controls
593 lines (494 loc) · 21.1 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
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/*
╔═════════════════════════════════════════════════════════════════════╗
║ ThemisDB - Hybrid Database System ║
╠═════════════════════════════════════════════════════════════════════╣
File: test_ldap_authenticator.cpp ║
Version: 0.0.4 ║
Last Modified: 2026-03-30 04:29:01 ║
Author: unknown ║
╠═════════════════════════════════════════════════════════════════════╣
Quality Metrics: ║
• Maturity Level: 🟢 PRODUCTION-READY ║
• Quality Score: 100.0/100 ║
• Total Lines: 595 ║
• Open Issues: TODOs: 0, Stubs: 1 ║
╠═════════════════════════════════════════════════════════════════════╣
Revision History: ║
• fc7a85ac8 2026-03-12 fix(auth): address PR review - curl_multi_info_read, void... ║
• 57fef95c4 2026-03-12 feat(auth): async/non-blocking LDAP and HTTP authenticati... ║
• 0f9b874f4 2026-03-12 fix(auth): address all reviewer comments on LDAP injectio... ║
• 83e36bcbd 2026-03-12 security(auth): LDAP DN and filter injection prevention (... ║
• 2a1fb0423 2026-03-03 Merge branch 'develop' into copilot/audit-src-module-docu... ║
╠═════════════════════════════════════════════════════════════════════╣
Status: ✅ Production Ready ║
╚═════════════════════════════════════════════════════════════════════╝
*/
#include <gtest/gtest.h>
#include "auth/ldap_authenticator.h"
#include "auth/auth_error.h"
#include <string>
#include <vector>
#include <algorithm>
#include <future>
#include <chrono>
using namespace themis::auth;
// ===========================================================================
// Helper: build a valid test configuration
// ===========================================================================
namespace {
LDAPConfig makeConfig(bool with_groups = false)
{
LDAPConfig cfg;
cfg.server_url = "ldap://dc.example.com:389";
cfg.bind_dn_template = "CN={username},OU=Users,DC=example,DC=com";
cfg.default_role = "readonly";
if (with_groups) {
cfg.enable_group_search = true;
cfg.base_dn = "DC=example,DC=com";
cfg.user_search_filter = "(&(objectClass=user)(sAMAccountName={username}))";
cfg.group_search_filter = "(&(objectClass=group)(member={dn}))";
cfg.group_attribute = "cn";
cfg.group_mappings.push_back({"Admins", "admin"});
cfg.group_mappings.push_back({"Engineers", "engineer"});
}
return cfg;
}
} // anonymous namespace
// ===========================================================================
// Construction / initialization
// ===========================================================================
TEST(LDAPAuthenticatorTest, DefaultConstructedIsNotInitialized)
{
LDAPAuthenticator auth;
EXPECT_FALSE(auth.isInitialized());
}
TEST(LDAPAuthenticatorTest, InitializeSucceedsWithValidConfig)
{
LDAPAuthenticator auth;
EXPECT_TRUE(auth.initialize(makeConfig()));
EXPECT_TRUE(auth.isInitialized());
}
TEST(LDAPAuthenticatorTest, InitializeFailsWhenServerUrlEmpty)
{
LDAPAuthenticator auth;
LDAPConfig cfg = makeConfig();
cfg.server_url = "";
EXPECT_FALSE(auth.initialize(cfg));
EXPECT_FALSE(auth.isInitialized());
}
TEST(LDAPAuthenticatorTest, InitializeFailsWhenBindDnTemplateEmpty)
{
LDAPAuthenticator auth;
LDAPConfig cfg = makeConfig();
cfg.bind_dn_template = "";
EXPECT_FALSE(auth.initialize(cfg));
}
TEST(LDAPAuthenticatorTest, InitializeFailsWhenGroupSearchEnabledButBaseDnEmpty)
{
LDAPAuthenticator auth;
LDAPConfig cfg = makeConfig(/*with_groups=*/true);
cfg.base_dn = "";
EXPECT_FALSE(auth.initialize(cfg));
}
// ===========================================================================
// buildUserDN
// ===========================================================================
TEST(LDAPAuthenticatorTest, BuildUserDN_SubstitutesUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
const std::string dn = auth.buildUserDN("jdoe");
EXPECT_EQ(dn, "CN=jdoe,OU=Users,DC=example,DC=com");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_UPNStyleTemplate)
{
LDAPAuthenticator auth;
LDAPConfig cfg;
cfg.server_url = "ldap://dc.example.com";
cfg.bind_dn_template = "{username}@EXAMPLE.COM";
ASSERT_TRUE(auth.initialize(cfg));
EXPECT_EQ(auth.buildUserDN("alice"), "alice@EXAMPLE.COM");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_NoPlaceholderReturnsTemplateUnchanged)
{
LDAPAuthenticator auth;
LDAPConfig cfg;
cfg.server_url = "ldap://dc.example.com";
cfg.bind_dn_template = "CN=service,DC=example,DC=com";
ASSERT_TRUE(auth.initialize(cfg));
// No {username} placeholder — template is returned as-is
EXPECT_EQ(auth.buildUserDN("anyone"), "CN=service,DC=example,DC=com");
}
// ===========================================================================
// mapGroupsToRoles
// ===========================================================================
TEST(LDAPAuthenticatorTest, MapGroupsToRoles_SingleMapping)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig(/*with_groups=*/true)));
const auto roles = auth.mapGroupsToRoles({"Admins"});
ASSERT_EQ(roles.size(), 1u);
EXPECT_EQ(roles[0], "admin");
}
TEST(LDAPAuthenticatorTest, MapGroupsToRoles_MultipleGroupsMapped)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig(/*with_groups=*/true)));
const auto roles = auth.mapGroupsToRoles({"Admins", "Engineers"});
EXPECT_EQ(roles.size(), 2u);
EXPECT_NE(std::find(roles.begin(), roles.end(), "admin"), roles.end());
EXPECT_NE(std::find(roles.begin(), roles.end(), "engineer"), roles.end());
}
TEST(LDAPAuthenticatorTest, MapGroupsToRoles_UnknownGroupReturnsDefaultRole)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig(/*with_groups=*/true)));
const auto roles = auth.mapGroupsToRoles({"UnknownGroup"});
ASSERT_EQ(roles.size(), 1u);
EXPECT_EQ(roles[0], "readonly");
}
TEST(LDAPAuthenticatorTest, MapGroupsToRoles_EmptyGroupListReturnsDefaultRole)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig(/*with_groups=*/true)));
const auto roles = auth.mapGroupsToRoles({});
ASSERT_EQ(roles.size(), 1u);
EXPECT_EQ(roles[0], "readonly");
}
TEST(LDAPAuthenticatorTest, MapGroupsToRoles_NoDuplicateRoles)
{
LDAPAuthenticator auth;
LDAPConfig cfg;
cfg.server_url = "ldap://dc.example.com";
cfg.bind_dn_template = "{username}@EXAMPLE.COM";
// Two groups that map to the same role
cfg.group_mappings.push_back({"GroupA", "admin"});
cfg.group_mappings.push_back({"GroupB", "admin"});
ASSERT_TRUE(auth.initialize(cfg));
const auto roles = auth.mapGroupsToRoles({"GroupA", "GroupB"});
EXPECT_EQ(roles.size(), 1u); // deduplication
EXPECT_EQ(roles[0], "admin");
}
// ===========================================================================
// Input validation in authenticate()
// ===========================================================================
TEST(LDAPAuthenticatorTest, AuthenticateThrowsOnEmptyUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
EXPECT_THROW(
auth.authenticate("", "password"),
AuthException
);
}
TEST(LDAPAuthenticatorTest, AuthenticateThrowsOnEmptyPassword)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
EXPECT_THROW(
auth.authenticate("jdoe", ""),
AuthException
);
}
TEST(LDAPAuthenticatorTest, AuthenticateThrowsWhenUsernameTooLong)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
const std::string long_username(MAX_LDAP_USERNAME_LENGTH + 1, 'x');
EXPECT_THROW(
auth.authenticate(long_username, "password"),
AuthException
);
}
TEST(LDAPAuthenticatorTest, AuthenticateThrowsWhenPasswordTooLong)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
const std::string long_password(MAX_LDAP_PASSWORD_LENGTH + 1, 'x');
EXPECT_THROW(
auth.authenticate("jdoe", long_password),
AuthException
);
}
// ===========================================================================
// Offline failure handling (no LDAP server available)
// ===========================================================================
TEST(LDAPAuthenticatorTest, AuthenticateFailsWhenNotInitialized)
{
LDAPAuthenticator auth;
// Do not call initialize()
const auto result = auth.authenticate("jdoe", "password");
EXPECT_FALSE(result.success);
EXPECT_FALSE(result.error_message.empty());
}
TEST(LDAPAuthenticatorTest, AuthenticateReturnsFailedResultWhenServerUnreachable)
{
LDAPAuthenticator auth;
LDAPConfig cfg;
cfg.server_url = "ldap://127.0.0.1:39999"; // nothing listening here
cfg.bind_dn_template = "{username}@EXAMPLE.COM";
cfg.connection_timeout_seconds = 1;
cfg.search_timeout_seconds = 1;
ASSERT_TRUE(auth.initialize(cfg));
// The result must be a failure — we just don't assert the exact reason
// because it varies between platforms (LDAP stub vs real library).
const auto result = auth.authenticate("jdoe", "secret");
EXPECT_FALSE(result.success);
}
// ===========================================================================
// LDAPAuthResult helpers
// ===========================================================================
TEST(LDAPAuthResultTest, SuccessFactoryPopulatesFields)
{
const auto r = LDAPAuthResult::Success(
"jdoe",
"CN=jdoe,OU=Users,DC=example,DC=com",
{"admin", "readonly"},
{"Admins"}
);
EXPECT_TRUE(r.success);
EXPECT_EQ(r.username, "jdoe");
EXPECT_EQ(r.dn, "CN=jdoe,OU=Users,DC=example,DC=com");
EXPECT_EQ(r.roles.size(), 2u);
EXPECT_EQ(r.groups.size(), 1u);
EXPECT_TRUE(r.error_message.empty());
}
TEST(LDAPAuthResultTest, FailedFactoryPopulatesErrorMessage)
{
const auto r = LDAPAuthResult::Failed("connection timed out");
EXPECT_FALSE(r.success);
EXPECT_EQ(r.error_message, "connection timed out");
EXPECT_TRUE(r.username.empty());
EXPECT_TRUE(r.dn.empty());
EXPECT_TRUE(r.roles.empty());
}
// ===========================================================================
// getConfig
// ===========================================================================
TEST(LDAPAuthenticatorTest, GetConfigReturnsInitializedConfig)
{
LDAPAuthenticator auth;
const LDAPConfig cfg = makeConfig();
ASSERT_TRUE(auth.initialize(cfg));
EXPECT_EQ(auth.getConfig().server_url, cfg.server_url);
EXPECT_EQ(auth.getConfig().bind_dn_template, cfg.bind_dn_template);
}
// ===========================================================================
// LDAP DN injection prevention (RFC 4514)
// ===========================================================================
TEST(LDAPAuthenticatorTest, BuildUserDN_EscapesCommaInUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
// Comma is a DN special character and must be backslash-escaped.
const std::string dn = auth.buildUserDN("j,doe");
EXPECT_EQ(dn, "CN=j\\,doe,OU=Users,DC=example,DC=com");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_EscapesPlusInUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
const std::string dn = auth.buildUserDN("j+doe");
EXPECT_EQ(dn, "CN=j\\+doe,OU=Users,DC=example,DC=com");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_EscapesQuoteInUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
const std::string dn = auth.buildUserDN("j\"doe");
EXPECT_EQ(dn, "CN=j\\\"doe,OU=Users,DC=example,DC=com");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_EscapesBackslashInUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
const std::string dn = auth.buildUserDN("j\\doe");
EXPECT_EQ(dn, "CN=j\\\\doe,OU=Users,DC=example,DC=com");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_EscapesAngleBracketsInUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
const std::string dn = auth.buildUserDN("a<b>c");
EXPECT_EQ(dn, "CN=a\\<b\\>c,OU=Users,DC=example,DC=com");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_EscapesSemicolonInUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
const std::string dn = auth.buildUserDN("j;doe");
EXPECT_EQ(dn, "CN=j\\;doe,OU=Users,DC=example,DC=com");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_EscapesLeadingHashInUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
// Leading '#' must be escaped; interior '#' is left as-is.
const std::string dn = auth.buildUserDN("#admin");
EXPECT_EQ(dn, "CN=\\#admin,OU=Users,DC=example,DC=com");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_EscapesLeadingSpaceInUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
const std::string dn = auth.buildUserDN(" jdoe");
EXPECT_EQ(dn, "CN=\\ jdoe,OU=Users,DC=example,DC=com");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_EscapesTrailingSpaceInUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
const std::string dn = auth.buildUserDN("jdoe ");
EXPECT_EQ(dn, "CN=jdoe\\ ,OU=Users,DC=example,DC=com");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_InjectionAttemptWithCommaAndEquals)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
// Classic DN injection: attacker tries to break out and add another RDN.
// "jdoe,OU=Attackers" should be escaped, not interpreted as a separate RDN.
const std::string dn = auth.buildUserDN("jdoe,OU=Attackers");
EXPECT_EQ(dn, "CN=jdoe\\,OU\\=Attackers,OU=Users,DC=example,DC=com");
// The constructed DN must contain exactly "CN=..." at the start.
EXPECT_EQ(dn.substr(0, 3), "CN=");
// And must NOT contain an unescaped "OU=Attackers" component.
EXPECT_EQ(dn.find(",OU=Attackers"), std::string::npos);
}
TEST(LDAPAuthenticatorTest, BuildUserDN_PlainUsernameUnchanged)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
// Normal alphanumeric username must pass through unmodified.
EXPECT_EQ(auth.buildUserDN("jdoe123"), "CN=jdoe123,OU=Users,DC=example,DC=com");
}
TEST(LDAPAuthenticatorTest, BuildUserDN_EscapesEqualsInUsername)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
// '=' is an RFC 4514 DN special character and must be backslash-escaped.
const std::string dn = auth.buildUserDN("cn=admin");
EXPECT_EQ(dn, "CN=cn\\=admin,OU=Users,DC=example,DC=com");
}
// ===========================================================================
// LDAP filter injection prevention (RFC 4515) — buildGroupSearchFilter
// ===========================================================================
TEST(LDAPAuthenticatorTest, BuildGroupSearchFilter_EscapesFilterSpecialCharsInDN)
{
LDAPAuthenticator auth;
LDAPConfig cfg = makeConfig();
cfg.enable_group_search = true;
cfg.base_dn = "DC=example,DC=com";
cfg.group_search_filter = "(&(objectClass=group)(member={dn}))";
ASSERT_TRUE(auth.initialize(cfg));
// A DN containing LDAP filter special chars must be hex-escaped per RFC 4515.
// '*' → \2a, '(' → \28, ')' → \29, '\' → \5c
const std::string filter =
auth.buildGroupSearchFilter("CN=j*doe(evil),DC=example,DC=com");
EXPECT_EQ(filter,
"(&(objectClass=group)(member=CN=j\\2adoe\\28evil\\29,DC=example,DC=com))");
// Must not contain unescaped wildcard in substituted member DN.
const std::string substituted = filter.substr(filter.find("member=") + 7);
EXPECT_EQ(substituted.find('*'), std::string::npos);
}
/**
* @brief Integration test — requires an actual LDAP / Active Directory server.
*
* To run this test:
* 1. Set up an OpenLDAP or Active Directory test server.
* 2. Create a test user, e.g., "testuser" with password "testpass".
* 3. Build ThemisDB with -DTHEMIS_ENABLE_LDAP=ON.
* 4. Run: ctest -R LDAPAuthenticator.DISABLED_IntegrationWithLDAPServer
*/
TEST(LDAPAuthenticatorTest, DISABLED_IntegrationWithLDAPServer)
{
LDAPAuthenticator auth;
LDAPConfig cfg;
cfg.server_url = "ldap://localhost:389";
cfg.bind_dn_template = "CN={username},OU=Users,DC=test,DC=local";
cfg.connection_timeout_seconds = 5;
cfg.search_timeout_seconds = 5;
ASSERT_TRUE(auth.initialize(cfg));
// Authenticate with valid credentials
const auto result = auth.authenticate("testuser", "testpass");
EXPECT_TRUE(result.success) << result.error_message;
EXPECT_EQ(result.username, "testuser");
EXPECT_FALSE(result.dn.empty());
// Authenticate with wrong password
const auto bad_result = auth.authenticate("testuser", "wrongpassword");
EXPECT_FALSE(bad_result.success);
}
// ===========================================================================
// authenticateAsync() — thread pool dispatch
// ===========================================================================
// authenticateAsync() must throw synchronously for empty username (same as
// authenticate()), because input validation runs on the calling thread.
TEST(LDAPAuthenticatorAsyncTest, ThrowsOnEmptyUsernameSync)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
EXPECT_THROW(
(void)auth.authenticateAsync("", "password"),
AuthException
);
}
// authenticateAsync() must throw synchronously for empty password.
TEST(LDAPAuthenticatorAsyncTest, ThrowsOnEmptyPasswordSync)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
EXPECT_THROW(
(void)auth.authenticateAsync("user", ""),
AuthException
);
}
// authenticateAsync() must throw synchronously for oversized username.
TEST(LDAPAuthenticatorAsyncTest, ThrowsOnOversizedUsernameSync)
{
LDAPAuthenticator auth;
ASSERT_TRUE(auth.initialize(makeConfig()));
const std::string long_user(MAX_LDAP_USERNAME_LENGTH + 1, 'a');
EXPECT_THROW(
(void)auth.authenticateAsync(long_user, "password"),
AuthException
);
}
// authenticateAsync() returns a valid std::future (not initialized) even
// when the authenticator is not initialized — the error is returned through
// the future rather than thrown synchronously.
TEST(LDAPAuthenticatorAsyncTest, ReturnsFailedFutureWhenNotInitialized)
{
LDAPAuthenticator auth;
// Do NOT call initialize()
auto fut = auth.authenticateAsync("jdoe", "secret");
ASSERT_TRUE(fut.valid());
// Should be ready quickly (no real LDAP call)
ASSERT_EQ(fut.wait_for(std::chrono::seconds(5)),
std::future_status::ready);
const auto result = fut.get();
EXPECT_FALSE(result.success);
EXPECT_FALSE(result.error_message.empty());
}
// Submitting multiple concurrent authenticateAsync() calls must not deadlock.
TEST(LDAPAuthenticatorAsyncTest, ConcurrentCallsDoNotDeadlock)
{
LDAPAuthenticator auth;
// Intentionally NOT calling initialize() so all async calls return a
// fast-fail result without any network I/O. This exercises the thread
// pool correctness (no deadlock, all futures become ready) without
// requiring a real LDAP server or accepting a network timeout.
constexpr int kTasks = 16;
std::vector<std::future<LDAPAuthResult>> futures;
futures.reserve(kTasks);
for (int i = 0; i < kTasks; ++i) {
futures.push_back(auth.authenticateAsync("user" + std::to_string(i), "pass"));
}
for (auto& f : futures) {
ASSERT_TRUE(f.valid());
ASSERT_EQ(f.wait_for(std::chrono::seconds(5)),
std::future_status::ready);
// Not-initialized path returns a failed result immediately (no throw).
const auto result = f.get();
EXPECT_FALSE(result.success);
EXPECT_FALSE(result.error_message.empty());
}
}