From c09ae830c63f228c666d70cab539a58aa89ed751 Mon Sep 17 00:00:00 2001 From: brave-builds <45370463+brave-builds@users.noreply.github.com> Date: Mon, 5 Feb 2024 19:48:14 +0000 Subject: [PATCH] Accept a response code of 206 from Uphold cards endpoint (uplift to 1.62.x) (#21885) Uplift of #21647 (squashed) to release Co-authored-by: brave-builds --- .../endpoint/uphold/get_cards/get_cards.cc | 2 +- .../endpoint/uphold/get_cards/get_cards.h | 3 +- .../uphold/get_cards/get_cards_unittest.cc | 29 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards.cc b/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards.cc index 5043db125e44..2d93d93b2025 100644 --- a/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards.cc +++ b/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards.cc @@ -30,7 +30,7 @@ mojom::Result GetCards::CheckStatusCode(int status_code) const { return mojom::Result::EXPIRED_TOKEN; } - if (status_code != net::HTTP_OK) { + if (status_code != net::HTTP_OK && status_code != net::HTTP_PARTIAL_CONTENT) { BLOG(0, "Unexpected HTTP status: " << status_code); return mojom::Result::FAILED; } diff --git a/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards.h b/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards.h index e1904c1a5de7..c8625c983b9f 100644 --- a/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards.h +++ b/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards.h @@ -13,8 +13,9 @@ // GET https://api.uphold.com/v0/me/cards?q=currency:BAT // -// Success code: +// Success codes: // HTTP_OK (200) +// HTTP_PARTIAL_CONTENT (206) // // Error codes: // HTTP_UNAUTHORIZED (401) diff --git a/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards_unittest.cc b/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards_unittest.cc index f7644b2d4302..605eae64a607 100644 --- a/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards_unittest.cc +++ b/components/brave_rewards/core/endpoint/uphold/get_cards/get_cards_unittest.cc @@ -102,6 +102,35 @@ TEST_F(GetCardsTest, ServerOK) { task_environment_.RunUntilIdle(); } +TEST_F(GetCardsTest, ServerPartialContent) { + EXPECT_CALL(*mock_engine_impl_.mock_client(), LoadURL(_, _)) + .Times(1) + .WillOnce([](mojom::UrlRequestPtr request, auto callback) { + auto response = mojom::UrlResponse::New(); + response->status_code = 206; + response->url = request->url; + response->body = R"([ + { + "available": "12.35", + "balance": "12.35", + "currency": "BAT", + "id": "3ed3b2c4-a715-4c01-b302-fa2681a971ea", + "label": "Brave Browser" + } + ])"; + std::move(callback).Run(std::move(response)); + }); + + base::MockCallback callback; + EXPECT_CALL(callback, + Run(mojom::Result::OK, + std::string("3ed3b2c4-a715-4c01-b302-fa2681a971ea"))) + .Times(1); + card_.Request("4c2b665ca060d912fec5c735c734859a06118cc8", callback.Get()); + + task_environment_.RunUntilIdle(); +} + TEST_F(GetCardsTest, CardNotFound) { EXPECT_CALL(*mock_engine_impl_.mock_client(), LoadURL(_, _)) .Times(1)