@@ -54,6 +54,17 @@ class AuthenticationClientImplTestable : public auth::AuthenticationClientImpl {
5454 client::OlpClient::RequestBodyType, std::time_t ,
5555 const std::string&),
5656 (override ));
57+
58+ client::HttpResponse RealCallAuth (
59+ const client::OlpClient& client, const std::string& endpoint,
60+ client::CancellationContext context,
61+ const auth::AuthenticationCredentials& credentials,
62+ client::OlpClient::RequestBodyType body, std::time_t time,
63+ const std::string& content_type) {
64+ return auth::AuthenticationClientImpl::CallAuth (
65+ client, endpoint, std::move (context), credentials, std::move (body),
66+ time, content_type);
67+ }
5768};
5869
5970ACTION_P (Wait, time) { std::this_thread::sleep_for (time); }
@@ -264,3 +275,59 @@ TEST(AuthenticationClientTest, GenerateAuthorizationHeader) {
264275 " 3D\" " ;
265276 EXPECT_EQ (sig, expected_sig);
266277}
278+
279+ TEST (AuthenticationClientTest, SignInWithCustomUrlAndBody) {
280+ // Making CPPLINT happy
281+ using testing::_;
282+ using testing::Contains;
283+ using testing::DoAll;
284+ using testing::ElementsAreArray;
285+ using testing::Not;
286+ using testing::Pair;
287+ using testing::Return;
288+ using testing::SaveArg;
289+
290+ using std::placeholders::_1;
291+ using std::placeholders::_2;
292+ using std::placeholders::_3;
293+ using std::placeholders::_4;
294+ using std::placeholders::_5;
295+ using std::placeholders::_6;
296+ using std::placeholders::_7;
297+
298+ constexpr auto custom_url = " https://example.com/user/login" ;
299+ const auto custom_body = std::string (" custom_body" );
300+ olp::http::NetworkRequest expected_request{" " };
301+
302+ const auth::AuthenticationCredentials credentials (" " , " " , custom_url);
303+ auth::SignInProperties properties;
304+ properties.custom_body = custom_body;
305+
306+ auth::AuthenticationSettings settings;
307+ auto network_mock = std::make_shared<NetworkMock>();
308+ settings.network_request_handler = network_mock;
309+
310+ AuthenticationClientImplTestable auth_impl (settings);
311+
312+ EXPECT_CALL (*network_mock, Send)
313+ .WillOnce (DoAll (
314+ SaveArg<0 >(&expected_request),
315+ Return (olp::http::SendOutcome (olp::http::ErrorCode::UNKNOWN_ERROR ))));
316+
317+ EXPECT_CALL (auth_impl, CallAuth)
318+ .WillOnce (std::bind (&AuthenticationClientImplTestable::RealCallAuth,
319+ &auth_impl, _1, _2, _3, _4, _5, _6, _7));
320+
321+ auth_impl.SignInClient (
322+ credentials, properties,
323+ [=](const auth::AuthenticationClient::SignInClientResponse& response) {
324+ EXPECT_FALSE (response.IsSuccessful ());
325+ EXPECT_EQ (response.GetError ().GetErrorCode (),
326+ client::ErrorCode::Unknown);
327+ });
328+
329+ EXPECT_EQ (expected_request.GetUrl (), custom_url);
330+ EXPECT_THAT (*expected_request.GetBody (), ElementsAreArray (custom_body));
331+ EXPECT_THAT (expected_request.GetHeaders (),
332+ Not (Contains (Pair (" Content-Type" , _))));
333+ }
0 commit comments