@@ -432,6 +432,44 @@ TEST(ComputeEngineCredentialsTest, AccountEmail) {
432432#endif
433433}
434434
435+ TEST (ComputeEngineCredentialsTest, AccountEmailInvalidForRAB) {
436+ auto const alias = std::string{" default" };
437+ auto const not_an_email = std::string{" not-an-email" };
438+ auto const svc_acct_info_resp = std::string{R"""( {
439+ "email": ")""" + not_an_email + R"""( ",
440+ "scopes": ["scope1","scope2"]
441+ })""" };
442+
443+ auto client = std::make_unique<MockRestClient>();
444+ EXPECT_CALL (*client, Get (_, expect_service_config (alias)))
445+ .WillOnce ([&](RestContext&, RestRequest const &) {
446+ auto response = std::make_unique<MockRestResponse>();
447+ EXPECT_CALL (*response, StatusCode)
448+ .WillRepeatedly (Return (HttpStatusCode::kOk ));
449+ EXPECT_CALL (std::move (*response), ExtractPayload).WillOnce ([&] {
450+ return MakeMockHttpPayloadSuccess (svc_acct_info_resp);
451+ });
452+ return std::unique_ptr<RestResponse>(std::move (response));
453+ });
454+
455+ MockHttpClientFactory client_factory;
456+ EXPECT_CALL (client_factory, Call).WillOnce (Return (ByMove (std::move (client))));
457+ ComputeEngineCredentials credentials (alias, Options{},
458+ client_factory.AsStdFunction ());
459+ EXPECT_EQ (credentials.service_account_email (), alias);
460+ auto refreshed_email = credentials.AccountEmail ();
461+ EXPECT_EQ (not_an_email, refreshed_email);
462+ EXPECT_EQ (credentials.service_account_email (), refreshed_email);
463+ // TODO(#16079): Remove conditional and else clause when GA.
464+ #ifdef GOOGLE_CLOUD_CPP_TESTING_ENABLE_RAB
465+ EXPECT_THAT (credentials.AllowedLocationsRequest (),
466+ VariantWith<std::monostate>(std::monostate ()));
467+ #else
468+ EXPECT_THAT (credentials.AllowedLocationsRequest (),
469+ VariantWith<std::monostate>(std::monostate ()));
470+ #endif
471+ }
472+
435473auto expected_universe_domain_request = []() {
436474 auto const expected_path = absl::StrCat (
437475 internal::GceMetadataScheme (), " ://" , internal::GceMetadataHostname (),
0 commit comments