84 std::shared_ptr<xdoauth::OAuthConfiguration>(
new xdoauth::OAuthConfiguration(
"/authz",
"/token",
"client-id",
"",
"/redir", tenduke::oauth::OAuthClientConfiguration::PKCE)),
94 EXPECT_CALL(*randomBytes, generate(_, _))
95 .WillRepeatedly(Invoke(generateRandomBytes));
96 EXPECT_CALL(*httpClient, request())
98 EXPECT_CALL(*urlEncoder, encode(_))
99 .WillRepeatedly(::testing::ReturnArg<0>());
102 void stubForBuildAuthorizationUrl()
105 EXPECT_CALL(*messageDigestFactory, create(xdcrypto::MessageDigest::SHA256))
107 .WillOnce(Return(std::unique_ptr<xdcrypto::MessageDigest>(digest)));
108 EXPECT_CALL(*digest, update(_, _))
110 .WillOnce(Return(digest));
111 EXPECT_CALL(*digest, digestTo(_))
113 .WillOnce(Invoke(fakeSha256));
116 void stubForHandleCallback(
const std::string &redirectUri)
119 EXPECT_CALL(*urlParser, from(StrEq(redirectUri)))
121 .WillOnce(Return(std::unique_ptr<xdnet::URL>(url)));
124 void stubForTokenResponse()
126 auto responseBody = ::makeFixedSizeBinaryData(
"simulated-response-body");
127 auto tokenResponse = new ::HTTPResponse(200, {}, std::move(responseBody));
129 auto tokenRequestCall = new ::HTTPCallMock();
131 EXPECT_CALL(*httpClient, call(::_)).WillOnce(::Return(std::unique_ptr<::HTTPCallMock>(tokenRequestCall)));
132 EXPECT_CALL(*tokenRequestCall, execute()).WillOnce(::Return(std::unique_ptr<::HTTPResponse>(tokenResponse)));
134 auto json = ::JSONObjectMock::create();
135 auto accessToken = ::JSONStringMock::createShared(
"simulated-access-token");
136 auto refreshToken = ::JSONStringMock::createShared(
"simulated-refresh-token");
137 auto expiresIn = ::JSONNumberMock::createShared(42);
138 auto additionalProperty1 = ::JSONStringMock::createShared(
"value-1");
139 auto additionalProperty2 = ::JSONStringMock::createShared(
"value-2");
140 additionalTokenResponseProperties.emplace(
"name-1", additionalProperty1);
141 additionalTokenResponseProperties.emplace(
"name-2", additionalProperty2);
143 EXPECT_CALL(*jsonParser, from(
"simulated-response-body")).WillOnce(::Return(std::unique_ptr<::JSONObjectMock>(
json)));
144 EXPECT_CALL(*
json, removeProperty(
"access_token")).WillOnce(::Return(accessToken));
145 EXPECT_CALL(*
json, removeProperty(
"refresh_token")).WillOnce(::Return(refreshToken));
146 EXPECT_CALL(*
json, removeProperty(
"expires_in")).WillOnce(::Return(expiresIn));
147 EXPECT_CALL(*
json, getProperties()).WillOnce(::ReturnRef(additionalTokenResponseProperties));
149 EXPECT_CALL(*clock, epochSeconds()).WillRepeatedly(::Return(100));
155 std::map<std::string, std::shared_ptr<::JSONElement>> additionalTokenResponseProperties;
156 std::shared_ptr<xdmock::HTTPClientMock> httpClient;
157 std::shared_ptr<xdmock::URLParserMock> urlParser;
158 std::shared_ptr<xdmock::JSONParserMock> jsonParser;
159 std::shared_ptr<xdutl::Base64Encoder> base64Encoder;
160 std::shared_ptr<xdmock::MessageDigestFactoryMock> messageDigestFactory;
161 std::shared_ptr<xdmock::ClockMock> clock;
162 std::shared_ptr<xdmock::RandomBytesMock> randomBytes;
163 std::shared_ptr<xdmock::URLEncoderMock> urlEncoder;
165 std::unique_ptr<xdpkce::OAuthPKCEFlow>
oauth;