Skip to content

Commit 62df4a3

Browse files
Add unit test for AuthenticationClient
Message to make CI happy Relates-To: HERESDK-7942 Signed-off-by: Mykhailo Diachenko <ext-mykhailo.z.diachenko@here.com>
1 parent 9882d2e commit 62df4a3

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

olp-cpp-sdk-authentication/tests/AuthenticationClientTest.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "AuthenticationClientImpl.h"
2727
#include "AuthenticationClientUtils.h"
28+
#include "gmock/gmock.h"
2829
#include "mocks/NetworkMock.h"
2930

3031
namespace {
@@ -54,6 +55,17 @@ class AuthenticationClientImplTestable : public auth::AuthenticationClientImpl {
5455
client::OlpClient::RequestBodyType, std::time_t,
5556
const std::string&),
5657
(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+
}
5769
};
5870

5971
ACTION_P(Wait, time) { std::this_thread::sleep_for(time); }
@@ -264,3 +276,59 @@ TEST(AuthenticationClientTest, GenerateAuthorizationHeader) {
264276
"3D\"";
265277
EXPECT_EQ(sig, expected_sig);
266278
}
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

Comments
 (0)