89 clock = ::ClockMock::createShared();
90 oidcLogin = ::OIDCLoginMock::createShared();
91 oidcClient = ::OIDCClientMock::createShared();
92 sessionEventListener = std::make_shared<SessionEventListener>();
94 EXPECT_CALL(*clock, epochSeconds()).WillRepeatedly(::Return(100));
97 std::shared_ptr<::ClockMock> clock;
98 std::shared_ptr<::OIDCLoginMock> oidcLogin;
99 std::shared_ptr<::OIDCClientMock> oidcClient;
100 std::shared_ptr<SessionEventListener> sessionEventListener;
103 std::shared_ptr<::OIDCSessionImpl> session(
104 std::unique_ptr<::OIDCState> state,
105 std::uint64_t validitySafetyMarginS = 10,
106 std::chrono::milliseconds loginTimeout = std::chrono::milliseconds(0)
109 return std::make_shared<::OIDCSessionImpl>(
114 sessionEventListener,
115 validitySafetyMarginS,
119 std::shared_ptr<::OIDCSessionImpl> session(
120 const ::OIDCState &state,
121 std::uint64_t validitySafetyMarginS = 10,
122 std::chrono::milliseconds loginTimeout = std::chrono::milliseconds(0)
125 return session(std::unique_ptr<::OIDCState>(new ::OIDCState(state)), validitySafetyMarginS, loginTimeout);
127 std::shared_ptr<::OIDCSessionImpl> session_without_state()
129 return session(
nullptr);
131 std::shared_ptr<::OIDCSessionImpl> session_without_access_token()
135 std::shared_ptr<::OIDCSessionImpl> infinite_session(std::chrono::milliseconds loginTimeout = std::chrono::milliseconds (0))
143 std::shared_ptr<::OIDCSessionImpl> session_that_expires_at(
const std::int64_t expiresAt,
const bool refreshable =
true)
145 return session(
::OIDCState(
"at", (refreshable ?
"rt" :
""), expiresAt,
false, {},
::IdToken({}, {})));
149 return new ::OIDCState(
158 void stubSuccessfulRefresh()
160 auto refreshRequest = new ::OIDCRefreshRequestMock();
161 auto refreshedState = createRefreshedState();
163 EXPECT_CALL(*oidcClient, refresh(::_)).WillOnce(::Return(std::unique_ptr<::OIDCRefreshRequestMock>(refreshRequest)));
164 EXPECT_CALL(*refreshRequest, execute()).WillOnce(::Return(std::unique_ptr<::OIDCState>(refreshedState)));
166 void stubOAuthInvalidGrantRefresh()
168 auto refreshRequest = new ::OIDCRefreshRequestMock();
170 EXPECT_CALL(*oidcClient, refresh(::_)).WillOnce(::Return(std::unique_ptr<::OIDCRefreshRequestMock>(refreshRequest)));
171 EXPECT_CALL(*refreshRequest, execute()).WillOnce(::Throw(
::OAuthInvalidGrant(oauth::OAuthException::REFRESH_REQUEST,
"",
"")));
175 auto loginRequest = new ::OIDCLoginRequestMock();
177 EXPECT_CALL(*oidcLogin, login()).WillOnce(::Return(std::unique_ptr<::OIDCLoginRequestMock>(loginRequest)));
183 auto loginRequest = stubLogin();
184 auto state = createRefreshedState();
186 EXPECT_CALL(*loginRequest, execute()).WillOnce(::Return(std::unique_ptr<::OIDCState>(state)));