MCPcopy Create free account
hub / github.com/apache/mesos / TEST

Function TEST

src/tests/http_authentication_tests.cpp:346–536  ·  view source on GitHub ↗

Verifies the functionality of the `CombinedAuthenticator`. Note: This test relies on the order of invocation of the installed authenticators. If the `CombinedAuthenticator` is changed in the future to call them in a different order, this test must be updated.

Source from the content-addressed store, hash-verified

344// authenticators. If the `CombinedAuthenticator` is changed in the future to
345// call them in a different order, this test must be updated.
346TEST(CombinedAuthenticatorTest, MultipleAuthenticators)
347{
348 // Create two mock HTTP authenticators to install.
349 MockAuthenticator* basicAuthenticator = new MockAuthenticator("Basic");
350 MockAuthenticator* bearerAuthenticator = new MockAuthenticator("Bearer");
351
352 // Create a `CombinedAuthenticator` containing multiple authenticators.
353 Owned<Authenticator> combinedAuthenticator(
354 new CombinedAuthenticator(
355 REALM,
356 {
357 Owned<Authenticator>(basicAuthenticator),
358 Owned<Authenticator>(bearerAuthenticator)
359 }
360 ));
361
362 Request request;
363 request.headers.put(
364 "Authorization",
365 "Basic " + base64::encode("user:password"));
366
367 // The first authenticator succeeds.
368 {
369 AuthenticationResult successfulResult;
370 successfulResult.principal = Principal("user");
371
372 EXPECT_CALL(*basicAuthenticator, authenticate(request))
373 .WillOnce(Return(successfulResult));
374
375 Future<AuthenticationResult> result =
376 combinedAuthenticator->authenticate(request);
377 AWAIT_EXPECT_EQ(successfulResult, result);
378 }
379
380 // The first authenticator fails but the second one succeeds.
381 {
382 AuthenticationResult successfulResult;
383 successfulResult.principal = Principal("user");
384
385 EXPECT_CALL(*basicAuthenticator, authenticate(request))
386 .WillOnce(Return(createUnauthorized(*basicAuthenticator)));
387 EXPECT_CALL(*bearerAuthenticator, authenticate(request))
388 .WillOnce(Return(successfulResult));
389
390 Future<AuthenticationResult> result =
391 combinedAuthenticator->authenticate(request);
392 AWAIT_EXPECT_EQ(successfulResult, result);
393 }
394
395 // Two Unauthorized results.
396 {
397 EXPECT_CALL(*basicAuthenticator, authenticate(request))
398 .WillOnce(Return(createUnauthorized(*basicAuthenticator)));
399 EXPECT_CALL(*bearerAuthenticator, authenticate(request))
400 .WillOnce(Return(createUnauthorized(*bearerAuthenticator)));
401
402 Future<AuthenticationResult> result =
403 combinedAuthenticator->authenticate(request);

Callers

nothing calls this directly

Calls 9

createUnauthorizedFunction · 0.85
createForbiddenFunction · 0.85
createCombinedForbiddenFunction · 0.85
FailureClass · 0.85
encodeFunction · 0.50
PrincipalClass · 0.50
putMethod · 0.45
authenticateMethod · 0.45

Tested by

no test coverage detected