77 ::URLMockingTest::SetUp();
87 std::shared_ptr<xdoauth::OAuthConfiguration>(
new xdoauth::OAuthConfiguration(
"/authz",
"/token",
"client-id",
"",
"/redir", tenduke::oauth::OAuthClientConfiguration::PKCE)),
97 EXPECT_CALL(*randomBytes, generate(_, _))
98 .WillRepeatedly(Invoke(generateRandomBytes));
99 EXPECT_CALL(*httpClient, request())
103 void stubForBuildAuthorizationUrl()
105 mockDefaultURLParsing();
106 mockIdentityURLEncoding();
107 mockParse(
"/authz",
::URL(
"",
"",
"",
"", 0,
"/authz", {},
""));
110 EXPECT_CALL(*messageDigestFactory, create(xdcrypto::MessageDigest::SHA256))
112 .WillOnce(Return(std::unique_ptr<xdcrypto::MessageDigest>(digest)));
113 EXPECT_CALL(*digest, update(_, _))
115 .WillOnce(Return(digest));
116 EXPECT_CALL(*digest, digestTo(_))
118 .WillOnce(Invoke(fakeSha256));
121 void stubForTokenResponse()
123 auto responseBody = ::makeFixedSizeBinaryData(
"simulated-response-body");
124 auto tokenResponse = new ::HTTPResponse(200, {}, std::move(responseBody));
126 auto tokenRequestCall = new ::HTTPCallMock();
128 EXPECT_CALL(*httpClient, call(::_)).WillOnce(::Return(std::unique_ptr<::HTTPCallMock>(tokenRequestCall)));
129 EXPECT_CALL(*tokenRequestCall, execute()).WillOnce(::Return(std::unique_ptr<::HTTPResponse>(tokenResponse)));
131 auto json = ::JSONObjectMock::create();
132 auto accessToken = ::JSONStringMock::createShared(
"simulated-access-token");
133 auto refreshToken = ::JSONStringMock::createShared(
"simulated-refresh-token");
134 auto expiresIn = ::JSONNumberMock::createShared(42);
135 auto additionalProperty1 = ::JSONStringMock::createShared(
"value-1");
136 auto additionalProperty2 = ::JSONStringMock::createShared(
"value-2");
137 additionalTokenResponseProperties.emplace(
"name-1", additionalProperty1);
138 additionalTokenResponseProperties.emplace(
"name-2", additionalProperty2);
140 EXPECT_CALL(*jsonParser, from(
"simulated-response-body")).WillOnce(::Return(std::unique_ptr<::JSONObjectMock>(
json)));
141 EXPECT_CALL(*
json, removeProperty(
"access_token")).WillOnce(::Return(accessToken));
142 EXPECT_CALL(*
json, removeProperty(
"refresh_token")).WillOnce(::Return(refreshToken));
143 EXPECT_CALL(*
json, removeProperty(
"expires_in")).WillOnce(::Return(expiresIn));
144 EXPECT_CALL(*
json, getProperties()).WillOnce(::ReturnRef(additionalTokenResponseProperties));
146 EXPECT_CALL(*clock, epochSeconds()).WillRepeatedly(::Return(100));
151 std::map<std::string, std::shared_ptr<::JSONElement>> additionalTokenResponseProperties;
152 std::shared_ptr<xdmock::HTTPClientMock> httpClient;
153 std::shared_ptr<xdmock::JSONParserMock> jsonParser;
154 std::shared_ptr<xdutl::Base64Encoder> base64Encoder;
155 std::shared_ptr<xdmock::MessageDigestFactoryMock> messageDigestFactory;
156 std::shared_ptr<xdmock::ClockMock> clock;
157 std::shared_ptr<xdmock::RandomBytesMock> randomBytes;
159 std::unique_ptr<xdpkce::OAuthPKCEFlow>
oauth;