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
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/credentialmanagement/authentication_credentials_container.h"
#include <memory>
#include <utility>
#include "base/test/scoped_feature_list.h"
#include "components/ukm/test_ukm_recorder.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/credentialmanagement/credential_manager.mojom-blink.h"
#include "third_party/blink/public/mojom/webauthn/authenticator.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_tester.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_gc_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_arraybuffer_arraybufferview.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_credential_creation_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_credential_request_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_federated_credential_request_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_identity_credential_request_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_identity_provider_request_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_creation_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_parameters.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_request_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_rp_entity.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_user_entity.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/testing/gc_object_liveness_observer.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/modules/credentialmanagement/credential.h"
#include "third_party/blink/renderer/modules/credentialmanagement/credential_manager_proxy.h"
#include "third_party/blink/renderer/modules/credentialmanagement/federated_credential.h"
#include "third_party/blink/renderer/modules/credentialmanagement/password_credential.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/wrapper_type_info.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
namespace {
class MockCredentialManager : public mojom::blink::CredentialManager {
public:
MockCredentialManager() = default;
MockCredentialManager(const MockCredentialManager&) = delete;
MockCredentialManager& operator=(const MockCredentialManager&) = delete;
~MockCredentialManager() override {}
void Bind(mojo::PendingReceiver<::blink::mojom::blink::CredentialManager>
receiver) {
receiver_.Bind(std::move(receiver));
receiver_.set_disconnect_handler(WTF::BindOnce(
&MockCredentialManager::Disconnected, WTF::Unretained(this)));
}
void Disconnected() { disconnected_ = true; }
bool IsDisconnected() const { return disconnected_; }
void WaitForCallToGet() {
if (get_callback_)
return;
loop_.Run();
}
void InvokeGetCallback() {
EXPECT_TRUE(receiver_.is_bound());
auto info = blink::mojom::blink::CredentialInfo::New();
info->type = blink::mojom::blink::CredentialType::EMPTY;
std::move(get_callback_)
.Run(blink::mojom::blink::CredentialManagerError::SUCCESS,
std::move(info));
}
protected:
void Store(blink::mojom::blink::CredentialInfoPtr credential,
StoreCallback callback) override {}
void PreventSilentAccess(PreventSilentAccessCallback callback) override {}
void Get(blink::mojom::blink::CredentialMediationRequirement mediation,
bool include_passwords,
const WTF::Vector<::blink::KURL>& federations,
GetCallback callback) override {
get_callback_ = std::move(callback);
loop_.Quit();
}
private:
mojo::Receiver<::blink::mojom::blink::CredentialManager> receiver_{this};
GetCallback get_callback_;
bool disconnected_ = false;
base::RunLoop loop_;
};
class MockAuthenticatorInterface : public mojom::blink::Authenticator {
public:
MockAuthenticatorInterface() { loop_ = std::make_unique<base::RunLoop>(); }
MockAuthenticatorInterface(const MockAuthenticatorInterface&) = delete;
MockAuthenticatorInterface& operator=(const MockAuthenticatorInterface&) =
delete;
void Bind(
mojo::PendingReceiver<::blink::mojom::blink::Authenticator> receiver) {
receiver_.Bind(std::move(receiver));
}
void WaitForCallToGet() {
if (get_callback_) {
return;
}
loop_->Run();
}
void InvokeGetCallback() {
EXPECT_TRUE(receiver_.is_bound());
auto assertion_response = mojom::blink::GetAssertionResponse::New(
blink::mojom::blink::AuthenticatorStatus::NOT_ALLOWED_ERROR, nullptr,
nullptr);
auto credential_response =
mojom::blink::GetCredentialResponse::NewGetAssertionResponse(
std::move(assertion_response));
std::move(get_callback_).Run(std::move(credential_response));
}
void Reset() { loop_ = std::make_unique<base::RunLoop>(); }
protected:
void MakeCredential(
blink::mojom::blink::PublicKeyCredentialCreationOptionsPtr options,
MakeCredentialCallback callback) override {}
void GetCredential(
blink::mojom::blink::PublicKeyCredentialRequestOptionsPtr options,
GetCredentialCallback callback) override {
get_callback_ = std::move(callback);
loop_->Quit();
}
void IsUserVerifyingPlatformAuthenticatorAvailable(
IsUserVerifyingPlatformAuthenticatorAvailableCallback callback) override {
}
void IsConditionalMediationAvailable(
IsConditionalMediationAvailableCallback callback) override {}
void Report(blink::mojom::blink::PublicKeyCredentialReportOptionsPtr options,
ReportCallback callback) override {}
void GetClientCapabilities(GetClientCapabilitiesCallback callback) override {}
void Cancel() override {}
private:
mojo::Receiver<::blink::mojom::blink::Authenticator> receiver_{this};
GetCredentialCallback get_callback_;
std::unique_ptr<base::RunLoop> loop_;
};
class MockFederatedAuthRequest : public mojom::blink::FederatedAuthRequest {
public:
MockFederatedAuthRequest() = default;
MockFederatedAuthRequest(const MockFederatedAuthRequest&) = delete;
MockFederatedAuthRequest& operator=(const MockFederatedAuthRequest&) = delete;
~MockFederatedAuthRequest() override = default;
void Bind(mojo::PendingReceiver<::blink::mojom::blink::FederatedAuthRequest>
receiver) {
receiver_.Bind(std::move(receiver));
receiver_.set_disconnect_handler(WTF::BindOnce(
&MockFederatedAuthRequest::Disconnected, WTF::Unretained(this)));
}
void Disconnected() { disconnected_ = true; }
bool IsDisconnected() const { return disconnected_; }
void WaitForCallToRequestToken() {
if (request_token_callback_) {
return;
}
loop_.Run();
}
void InvokeRequestTokenCallback() {
EXPECT_TRUE(receiver_.is_bound());
std::move(request_token_callback_)
.Run(mojom::RequestTokenStatus::kSuccess, KURL("https://idp.example"),
"token", /*error=*/nullptr, /*is_auto_selected=*/false);
}
protected:
void RequestToken(
WTF::Vector<blink::mojom::blink::IdentityProviderGetParametersPtr>
idp_get_params_ptrs,
mojom::CredentialMediationRequirement requirement,
RequestTokenCallback callback) override {
request_token_callback_ = std::move(callback);
loop_.Quit();
}
void RequestUserInfo(mojom::blink::IdentityProviderConfigPtr provider,
RequestUserInfoCallback callback) override {}
void CancelTokenRequest() override {}
void ResolveTokenRequest(const WTF::String& account_id,
const WTF::String& token,
ResolveTokenRequestCallback callback) override {}
void SetIdpSigninStatus(
const ::scoped_refptr<const ::blink::SecurityOrigin>& origin,
mojom::IdpSigninStatus status,
mojom::blink::LoginStatusOptionsPtr options) override {}
void RegisterIdP(const ::blink::KURL& url,
RegisterIdPCallback callback) override {}
void UnregisterIdP(const ::blink::KURL& url,
UnregisterIdPCallback callback) override {}
void CloseModalDialogView() override {}
void PreventSilentAccess(PreventSilentAccessCallback callback) override {}
void Disconnect(mojom::blink::IdentityCredentialDisconnectOptionsPtr options,
DisconnectCallback callback) override {}
private:
mojo::Receiver<::blink::mojom::blink::FederatedAuthRequest> receiver_{this};
RequestTokenCallback request_token_callback_;
bool disconnected_ = false;
base::RunLoop loop_;
};
class CredentialManagerTestingContext {
STACK_ALLOCATED();
public:
explicit CredentialManagerTestingContext(
MockCredentialManager* mock_credential_manager,
MockAuthenticatorInterface* mock_authenticator = nullptr,
MockFederatedAuthRequest* mock_federated_auth_request = nullptr)
: dummy_context_(KURL("https://example.test")) {
if (mock_credential_manager) {
DomWindow().GetBrowserInterfaceBroker().SetBinderForTesting(
::blink::mojom::blink::CredentialManager::Name_,
WTF::BindRepeating(
[](MockCredentialManager* mock_credential_manager,
mojo::ScopedMessagePipeHandle handle) {
mock_credential_manager->Bind(
mojo::PendingReceiver<
::blink::mojom::blink::CredentialManager>(
std::move(handle)));
},
WTF::Unretained(mock_credential_manager)));
}
if (mock_authenticator) {
DomWindow().GetBrowserInterfaceBroker().SetBinderForTesting(
::blink::mojom::blink::Authenticator::Name_,
WTF::BindRepeating(
[](MockAuthenticatorInterface* mock_authenticator,
mojo::ScopedMessagePipeHandle handle) {
mock_authenticator->Bind(
mojo::PendingReceiver<::blink::mojom::blink::Authenticator>(
std::move(handle)));
},
WTF::Unretained(mock_authenticator)));
}
if (mock_federated_auth_request) {
DomWindow().GetBrowserInterfaceBroker().SetBinderForTesting(
::blink::mojom::blink::FederatedAuthRequest::Name_,
WTF::BindRepeating(
[](MockFederatedAuthRequest* mock_federated_auth_request,
mojo::ScopedMessagePipeHandle handle) {
mock_federated_auth_request->Bind(
mojo::PendingReceiver<
::blink::mojom::blink::FederatedAuthRequest>(
std::move(handle)));
},
WTF::Unretained(mock_federated_auth_request)));
}
}
~CredentialManagerTestingContext() {
DomWindow().GetBrowserInterfaceBroker().SetBinderForTesting(
::blink::mojom::blink::CredentialManager::Name_, {});
DomWindow().GetBrowserInterfaceBroker().SetBinderForTesting(
::blink::mojom::blink::Authenticator::Name_, {});
}
LocalDOMWindow& DomWindow() { return dummy_context_.GetWindow(); }
ScriptState* GetScriptState() { return dummy_context_.GetScriptState(); }
private:
V8TestingScope dummy_context_;
};
} // namespace
class MockPublicKeyCredential : public Credential {
public:
MockPublicKeyCredential() : Credential("test", "public-key") {}
bool IsPublicKeyCredential() const override { return true; }
};
// The completion callbacks for pending mojom::CredentialManager calls each own
// a persistent handle to a ScriptPromiseResolverBase instance. Ensure that if
// the document is destroyed while a call is pending, it can still be freed up.
TEST(AuthenticationCredentialsContainerTest, PendingGetRequest_NoGCCycles) {
test::TaskEnvironment task_environment;
MockCredentialManager mock_credential_manager;
GCObjectLivenessObserver<Document> document_observer;
{
CredentialManagerTestingContext context(&mock_credential_manager);
document_observer.Observe(context.DomWindow().document());
AuthenticationCredentialsContainer::credentials(*context.DomWindow().navigator())
->get(context.GetScriptState(), CredentialRequestOptions::Create(),
IGNORE_EXCEPTION_FOR_TESTING);
mock_credential_manager.WaitForCallToGet();
}
test::RunPendingTasks();
ThreadState::Current()->CollectAllGarbageForTesting();
ASSERT_TRUE(document_observer.WasCollected());
mock_credential_manager.InvokeGetCallback();
ASSERT_TRUE(mock_credential_manager.IsDisconnected());
}
// If the document is detached before the request is resolved, the promise
// should be left unresolved, and there should be no crashes.
TEST(AuthenticationCredentialsContainerTest,
PendingGetRequest_NoCrashOnResponseAfterDocumentShutdown) {
test::TaskEnvironment task_environment;
MockCredentialManager mock_credential_manager;
CredentialManagerTestingContext context(&mock_credential_manager);
auto promise =
AuthenticationCredentialsContainer::credentials(*context.DomWindow().navigator())
->get(context.GetScriptState(), CredentialRequestOptions::Create(),
IGNORE_EXCEPTION_FOR_TESTING);
mock_credential_manager.WaitForCallToGet();
context.DomWindow().FrameDestroyed();
mock_credential_manager.InvokeGetCallback();
EXPECT_EQ(v8::Promise::kPending, promise.V8Promise()->State());
}
TEST(AuthenticationCredentialsContainerTest, RejectPublicKeyCredentialStoreOperation) {
test::TaskEnvironment task_environment;
MockCredentialManager mock_credential_manager;
CredentialManagerTestingContext context(&mock_credential_manager);
auto promise = AuthenticationCredentialsContainer::credentials(
*context.DomWindow().navigator())
->store(context.GetScriptState(),
MakeGarbageCollected<MockPublicKeyCredential>(),
IGNORE_EXCEPTION_FOR_TESTING);
EXPECT_EQ(v8::Promise::kRejected, promise.V8Promise()->State());
}
TEST(AuthenticationCredentialsContainerTest,
GetPasswordAndFederatedCredentialUseCounters) {
test::TaskEnvironment task_environment;
{
// Password only.
MockCredentialManager mock_credential_manager;
CredentialManagerTestingContext context(&mock_credential_manager);
context.DomWindow().document()->ClearUseCounterForTesting(
WebFeature::kCredentialManagerGetPasswordCredential);
context.DomWindow().document()->ClearUseCounterForTesting(
WebFeature::kCredentialManagerGetLegacyFederatedCredential);
auto* request_options = CredentialRequestOptions::Create();
request_options->setPassword(true);
AuthenticationCredentialsContainer::credentials(
*context.DomWindow().navigator())
->get(context.GetScriptState(), request_options,
IGNORE_EXCEPTION_FOR_TESTING);
mock_credential_manager.WaitForCallToGet();
EXPECT_TRUE(context.DomWindow().document()->IsUseCounted(
WebFeature::kCredentialManagerGetPasswordCredential));
EXPECT_FALSE(context.DomWindow().document()->IsUseCounted(
WebFeature::kCredentialManagerGetLegacyFederatedCredential));
mock_credential_manager.InvokeGetCallback();
}
{
// Federated only.
MockCredentialManager mock_credential_manager;
CredentialManagerTestingContext context(&mock_credential_manager);
context.DomWindow().document()->ClearUseCounterForTesting(
WebFeature::kCredentialManagerGetPasswordCredential);
context.DomWindow().document()->ClearUseCounterForTesting(
WebFeature::kCredentialManagerGetLegacyFederatedCredential);
auto* request_options = CredentialRequestOptions::Create();
auto* federated_cred_options = FederatedCredentialRequestOptions::Create();
federated_cred_options->setProviders({"idp.example"});
request_options->setFederated(federated_cred_options);
AuthenticationCredentialsContainer::credentials(
*context.DomWindow().navigator())
->get(context.GetScriptState(), request_options,
IGNORE_EXCEPTION_FOR_TESTING);
mock_credential_manager.WaitForCallToGet();
EXPECT_FALSE(context.DomWindow().document()->IsUseCounted(
WebFeature::kCredentialManagerGetPasswordCredential));
EXPECT_TRUE(context.DomWindow().document()->IsUseCounted(
WebFeature::kCredentialManagerGetLegacyFederatedCredential));
mock_credential_manager.InvokeGetCallback();
}
{
// Federated and Password.
MockCredentialManager mock_credential_manager;
CredentialManagerTestingContext context(&mock_credential_manager);
context.DomWindow().document()->ClearUseCounterForTesting(
WebFeature::kCredentialManagerGetPasswordCredential);
context.DomWindow().document()->ClearUseCounterForTesting(
WebFeature::kCredentialManagerGetLegacyFederatedCredential);
auto* request_options = CredentialRequestOptions::Create();
auto* federated_cred_options = FederatedCredentialRequestOptions::Create();
federated_cred_options->setProviders({"idp.example"});
request_options->setFederated(federated_cred_options);
request_options->setPassword(true);
AuthenticationCredentialsContainer::credentials(
*context.DomWindow().navigator())
->get(context.GetScriptState(), request_options,
IGNORE_EXCEPTION_FOR_TESTING);
mock_credential_manager.WaitForCallToGet();
EXPECT_TRUE(context.DomWindow().document()->IsUseCounted(
WebFeature::kCredentialManagerGetPasswordCredential));
EXPECT_TRUE(context.DomWindow().document()->IsUseCounted(
WebFeature::kCredentialManagerGetLegacyFederatedCredential));
mock_credential_manager.InvokeGetCallback();
}
{
// Federated and Password but empty federated providers.
MockCredentialManager mock_credential_manager;
CredentialManagerTestingContext context(&mock_credential_manager);
context.DomWindow().document()->ClearUseCounterForTesting(
WebFeature::kCredentialManagerGetPasswordCredential);
context.DomWindow().document()->ClearUseCounterForTesting(
WebFeature::kCredentialManagerGetLegacyFederatedCredential);
auto* request_options = CredentialRequestOptions::Create();
auto* federated_cred_options = FederatedCredentialRequestOptions::Create();
federated_cred_options->setProviders({});
request_options->setFederated(federated_cred_options);
request_options->setPassword(true);
AuthenticationCredentialsContainer::credentials(
*context.DomWindow().navigator())
->get(context.GetScriptState(), request_options,
IGNORE_EXCEPTION_FOR_TESTING);
mock_credential_manager.WaitForCallToGet();
EXPECT_TRUE(context.DomWindow().document()->IsUseCounted(
WebFeature::kCredentialManagerGetPasswordCredential));
EXPECT_FALSE(context.DomWindow().document()->IsUseCounted(
WebFeature::kCredentialManagerGetLegacyFederatedCredential));
mock_credential_manager.InvokeGetCallback();
}
}
TEST(AuthenticationCredentialsContainerTest, PublicKeyConditionalMediationUkm) {
test::TaskEnvironment task_environment;
MockAuthenticatorInterface mock_authenticator;
CredentialManagerTestingContext context(/*mock_credential_manager=*/nullptr,
&mock_authenticator);
ukm::TestAutoSetUkmRecorder recorder;
context.DomWindow().document()->View()->ResetUkmAggregatorForTesting();
auto* request_options = CredentialRequestOptions::Create();
request_options->setMediation("conditional");
auto* public_key_request_options =
PublicKeyCredentialRequestOptions::Create();
public_key_request_options->setTimeout(10000);
public_key_request_options->setRpId("https://www.example.com");
public_key_request_options->setUserVerification("preferred");
const Vector<uint8_t> challenge = {1, 2, 3, 4};
public_key_request_options->setChallenge(
MakeGarbageCollected<V8UnionArrayBufferOrArrayBufferView>(
DOMArrayBuffer::Create(challenge)));
request_options->setPublicKey(public_key_request_options);
auto promise = AuthenticationCredentialsContainer::credentials(
*context.DomWindow().navigator())
->get(context.GetScriptState(), request_options,
IGNORE_EXCEPTION_FOR_TESTING);
mock_authenticator.WaitForCallToGet();
auto entries = recorder.GetEntriesByName("WebAuthn.ConditionalUiGetCall");
ASSERT_EQ(entries.size(), 1u);
mock_authenticator.InvokeGetCallback();
mock_authenticator.Reset();
// Verify that a second request does not get reported.
promise = AuthenticationCredentialsContainer::credentials(
*context.DomWindow().navigator())
->get(context.GetScriptState(), request_options,
IGNORE_EXCEPTION_FOR_TESTING);
mock_authenticator.WaitForCallToGet();
entries = recorder.GetEntriesByName("WebAuthn.ConditionalUiGetCall");
ASSERT_EQ(entries.size(), 1u);
mock_authenticator.InvokeGetCallback();
}
class AuthenticationCredentialsContainerActiveModeMultiIdpTest
: public testing::Test,
private ScopedFedCmMultipleIdentityProvidersForTest {
protected:
AuthenticationCredentialsContainerActiveModeMultiIdpTest()
: ScopedFedCmMultipleIdentityProvidersForTest(true) {}
};
TEST_F(AuthenticationCredentialsContainerActiveModeMultiIdpTest,
RejectActiveModeWithMultipleIdps) {
test::TaskEnvironment task_environment;
MockFederatedAuthRequest mock_federated_auth_request;
CredentialManagerTestingContext context(
/*mock_credential_manager=*/nullptr, /*mock_authenticator=*/nullptr,
/*mock_federated_auth_request=*/&mock_federated_auth_request);
CredentialRequestOptions* options = CredentialRequestOptions::Create();
IdentityCredentialRequestOptions* identity =
IdentityCredentialRequestOptions::Create();
auto* idp1 = IdentityProviderRequestOptions::Create();
idp1->setConfigURL("https://idp1.example/config.json");
idp1->setClientId("clientId");
auto* idp2 = IdentityProviderRequestOptions::Create();
idp2->setConfigURL("https://idp2.example/config.json");
idp2->setClientId("clientId");
identity->setProviders({idp1, idp2});
identity->setMode("active");
options->setIdentity(identity);
auto promise = AuthenticationCredentialsContainer::credentials(
*context.DomWindow().navigator())
->get(context.GetScriptState(), options,
IGNORE_EXCEPTION_FOR_TESTING);
task_environment.RunUntilIdle();
EXPECT_EQ(v8::Promise::kRejected, promise.V8Promise()->State());
}
} // namespace blink
|