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