Skip to content

Commit 899b1f4

Browse files
authored
Break circular dependency between classes (#1278)
Break dependency between TokenEndpoint and AutoRefreshingToken Remove RequestAutoRefreshingToken method from TokenEndpoint. Resolves: OLPEDGE-1030 Signed-off-by: Yevhenii Dudnyk <[email protected]>
1 parent c8d72bb commit 899b1f4

File tree

5 files changed

+20
-34
lines changed

5 files changed

+20
-34
lines changed

olp-cpp-sdk-authentication/src/TokenEndpoint.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,5 @@ std::future<TokenResponse> TokenEndpoint::RequestToken(
7575
return impl_->RequestToken(cancellation_token, token_request);
7676
}
7777

78-
AutoRefreshingToken TokenEndpoint::RequestAutoRefreshingToken(
79-
const TokenRequest& token_request) {
80-
return AutoRefreshingToken(*this, token_request);
81-
}
82-
8378
} // namespace authentication
8479
} // namespace olp

olp-cpp-sdk-authentication/src/TokenEndpoint.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,6 @@ class TokenEndpoint {
114114
std::future<TokenResponse> RequestToken(
115115
const TokenRequest& token_request = TokenRequest()) const;
116116

117-
/**
118-
* @brief Gets the `AutoRefreshingToken` instance that caches the requested
119-
* token and refreshes it when needed.
120-
*
121-
* @param token_request The `TokenRequest` instance.
122-
*
123-
* @return The `AutoRefreshingToken` instance that caches the requested
124-
* token and refreshes it when needed.
125-
*/
126-
AutoRefreshingToken RequestAutoRefreshingToken(
127-
const TokenRequest& token_request = TokenRequest());
128-
129117
/**
130118
* @brief Creates the `TokenEndpoint` instance with the given `settings`
131119
* parameter.

olp-cpp-sdk-authentication/src/TokenProvider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TokenProviderPrivate {
3232
TokenProviderPrivate(Settings settings, std::chrono::seconds minimum_validity)
3333
: minimum_validity_{minimum_validity},
3434
token_(std::make_shared<AutoRefreshingToken>(
35-
TokenEndpoint(std::move(settings)).RequestAutoRefreshingToken())) {}
35+
TokenEndpoint(std::move(settings)), TokenRequest())) {}
3636

3737
std::string operator()() const {
3838
client::CancellationContext context;

tests/functional/olp-cpp-sdk-authentication/HereAccountOauth2ProductionTest.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ void TestAutoRefreshingTokenValidRequest(
7474
std::function<authentication::TokenResponse(
7575
const authentication::AutoRefreshingToken& auto_token)>
7676
func) {
77-
auto token_response = func(token_endpoint.RequestAutoRefreshingToken());
77+
auto token_response =
78+
func(authentication::AutoRefreshingToken(token_endpoint, {}));
7879
ASSERT_TRUE(token_response);
7980
EXPECT_GT(token_response.GetResult().GetAccessToken().length(), 42u);
8081
EXPECT_GT(token_response.GetResult().GetExpiryTime(), time(nullptr));
@@ -90,7 +91,8 @@ void TestAutoRefreshingTokenInvalidRequest(
9091
olp::client::OlpClientSettingsFactory::CreateDefaultTaskScheduler();
9192
settings.network_request_handler = network;
9293
auto bad_token_endpoint = authentication::TokenEndpoint(settings);
93-
auto token_response = func(bad_token_endpoint.RequestAutoRefreshingToken());
94+
auto token_response =
95+
func(authentication::AutoRefreshingToken(bad_token_endpoint, {}));
9496
ASSERT_FALSE(token_response);
9597
EXPECT_EQ(token_response.GetError().GetHttpStatusCode(),
9698
olp::http::HttpStatusCode::UNAUTHORIZED);
@@ -102,7 +104,7 @@ void TestAutoRefreshingTokenReuseToken(
102104
std::function<authentication::TokenResponse(
103105
const authentication::AutoRefreshingToken& auto_token)>
104106
func) {
105-
auto auto_token = token_endpoint.RequestAutoRefreshingToken();
107+
auto auto_token = authentication::AutoRefreshingToken(token_endpoint, {});
106108
auto token_response_one = func(auto_token);
107109
auto token_response_two = func(auto_token);
108110
EXPECT_EQ(token_response_one.GetResult().GetAccessToken(),
@@ -117,7 +119,7 @@ void TestAutoRefreshingTokenForceRefresh(
117119
const authentication::AutoRefreshingToken& auto_token,
118120
const std::chrono::seconds minimum_validity)>
119121
func) {
120-
auto auto_token = token_endpoint.RequestAutoRefreshingToken();
122+
auto auto_token = authentication::AutoRefreshingToken(token_endpoint, {});
121123
auto token_response_one = func(auto_token, std::chrono::minutes(5));
122124
auto token_response_two = func(auto_token, authentication::kForceRefresh);
123125

@@ -130,8 +132,8 @@ void TestAutoRefreshingTokenExpiresInRefresh(
130132
std::function<authentication::TokenResponse(
131133
const authentication::AutoRefreshingToken& auto_token)>
132134
func) {
133-
auto auto_token = token_endpoint.RequestAutoRefreshingToken(
134-
authentication::TokenRequest{std::chrono::seconds(302)});
135+
auto auto_token = authentication::AutoRefreshingToken(
136+
token_endpoint, authentication::TokenRequest{std::chrono::seconds(302)});
135137
auto token_response_one = func(auto_token);
136138
std::this_thread::sleep_for(std::chrono::seconds(4));
137139
auto token_response_two = func(auto_token);
@@ -147,8 +149,8 @@ void TestAutoRefreshingTokenExpiresDoNotRefresh(
147149
std::function<authentication::TokenResponse(
148150
const authentication::AutoRefreshingToken& auto_token)>
149151
func) {
150-
auto auto_token = token_endpoint.RequestAutoRefreshingToken(
151-
authentication::TokenRequest{std::chrono::seconds(305)});
152+
auto auto_token = authentication::AutoRefreshingToken(
153+
token_endpoint, authentication::TokenRequest{std::chrono::seconds(305)});
152154
auto token_response_one = func(auto_token);
153155
std::this_thread::sleep_for(std::chrono::seconds(2));
154156
auto token_response_two = func(auto_token);
@@ -165,7 +167,8 @@ void TestAutoRefreshingTokenExpiresDoRefresh(
165167
const authentication::AutoRefreshingToken& auto_token,
166168
const std::chrono::seconds minimum_validity)>
167169
func) {
168-
auto auto_token = token_endpoint.RequestAutoRefreshingToken(
170+
auto auto_token = authentication::AutoRefreshingToken(
171+
token_endpoint,
169172
authentication::TokenRequest{std::chrono::seconds(1)}); // 1 second
170173
auto token_response_one =
171174
func(auto_token, std::chrono::seconds(1)); // 1 sec validity window,
@@ -189,8 +192,8 @@ void TestAutoRefreshingTokenExpiresInAnHour(
189192
const authentication::AutoRefreshingToken& auto_token,
190193
const std::chrono::seconds minimum_validity)>
191194
func) {
192-
auto auto_token = token_endpoint.RequestAutoRefreshingToken(
193-
authentication::TokenRequest{std::chrono::hours(1)});
195+
auto auto_token = authentication::AutoRefreshingToken(
196+
token_endpoint, authentication::TokenRequest{std::chrono::hours(1)});
194197
auto token_response_one = func(auto_token, std::chrono::seconds(1));
195198
std::this_thread::sleep_for(std::chrono::seconds(2));
196199
auto token_response_two = func(auto_token, std::chrono::seconds(1));
@@ -207,8 +210,8 @@ void TestAutoRefreshingTokenExpiresInASecond(
207210
const authentication::AutoRefreshingToken& auto_token,
208211
const std::chrono::seconds minimum_validity)>
209212
func) {
210-
auto auto_token = token_endpoint.RequestAutoRefreshingToken(
211-
authentication::TokenRequest{std::chrono::seconds(1)});
213+
auto auto_token = authentication::AutoRefreshingToken(
214+
token_endpoint, authentication::TokenRequest{std::chrono::seconds(1)});
212215
auto token_response_one = func(auto_token, std::chrono::seconds(1));
213216
std::this_thread::sleep_for(std::chrono::seconds(2));
214217
auto token_response_two = func(auto_token, std::chrono::seconds(1));
@@ -224,7 +227,7 @@ void TestAutoRefreshingTokenMultiThread(
224227
std::function<authentication::TokenResponse(
225228
const authentication::AutoRefreshingToken& auto_token)>
226229
func) {
227-
auto auto_token = token_endpoint.RequestAutoRefreshingToken();
230+
auto auto_token = authentication::AutoRefreshingToken(token_endpoint, {});
228231

229232
std::thread threads[5];
230233
auto token_responses = std::vector<authentication::TokenResponse>();

tests/integration/olp-cpp-sdk-authentication/HereAccountOauth2Test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void TestAutoRefreshingTokenCancel(
7474
const auth::AutoRefreshingToken& autoToken,
7575
const std::chrono::seconds minimumValidity)>
7676
func) {
77-
auto autoToken = token_endpoint.RequestAutoRefreshingToken();
77+
auto autoToken = auth::AutoRefreshingToken(token_endpoint, {});
7878

7979
std::thread threads[2];
8080
auto tokenResponses = std::vector<auth::TokenResponse>();
@@ -214,7 +214,7 @@ TEST_F(HereAccountOauth2Test, AutoRefreshingTokenBackendError) {
214214
olp::client::CancellationToken cancellationToken;
215215

216216
auto token = GetTokenFromSyncRequest(
217-
cancellationToken, token_endpoint.RequestAutoRefreshingToken(),
217+
cancellationToken, auth::AutoRefreshingToken(token_endpoint, {}),
218218
auth::kDefaultMinimumValiditySeconds);
219219

220220
EXPECT_FALSE(token);

0 commit comments

Comments
 (0)