@@ -438,6 +438,44 @@ TEST(UnifiedRestCredentialsTest, ServiceAccount) {
438438 EXPECT_EQ (access_token->token , *jwt);
439439}
440440
441+ TEST (UnifiedRestCredentialsTest, AuthorizedUser) {
442+ auto const token_uri = std::string{" https://user-refresh.example.com" };
443+ auto const contents = nlohmann::json{
444+ {" client_id" , " a-client-id.example.com" },
445+ {" client_secret" , " a-123456ABCDEF" },
446+ {" refresh_token" , " 1/THETOKEN" },
447+ {" type" , " authorized_user" },
448+ {" token_uri" , token_uri},
449+ };
450+
451+ auto const now = std::chrono::system_clock::now ();
452+
453+ MockClientFactory client_factory;
454+ EXPECT_CALL (client_factory, Call).WillOnce ([token_uri]() {
455+ auto client = std::make_unique<MockRestClient>();
456+ using FormDataType = std::vector<std::pair<std::string, std::string>>;
457+ auto expected_request = Property (&RestRequest::path, token_uri);
458+ auto expected_form_data = MatcherCast<FormDataType const &>(IsSupersetOf ({
459+ Pair (" grant_type" , " refresh_token" ),
460+ Pair (" client_id" , " a-client-id.example.com" ),
461+ Pair (" client_secret" , " a-123456ABCDEF" ),
462+ Pair (" refresh_token" , " 1/THETOKEN" ),
463+ }));
464+ EXPECT_CALL (*client, Post (_, expected_request, expected_form_data))
465+ .WillOnce (Return (
466+ Status{StatusCode::kPermissionDenied , " uh-oh - user refresh" }));
467+ return client;
468+ });
469+
470+ auto const config =
471+ internal::AuthorizedUserConfig (contents.dump (), Options{});
472+ auto credentials = MapCredentials (config, client_factory.AsStdFunction ());
473+
474+ auto access_token = credentials->GetToken (now);
475+ EXPECT_THAT (access_token,
476+ StatusIs (StatusCode::kPermissionDenied , " uh-oh - user refresh" ));
477+ }
478+
441479TEST (UnifiedRestCredentialsTest, ExternalAccount) {
442480 // This sets up a mocked request for the subject token.
443481 auto const subject_url = std::string{" https://test-only-oidc.example.com/" };
@@ -487,6 +525,16 @@ TEST(UnifiedRestCredentialsTest, ExternalAccount) {
487525 StatusIs (StatusCode::kPermissionDenied , " uh-oh - STS exchange" ));
488526}
489527
528+ TEST (UnifiedRestCredentialsTest, AuthorizedUserParseError) {
529+ MockClientFactory client_factory;
530+ EXPECT_CALL (client_factory, Call).Times (0 );
531+
532+ auto const config = internal::AuthorizedUserConfig (" invalid-json" , Options{});
533+ auto credentials = MapCredentials (config, client_factory.AsStdFunction ());
534+ auto access_token = credentials->GetToken (std::chrono::system_clock::now ());
535+ EXPECT_THAT (access_token, Not (IsOk ()));
536+ }
537+
490538TEST (UnifiedRestCredentialsTest, ApiKey) {
491539 auto creds = MakeApiKeyCredentials (" api-key" );
492540 ASSERT_THAT (creds, NotNull ());
0 commit comments