@@ -42,6 +42,8 @@ const std::string kTimestampUrl =
4242const std::string kIntrospectUrl =
4343 R"( https://authentication.server.url/app/me)" ;
4444
45+ constexpr auto kTokenEndpointUrl = " https://authentication.server.url" ;
46+
4547constexpr unsigned int kExpirtyTime = 3600 ;
4648constexpr unsigned int kMaxExpiryTime = kExpirtyTime + 30 ;
4749constexpr unsigned int kMinExpiryTime = kExpirtyTime - 10 ;
@@ -116,8 +118,7 @@ class AuthenticationClientTest : public ::testing::Test {
116118 AuthenticationClientTest ()
117119 : key_(" key" ), secret_(" secret" ), scope_(" scope" ) {}
118120 void SetUp () {
119- client_ = std::make_unique<AuthenticationClient>(
120- " https://authentication.server.url" );
121+ client_ = std::make_unique<AuthenticationClient>(kTokenEndpointUrl );
121122
122123 network_ = std::make_shared<NetworkMock>();
123124 task_scheduler_ =
@@ -222,6 +223,65 @@ class AuthenticationClientTest : public ::testing::Test {
222223 const std::string scope_;
223224};
224225
226+ TEST_F (AuthenticationClientTest, SignInClientUseLocalTime) {
227+ AuthenticationSettings settings;
228+ settings.network_request_handler = network_;
229+ settings.use_system_time = true ;
230+ settings.token_endpoint_url = kTokenEndpointUrl ;
231+
232+ auto client = std::make_unique<AuthenticationClient>(std::move (settings));
233+
234+ AuthenticationCredentials credentials (key_, secret_);
235+ std::promise<AuthenticationClient::SignInClientResponse> request;
236+ auto request_future = request.get_future ();
237+
238+ EXPECT_CALL (*network_, Send (IsGetRequest (kTimestampUrl ), _, _, _, _))
239+ .Times (0 );
240+
241+ EXPECT_CALL (*network_, Send (_, _, _, _, _))
242+ .WillOnce ([&](olp::http::NetworkRequest /* request*/ ,
243+ olp::http::Network::Payload payload,
244+ olp::http::Network::Callback callback,
245+ olp::http::Network::HeaderCallback /* header_callback*/ ,
246+ olp::http::Network::DataCallback data_callback) {
247+ olp::http::RequestId request_id (5 );
248+ if (payload) {
249+ *payload << kResponseWithScope ;
250+ }
251+ callback (olp::http::NetworkResponse ()
252+ .WithRequestId (request_id)
253+ .WithStatus (olp::http::HttpStatusCode::OK));
254+ if (data_callback) {
255+ auto raw = const_cast <char *>(kResponseWithScope .c_str ());
256+ data_callback (reinterpret_cast <uint8_t *>(raw), 0 ,
257+ kResponseWithScope .size ());
258+ }
259+
260+ return olp::http::SendOutcome (request_id);
261+ });
262+
263+ AuthenticationClient::SignInProperties properties;
264+ properties.scope = scope_;
265+ std::time_t now = std::time (nullptr );
266+ client->SignInClient (
267+ credentials, properties,
268+ [&](const AuthenticationClient::SignInClientResponse& response) {
269+ request.set_value (response);
270+ });
271+ request_future.wait ();
272+
273+ AuthenticationClient::SignInClientResponse response = request_future.get ();
274+ EXPECT_TRUE (response.IsSuccessful ());
275+ EXPECT_FALSE (response.GetResult ().GetAccessToken ().empty ());
276+ EXPECT_EQ (kResponseToken , response.GetResult ().GetAccessToken ());
277+ EXPECT_GE (now + kMaxExpiryTime , response.GetResult ().GetExpiryTime ());
278+ EXPECT_LT (now + kMinExpiryTime , response.GetResult ().GetExpiryTime ());
279+ EXPECT_EQ (" bearer" , response.GetResult ().GetTokenType ());
280+ EXPECT_TRUE (response.GetResult ().GetRefreshToken ().empty ());
281+ EXPECT_TRUE (response.GetResult ().GetUserIdentifier ().empty ());
282+ EXPECT_EQ (response.GetResult ().GetScope (), scope_);
283+ }
284+
225285TEST_F (AuthenticationClientTest, SignInClientScope) {
226286 AuthenticationCredentials credentials (key_, secret_);
227287 std::promise<AuthenticationClient::SignInClientResponse> request;
0 commit comments