83 FakeRequest * mkRequest(
const std::uint64_t localTimeoutS = 100)
85 std::map<std::string, std::string> params;
86 params.emplace(
"key-1",
"value-1");
87 params.emplace(
"key-2",
"value-2");
93 std::make_shared<::OAuthConfiguration>(
99 ::OAuthConfiguration::DEVICE,
104 std::make_shared<::HTTPResponseToException>(),
109 void SetUp()
override
111 clock = ::ClockMock::createShared();
112 httpClient = ::HTTPClientMock::createShared();
113 jsonParser = ::JSONParserMock::createShared();
114 urlEncoder = ::URLEncoderMock::createShared();
116 request.reset(mkRequest());
119 std::shared_ptr<FakeRequest> request;
120 std::shared_ptr<::ClockMock> clock;
121 std::shared_ptr<::HTTPClientMock> httpClient;
122 std::shared_ptr<::JSONParserMock> jsonParser;
123 std::shared_ptr<::URLEncoderMock> urlEncoder;
125 std::map<std::string, std::shared_ptr<::JSONElement>> tokenResponseProps;
127 void stubAuthorizationRequest(
128 const std::int64_t expiresIn = 42,
129 const std::int64_t interval = 69
132 auto document = ::JSONObjectMock::create();
133 EXPECT_CALL(*jsonParser, from(
"successful-authorization-request")).WillOnce(::Return(std::unique_ptr<::JSONObjectMock>(document)));
134 EXPECT_CALL(*document, getProperty(
"device_code")).WillRepeatedly(::Return(::JSONStringMock::createShared(
"-device-code-")));
135 EXPECT_CALL(*document, getProperty(
"user_code")).WillRepeatedly(::Return(::JSONStringMock::createShared(
"-user-code-")));
136 EXPECT_CALL(*document, getProperty(
"verification_uri")).WillRepeatedly(::Return(::JSONStringMock::createShared(
"/verify")));
137 EXPECT_CALL(*document, getProperty(
"verification_uri_complete")).WillRepeatedly(::Return(::JSONStringMock::createShared(
"/verify-complete")));
138 EXPECT_CALL(*document, getProperty(
"expires_in")).WillRepeatedly(::Return(::JSONNumberMock::createShared(expiresIn)));
140 EXPECT_CALL(*document, getProperty(
"interval")).WillRepeatedly(::Return(::JSONNumberMock::createShared(interval)));
143 EXPECT_CALL(*document, getProperty(
"interval")).WillRepeatedly(::Return(
nullptr));
146 void stubSuccessfulTokenRequest()
148 auto document = ::JSONObjectMock::create();
149 EXPECT_CALL(*jsonParser, from(
"successful-token-request")).WillOnce(::Return(std::unique_ptr<::JSONObjectMock>(document)));
150 EXPECT_CALL(*document, removeProperty(
"access_token")).WillOnce(::Return(::JSONStringMock::createShared(
"at")));
151 EXPECT_CALL(*document, removeProperty(
"refresh_token")).WillOnce(::Return(::JSONStringMock::createShared(
"rt")));
152 EXPECT_CALL(*document, removeProperty(
"expires_in")).WillOnce(::Return(::JSONNumberMock::createShared(77)));
154 tokenResponseProps.emplace(
"key-1", ::JSONStringMock::createShared(
"value-1"));
155 tokenResponseProps.emplace(
"key-2", ::JSONStringMock::createShared(
"value-2"));
157 EXPECT_CALL(*document, getProperties()).WillOnce(::ReturnRef(tokenResponseProps));
159 void stubErrorResponses(
160 const unsigned int numTimes,
161 const std::string jsonPayload,
162 const std::string error
164 auto &documentStub = EXPECT_CALL(*jsonParser, from(jsonPayload));
165 for (
unsigned int i = 0; i < numTimes; i++) {
166 auto document = ::JSONObjectMock::create();
167 documentStub.WillOnce(::Return(std::unique_ptr<::JSONObjectMock>(document)));
168 EXPECT_CALL(*document, getProperty(
"error")).WillRepeatedly(::Return(::JSONStringMock::createShared(error)));
169 EXPECT_CALL(*document, getProperty(
"error_description")).WillRepeatedly(::Return(::JSONStringMock::createShared(
"simulated_error")));
172 void stubAuthorizationPending(
const unsigned int numTimes) {
173 stubErrorResponses(numTimes,
"authorization-pending",
"authorization_pending");
175 void stubSlowDown(
const unsigned int numTimes)
177 stubErrorResponses(numTimes,
"slow-down",
"slow_down");