FIRAuthBackendRPCImplementationTests.m 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. #import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
  18. #import "FirebaseAuth/Sources/Backend/FIRAuthRPCRequest.h"
  19. #import "FirebaseAuth/Sources/Backend/FIRAuthRPCResponse.h"
  20. #import "FirebaseAuth/Sources/Backend/FIRAuthRequestConfiguration.h"
  21. #import "FirebaseAuth/Sources/Utilities/FIRAuthErrorUtils.h"
  22. #import "FirebaseAuth/Sources/Utilities/FIRAuthInternalErrors.h"
  23. #import "FirebaseAuth/Tests/Unit/FIRFakeBackendRPCIssuer.h"
  24. /** @var kFakeRequestURL
  25. @brief Used as a fake URL for a fake RPC request. We don't test this here, since it's tested
  26. for the specific RPC requests in their various unit tests.
  27. */
  28. static NSString *const kFakeRequestURL = @"https://www.google.com/";
  29. /** @var kFakeAPIkey
  30. @brief Used as a fake APIKey for a fake RPC request. We don't test this here.
  31. */
  32. static NSString *const kFakeAPIkey = @"FAKE_API_KEY";
  33. /** @var kFakeErrorDomain
  34. @brief A value to use for fake @c NSErrors.
  35. */
  36. static NSString *const kFakeErrorDomain = @"fakeDomain";
  37. /** @var kFakeErrorCode
  38. @brief A value to use for fake @c NSErrors.
  39. */
  40. static const NSUInteger kFakeErrorCode = -1;
  41. /** @var kUnknownServerErrorMessage
  42. @brief A value to use for fake server errors with an unknown message.
  43. */
  44. static NSString *const kUnknownServerErrorMessage = @"UNKNOWN_MESSAGE";
  45. /** @var kErrorMessageCaptchaRequired
  46. @brief The error message in JSON responses from the server for CAPTCHA required.
  47. */
  48. static NSString *const kErrorMessageCaptchaRequired = @"CAPTCHA_REQUIRED";
  49. /** @var kErrorMessageCaptchaRequiredInvalidPassword
  50. @brief The error message in JSON responses from the server for CAPTCHA required with invalid
  51. password.
  52. */
  53. static NSString *const kErrorMessageCaptchaRequiredInvalidPassword =
  54. @"CAPTCHA_REQUIRED_INVALID_PASSWORD";
  55. /** @var kErrorMessageCaptchaCheckFailed
  56. @brief The error message in JSON responses from the server for CAPTCHA check failed.
  57. */
  58. static NSString *const kErrorMessageCaptchaCheckFailed = @"CAPTCHA_CHECK_FAILED";
  59. /** @var kErrorMessageEmailExists
  60. @brief The error message in JSON responses from the server for user's email already exists.
  61. */
  62. static NSString *const kErrorMessageEmailExists = @"EMAIL_EXISTS";
  63. /** @var kErrorMessageKey
  64. @brief The key for the error message in an error response.
  65. */
  66. static NSString *const kErrorMessageKey = @"message";
  67. /** @var kTestKey
  68. @brief A key to use for a successful response dictionary.
  69. */
  70. static NSString *const kTestKey = @"TestKey";
  71. /** @var kUserDisabledErrorMessage
  72. @brief This is the base error message the server will respond with if the user's account has
  73. been disabled.
  74. */
  75. static NSString *const kUserDisabledErrorMessage = @"USER_DISABLED";
  76. /** @var kFakeUserDisabledCustomErrorMessage
  77. @brief This is a fake custom error message the server can respond with if the user's account has
  78. been disabled.
  79. */
  80. static NSString *const kFakeUserDisabledCustomErrorMessage = @"The user has been disabled.";
  81. /** @var kServerErrorDetailMarker
  82. @brief This marker indicates that the server error message contains a detail error message which
  83. should be used instead of the hardcoded client error message.
  84. */
  85. static NSString *const kServerErrorDetailMarker = @" : ";
  86. /** @var kTestValue
  87. @brief A value to use for a successful response dictionary.
  88. */
  89. static NSString *const kTestValue = @"TestValue";
  90. /** @class FIRAuthBackendRPCImplementation
  91. @brief Exposes an otherwise private class to these tests. See the real implementation for
  92. documentation.
  93. */
  94. @interface FIRAuthBackendRPCImplementation : NSObject <FIRAuthBackendImplementation>
  95. /** @fn postWithRequest:response:callback:
  96. @brief Calls the RPC using HTTP POST.
  97. @remarks Possible error responses:
  98. @see FIRAuthInternalErrorCodeRPCRequestEncodingError
  99. @see FIRAuthInternalErrorCodeJSONSerializationError
  100. @see FIRAuthInternalErrorCodeNetworkError
  101. @see FIRAuthInternalErrorCodeUnexpectedErrorResponse
  102. @see FIRAuthInternalErrorCodeUnexpectedResponse
  103. @see FIRAuthInternalErrorCodeRPCResponseDecodingError
  104. @param request The request.
  105. @param response The empty response to be filled.
  106. @param callback The callback for both success and failure.
  107. */
  108. - (void)postWithRequest:(id<FIRAuthRPCRequest>)request
  109. response:(id<FIRAuthRPCResponse>)response
  110. callback:(void (^)(NSError *error))callback;
  111. @end
  112. /** @class FIRFakeRequest
  113. @brief Allows us to fake a request with deterministic request bodies and encoding errors
  114. returned from the @c FIRAuthRPCRequest-specified @c unencodedHTTPRequestBodyWithError:
  115. method.
  116. */
  117. @interface FIRFakeRequest : NSObject <FIRAuthRPCRequest>
  118. /** @fn fakeRequest
  119. @brief A "normal" request which returns an encodable request object with no error.
  120. */
  121. + (nullable instancetype)fakeRequest;
  122. /** @fn fakeRequestWithEncodingError
  123. @brief A request which returns a fake error during the encoding process.
  124. */
  125. + (nullable instancetype)fakeRequestWithEncodingError:(NSError *)error;
  126. /** @fn fakeRequestWithUnserializableRequestBody
  127. @brief A request which returns a request object which can not be properly serialized by
  128. @c NSJSONSerialization.
  129. */
  130. + (nullable instancetype)fakeRequestWithUnserializableRequestBody;
  131. /** @fn fakeRequestWithNoBody
  132. @brief A request which returns a nil request body but no error.
  133. */
  134. + (nullable instancetype)fakeRequestWithNoBody;
  135. /** @fn init
  136. @brief Please use initWithRequestBody:encodingError:
  137. */
  138. - (nullable instancetype)init NS_UNAVAILABLE;
  139. /** @fn initWithRequestBody:encodingError:
  140. @brief Designated initializer.
  141. @param requestBody The fake request body to return when @c unencodedHTTPRequestBodyWithError: is
  142. invoked.
  143. @param encodingError The fake error to return when @c unencodedHTTPRequestBodyWithError is
  144. invoked.
  145. */
  146. - (nullable instancetype)initWithRequestBody:(nullable id)requestBody
  147. encodingError:(nullable NSError *)encodingError
  148. NS_DESIGNATED_INITIALIZER;
  149. @end
  150. @implementation FIRFakeRequest {
  151. /** @var _requestBody
  152. @brief The fake request body object we will return when @c unencodedHTTPRequestBodyWithError:
  153. is invoked.
  154. */
  155. id _Nullable _requestBody;
  156. /** @var _requestEncodingError
  157. @brief The fake error object we will return when @c unencodedHTTPRequestBodyWithError:
  158. is invoked.
  159. */
  160. NSError *_Nullable _requestEncodingError;
  161. }
  162. + (nullable instancetype)fakeRequest {
  163. return [[self alloc] initWithRequestBody:@{} encodingError:nil];
  164. }
  165. + (nullable instancetype)fakeRequestWithEncodingError:(NSError *)error {
  166. return [[self alloc] initWithRequestBody:nil encodingError:error];
  167. }
  168. + (nullable instancetype)fakeRequestWithUnserializableRequestBody {
  169. return [[self alloc] initWithRequestBody:@{@"unencodableValue" : self} encodingError:nil];
  170. }
  171. + (nullable instancetype)fakeRequestWithNoBody {
  172. return [[self alloc] initWithRequestBody:nil encodingError:nil];
  173. }
  174. - (nullable instancetype)initWithRequestBody:(nullable id)requestBody
  175. encodingError:(nullable NSError *)encodingError {
  176. self = [super init];
  177. if (self) {
  178. _requestBody = requestBody;
  179. _requestEncodingError = encodingError;
  180. }
  181. return self;
  182. }
  183. - (NSURL *)requestURL {
  184. return [NSURL URLWithString:kFakeRequestURL];
  185. }
  186. - (BOOL)containsPostBody {
  187. return YES;
  188. }
  189. - (FIRAuthRequestConfiguration *)requestConfiguration {
  190. FIRAuthRequestConfiguration *fakeConfiguration =
  191. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kFakeAPIkey];
  192. return fakeConfiguration;
  193. }
  194. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  195. if (error) {
  196. *error = _requestEncodingError;
  197. }
  198. return _requestBody;
  199. }
  200. @end
  201. /** @class FIRFakeResponse
  202. @brief Allows us to inspect the dictionaries received by @c FIRAuthRPCResponse classes, and
  203. provide deterministic responses to the @c setWithDictionary:error:
  204. methods.
  205. */
  206. @interface FIRFakeResponse : NSObject <FIRAuthRPCResponse>
  207. /** @property receivedDictionary
  208. @brief The dictionary passed to the @c setWithDictionary:error: method.
  209. */
  210. @property(nonatomic, strong, readonly, nullable) NSDictionary *receivedDictionary;
  211. /** @fn fakeResponse
  212. @brief A "normal" sucessful response (no error, no expected kind.)
  213. */
  214. + (nullable instancetype)fakeResponse;
  215. /** @fn fakeResponseWithDecodingError
  216. @brief A response which returns a fake error during the decoding process.
  217. */
  218. + (nullable instancetype)fakeResponseWithDecodingError;
  219. /** @fn init
  220. @brief Please use initWithDecodingError:
  221. */
  222. - (nullable instancetype)init NS_UNAVAILABLE;
  223. - (nullable instancetype)initWithDecodingError:(nullable NSError *)decodingError
  224. NS_DESIGNATED_INITIALIZER;
  225. @end
  226. @implementation FIRFakeResponse {
  227. /** @var _responseDecodingError
  228. @brief The value to return for an error when the @c setWithDictionary:error: method is
  229. invoked.
  230. */
  231. NSError *_Nullable _responseDecodingError;
  232. }
  233. + (nullable instancetype)fakeResponse {
  234. return [[self alloc] initWithDecodingError:nil];
  235. }
  236. + (nullable instancetype)fakeResponseWithDecodingError {
  237. NSError *decodingError = [FIRAuthErrorUtils unexpectedErrorResponseWithDeserializedResponse:self];
  238. return [[self alloc] initWithDecodingError:decodingError];
  239. }
  240. - (nullable instancetype)initWithDecodingError:(nullable NSError *)decodingError {
  241. self = [super init];
  242. if (self) {
  243. _responseDecodingError = decodingError;
  244. }
  245. return self;
  246. }
  247. - (BOOL)setWithDictionary:(NSDictionary *)dictionary error:(NSError *_Nullable *_Nullable)error {
  248. if (_responseDecodingError) {
  249. if (error) {
  250. *error = _responseDecodingError;
  251. }
  252. return NO;
  253. }
  254. _receivedDictionary = dictionary;
  255. return YES;
  256. }
  257. @end
  258. /** @class FIRAuthBackendRPCImplementationTests
  259. @brief This set of unit tests is designed primarily to test the possible outcomes of the
  260. @c FIRAuthBackendRPCImplementation.postWithRequest:response:callback: method.
  261. */
  262. @interface FIRAuthBackendRPCImplementationTests : XCTestCase
  263. @end
  264. @implementation FIRAuthBackendRPCImplementationTests {
  265. /** @var _RPCIssuer
  266. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  267. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  268. */
  269. FIRFakeBackendRPCIssuer *_RPCIssuer;
  270. /** @var _RPCImplementation
  271. @brief This backend RPC implementation is used to make fake network requests for each test in
  272. the suite.
  273. */
  274. FIRAuthBackendRPCImplementation *_RPCImplementation;
  275. }
  276. - (void)setUp {
  277. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  278. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  279. _RPCIssuer = RPCIssuer;
  280. _RPCImplementation = [FIRAuthBackend implementation];
  281. }
  282. - (void)tearDown {
  283. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  284. _RPCIssuer = nil;
  285. _RPCImplementation = nil;
  286. }
  287. /** @fn testRequestEncodingError
  288. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  289. request passed returns an error during it's unencodedHTTPRequestBodyWithError: method.
  290. The error returned should be delivered to the caller without any change.
  291. */
  292. - (void)testRequestEncodingError {
  293. NSError *encodingError = [NSError errorWithDomain:kFakeErrorDomain
  294. code:kFakeErrorCode
  295. userInfo:@{}];
  296. FIRFakeRequest *request = [FIRFakeRequest fakeRequestWithEncodingError:encodingError];
  297. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  298. __block NSError *callbackError;
  299. __block BOOL callbackInvoked;
  300. [_RPCImplementation postWithRequest:request
  301. response:response
  302. callback:^(NSError *error) {
  303. callbackInvoked = YES;
  304. callbackError = error;
  305. }];
  306. // There is no need to call [_RPCIssuer respondWithError:...] in this test because a request
  307. // should never have been tried - and we we know that's the case when we test @c callbackInvoked.
  308. XCTAssert(callbackInvoked);
  309. XCTAssertNotNil(callbackError);
  310. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  311. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  312. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  313. XCTAssertNotNil(underlyingError);
  314. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  315. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeRPCRequestEncodingError);
  316. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  317. XCTAssertNotNil(underlyingUnderlyingError);
  318. XCTAssertEqualObjects(underlyingUnderlyingError.domain, kFakeErrorDomain);
  319. XCTAssertEqual(underlyingUnderlyingError.code, kFakeErrorCode);
  320. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  321. XCTAssertNil(deserializedResponse);
  322. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  323. XCTAssertNil(dataResponse);
  324. }
  325. /** @fn testBodyDataSerializationError
  326. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  327. request returns an object which isn't serializable by @c NSJSONSerialization.
  328. The error from @c NSJSONSerialization should be returned as the underlyingError for an
  329. @c NSError with the code @c FIRAuthErrorCodeJSONSerializationError.
  330. */
  331. - (void)testBodyDataSerializationError {
  332. FIRFakeRequest *request = [FIRFakeRequest fakeRequestWithUnserializableRequestBody];
  333. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  334. __block NSError *callbackError;
  335. __block BOOL callbackInvoked;
  336. [_RPCImplementation postWithRequest:request
  337. response:response
  338. callback:^(NSError *error) {
  339. callbackInvoked = YES;
  340. callbackError = error;
  341. }];
  342. // There is no need to call [_RPCIssuer respondWithError:...] in this test because a request
  343. // should never have been tried - and we we know that's the case when we test @c callbackInvoked.
  344. XCTAssert(callbackInvoked);
  345. XCTAssertNotNil(callbackError);
  346. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  347. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  348. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  349. XCTAssertNotNil(underlyingError);
  350. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  351. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeJSONSerializationError);
  352. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  353. XCTAssertNil(underlyingUnderlyingError);
  354. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  355. XCTAssertNil(deserializedResponse);
  356. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  357. XCTAssertNil(dataResponse);
  358. }
  359. /** @fn testNetworkError
  360. @brief This test checks to make sure a network error is properly wrapped and forwarded with the
  361. correct code (FIRAuthErrorCodeNetworkError).
  362. */
  363. - (void)testNetworkError {
  364. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  365. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  366. __block NSError *callbackError;
  367. __block BOOL callbackInvoked;
  368. [_RPCImplementation postWithRequest:request
  369. response:response
  370. callback:^(NSError *error) {
  371. callbackInvoked = YES;
  372. callbackError = error;
  373. }];
  374. // It shouldn't matter what the error domain/code/userInfo are, any junk values are suitable. The
  375. // implementation should treat any error with no response data as a network error.
  376. NSError *responseError = [NSError errorWithDomain:kFakeErrorDomain
  377. code:kFakeErrorCode
  378. userInfo:nil];
  379. [_RPCIssuer respondWithError:responseError];
  380. XCTAssert(callbackInvoked);
  381. XCTAssertNotNil(callbackError);
  382. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  383. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeNetworkError);
  384. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  385. XCTAssertNotNil(underlyingError);
  386. XCTAssertEqualObjects(underlyingError.domain, kFakeErrorDomain);
  387. XCTAssertEqual(underlyingError.code, kFakeErrorCode);
  388. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  389. XCTAssertNil(underlyingUnderlyingError);
  390. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  391. XCTAssertNil(deserializedResponse);
  392. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  393. XCTAssertNil(dataResponse);
  394. }
  395. /** @fn testUnparsableErrorResponse
  396. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  397. response isn't deserializable by @c NSJSONSerialization and an error
  398. condition (with an associated error response message) was expected. We are expecting to
  399. receive the original network error wrapped in an @c NSError with the code
  400. @c FIRAuthErrorCodeUnexpectedHTTPResponse.
  401. */
  402. - (void)testUnparsableErrorResponse {
  403. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  404. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  405. __block NSError *callbackError;
  406. __block BOOL callbackInvoked;
  407. [_RPCImplementation postWithRequest:request
  408. response:response
  409. callback:^(NSError *error) {
  410. callbackInvoked = YES;
  411. callbackError = error;
  412. }];
  413. NSData *data =
  414. [@"<html><body>An error occurred.</body></html>" dataUsingEncoding:NSUTF8StringEncoding];
  415. NSError *error = [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{}];
  416. [_RPCIssuer respondWithData:data error:error];
  417. XCTAssert(callbackInvoked);
  418. XCTAssertNotNil(callbackError);
  419. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  420. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  421. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  422. XCTAssertNotNil(underlyingError);
  423. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  424. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  425. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  426. XCTAssertNotNil(underlyingUnderlyingError);
  427. XCTAssertEqualObjects(underlyingUnderlyingError.domain, kFakeErrorDomain);
  428. XCTAssertEqual(underlyingUnderlyingError.code, kFakeErrorCode);
  429. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  430. XCTAssertNil(deserializedResponse);
  431. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  432. XCTAssertNotNil(dataResponse);
  433. XCTAssertEqualObjects(dataResponse, data);
  434. }
  435. /** @fn testUnparsableSuccessResponse
  436. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  437. response isn't deserializable by @c NSJSONSerialization and no error
  438. condition was indicated. We are expecting to
  439. receive the @c NSJSONSerialization error wrapped in an @c NSError with the code
  440. @c FIRAuthErrorCodeUnexpectedServerResponse.
  441. */
  442. - (void)testUnparsableSuccessResponse {
  443. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  444. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  445. __block NSError *callbackError;
  446. __block BOOL callbackInvoked;
  447. [_RPCImplementation postWithRequest:request
  448. response:response
  449. callback:^(NSError *error) {
  450. callbackInvoked = YES;
  451. callbackError = error;
  452. }];
  453. NSData *data = [@"<xml>Some non-JSON value.</xml>" dataUsingEncoding:NSUTF8StringEncoding];
  454. [_RPCIssuer respondWithData:data error:nil];
  455. XCTAssert(callbackInvoked);
  456. XCTAssertNotNil(callbackError);
  457. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  458. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  459. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  460. XCTAssertNotNil(underlyingError);
  461. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  462. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedResponse);
  463. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  464. XCTAssertNotNil(underlyingUnderlyingError);
  465. XCTAssertEqualObjects(underlyingUnderlyingError.domain, NSCocoaErrorDomain);
  466. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  467. XCTAssertNil(deserializedResponse);
  468. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  469. XCTAssertNotNil(dataResponse);
  470. XCTAssertEqualObjects(dataResponse, data);
  471. }
  472. /** @fn testNonDictionaryErrorResponse
  473. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  474. response deserialized by @c NSJSONSerialization is not a dictionary, and an error was
  475. expected. We are expecting to receive an @c NSError with the code
  476. @c FIRAuthErrorCodeUnexpectedErrorServerResponse with the decoded response in the
  477. @c NSError.userInfo dictionary associated with the key
  478. @c FIRAuthErrorUserInfoDecodedResponseKey.
  479. */
  480. - (void)testNonDictionaryErrorResponse {
  481. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  482. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  483. __block NSError *callbackError;
  484. __block BOOL callbackInvoked;
  485. [_RPCImplementation postWithRequest:request
  486. response:response
  487. callback:^(NSError *error) {
  488. callbackInvoked = YES;
  489. callbackError = error;
  490. }];
  491. // We are responding with a JSON-encoded string value representing an array - which is unexpected.
  492. // It should normally be a dictionary, and we need to check for this sort of thing. Because we can
  493. // successfully decode this value, however, we do return it in the error results. We check for
  494. // this array later in the test.
  495. NSData *data = [@"[]" dataUsingEncoding:NSUTF8StringEncoding];
  496. NSError *error = [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{}];
  497. [_RPCIssuer respondWithData:data error:error];
  498. XCTAssert(callbackInvoked);
  499. XCTAssertNotNil(callbackError);
  500. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  501. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  502. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  503. XCTAssertNotNil(underlyingError);
  504. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  505. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  506. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  507. XCTAssertNil(underlyingUnderlyingError);
  508. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  509. XCTAssertNotNil(deserializedResponse);
  510. XCTAssert([deserializedResponse isKindOfClass:[NSArray class]]);
  511. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  512. XCTAssertNil(dataResponse);
  513. }
  514. /** @fn testNonDictionarySuccessResponse
  515. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  516. response deserialized by @c NSJSONSerialization is not a dictionary, and no error was
  517. expected. We are expecting to receive an @c NSError with the code
  518. @c FIRAuthErrorCodeUnexpectedServerResponse with the decoded response in the
  519. @c NSError.userInfo dictionary associated with the key
  520. @c FIRAuthErrorUserInfoDecodedResponseKey.
  521. */
  522. - (void)testNonDictionarySuccessResponse {
  523. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  524. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  525. __block NSError *callbackError;
  526. __block BOOL callbackInvoked;
  527. [_RPCImplementation postWithRequest:request
  528. response:response
  529. callback:^(NSError *error) {
  530. callbackInvoked = YES;
  531. callbackError = error;
  532. }];
  533. // We are responding with a JSON-encoded string value representing an array - which is unexpected.
  534. // It should normally be a dictionary, and we need to check for this sort of thing. Because we can
  535. // successfully decode this value, however, we do return it in the error results. We check for
  536. // this array later in the test.
  537. NSData *data = [@"[]" dataUsingEncoding:NSUTF8StringEncoding];
  538. [_RPCIssuer respondWithData:data error:nil];
  539. XCTAssert(callbackInvoked);
  540. XCTAssertNotNil(callbackError);
  541. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  542. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  543. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  544. XCTAssertNotNil(underlyingError);
  545. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  546. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedResponse);
  547. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  548. XCTAssertNil(underlyingUnderlyingError);
  549. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  550. XCTAssertNotNil(deserializedResponse);
  551. XCTAssert([deserializedResponse isKindOfClass:[NSArray class]]);
  552. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  553. XCTAssertNil(dataResponse);
  554. }
  555. /** @fn testCaptchaRequiredResponse
  556. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  557. we get an error message indicating captcha is required. The backend should not be returning
  558. this error to mobile clients. If it does, we should wrap it in an @c NSError with the code
  559. @c FIRAuthErrorCodeUnexpectedServerResponse with the decoded error message in the
  560. @c NSError.userInfo dictionary associated with the key
  561. @c FIRAuthErrorUserInfoDecodedErrorResponseKey.
  562. */
  563. - (void)testCaptchaRequiredResponse {
  564. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  565. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  566. __block NSError *callbackError;
  567. __block BOOL callbackInvoked;
  568. [_RPCImplementation postWithRequest:request
  569. response:response
  570. callback:^(NSError *error) {
  571. callbackInvoked = YES;
  572. callbackError = error;
  573. }];
  574. NSError *error = [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{}];
  575. [_RPCIssuer respondWithServerErrorMessage:kErrorMessageCaptchaRequired error:error];
  576. XCTAssert(callbackInvoked);
  577. XCTAssertNotNil(callbackError);
  578. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  579. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  580. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  581. XCTAssertNotNil(underlyingError);
  582. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  583. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  584. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  585. XCTAssertNil(underlyingUnderlyingError);
  586. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  587. XCTAssertNotNil(deserializedResponse);
  588. XCTAssert([deserializedResponse isKindOfClass:[NSDictionary class]]);
  589. XCTAssertNotNil(deserializedResponse[@"message"]);
  590. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  591. XCTAssertNil(dataResponse);
  592. }
  593. /** @fn testCaptchaCheckFailedResponse
  594. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  595. we get an error message indicating captcha check failed. The backend should not be returning
  596. this error to mobile clients. If it does, we should wrap it in an @c NSError with the code
  597. @c FIRAuthErrorCodeUnexpectedServerResponse with the decoded error message in the
  598. @c NSError.userInfo dictionary associated with the key
  599. @c FIRAuthErrorUserInfoDecodedErrorResponseKey.
  600. */
  601. - (void)testCaptchaCheckFailedResponse {
  602. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  603. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  604. __block NSError *callbackError;
  605. __block BOOL callbackInvoked;
  606. [_RPCImplementation postWithRequest:request
  607. response:response
  608. callback:^(NSError *error) {
  609. callbackInvoked = YES;
  610. callbackError = error;
  611. }];
  612. NSError *error = [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{}];
  613. [_RPCIssuer respondWithServerErrorMessage:kErrorMessageCaptchaCheckFailed error:error];
  614. XCTAssert(callbackInvoked);
  615. XCTAssertNotNil(callbackError);
  616. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  617. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeCaptchaCheckFailed);
  618. }
  619. /** @fn testCaptchaRequiredInvalidPasswordResponse
  620. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  621. we get an error message indicating captcha is required and an invalid password was entered.
  622. The backend should not be returning this error to mobile clients. If it does, we should wrap
  623. it in an @c NSError with the code
  624. @c FIRAuthErrorCodeUnexpectedServerResponse with the decoded error message in the
  625. @c NSError.userInfo dictionary associated with the key
  626. @c FIRAuthErrorUserInfoDecodedErrorResponseKey.
  627. */
  628. - (void)testCaptchaRequiredInvalidPasswordResponse {
  629. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  630. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  631. __block NSError *callbackError;
  632. __block BOOL callbackInvoked;
  633. [_RPCImplementation postWithRequest:request
  634. response:response
  635. callback:^(NSError *error) {
  636. callbackInvoked = YES;
  637. callbackError = error;
  638. }];
  639. NSError *error = [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{}];
  640. [_RPCIssuer respondWithServerErrorMessage:kErrorMessageCaptchaRequiredInvalidPassword
  641. error:error];
  642. XCTAssert(callbackInvoked);
  643. XCTAssertNotNil(callbackError);
  644. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  645. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  646. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  647. XCTAssertNotNil(underlyingError);
  648. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  649. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  650. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  651. XCTAssertNil(underlyingUnderlyingError);
  652. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  653. XCTAssertNotNil(deserializedResponse);
  654. XCTAssert([deserializedResponse isKindOfClass:[NSDictionary class]]);
  655. XCTAssertNotNil(deserializedResponse[@"message"]);
  656. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  657. XCTAssertNil(dataResponse);
  658. }
  659. /** @fn testDecodableErrorResponseWithUnknownMessage
  660. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  661. response deserialized by @c NSJSONSerialization represents a valid error response (and an
  662. error was indicated) but we didn't receive an error message we know about. We are expecting
  663. an @c NSError with the code @c FIRAuthErrorCodeUnexpectedServerResponse with the decoded
  664. error message in the @c NSError.userInfo dictionary associated with the key
  665. @c FIRAuthErrorUserInfoDecodedErrorResponseKey.
  666. */
  667. - (void)testDecodableErrorResponseWithUnknownMessage {
  668. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  669. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  670. __block NSError *callbackError;
  671. __block BOOL callbackInvoked;
  672. [_RPCImplementation postWithRequest:request
  673. response:response
  674. callback:^(NSError *error) {
  675. callbackInvoked = YES;
  676. callbackError = error;
  677. }];
  678. // We need to return a valid "error" response here, but we are going to intentionally use a bogus
  679. // error message.
  680. NSError *error = [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{}];
  681. [_RPCIssuer respondWithServerErrorMessage:kUnknownServerErrorMessage error:error];
  682. XCTAssert(callbackInvoked);
  683. XCTAssertNotNil(callbackError);
  684. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  685. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  686. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  687. XCTAssertNotNil(underlyingError);
  688. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  689. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  690. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  691. XCTAssertNil(underlyingUnderlyingError);
  692. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  693. XCTAssertNotNil(deserializedResponse);
  694. XCTAssert([deserializedResponse isKindOfClass:[NSDictionary class]]);
  695. XCTAssertNotNil(deserializedResponse[@"message"]);
  696. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  697. XCTAssertNil(dataResponse);
  698. }
  699. /** @fn testErrorResponseWithNoErrorMessage
  700. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  701. response deserialized by @c NSJSONSerialization is a dictionary, and an error was indicated,
  702. but no error information was present in the decoded response. We are expecting an @c NSError
  703. with the code @c FIRAuthErrorCodeUnexpectedServerResponse with the decoded
  704. response message in the @c NSError.userInfo dictionary associated with the key
  705. @c FIRAuthErrorUserInfoDecodedResponseKey.
  706. */
  707. - (void)testErrorResponseWithNoErrorMessage {
  708. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  709. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  710. __block NSError *callbackError;
  711. __block BOOL callbackInvoked;
  712. [_RPCImplementation postWithRequest:request
  713. response:response
  714. callback:^(NSError *error) {
  715. callbackInvoked = YES;
  716. callbackError = error;
  717. }];
  718. NSError *error = [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{}];
  719. [_RPCIssuer respondWithJSON:@{} error:error];
  720. XCTAssert(callbackInvoked);
  721. XCTAssertNotNil(callbackError);
  722. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  723. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  724. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  725. XCTAssertNotNil(underlyingError);
  726. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  727. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  728. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  729. XCTAssertNil(underlyingUnderlyingError);
  730. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  731. XCTAssertNotNil(deserializedResponse);
  732. XCTAssert([deserializedResponse isKindOfClass:[NSDictionary class]]);
  733. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  734. XCTAssertNil(dataResponse);
  735. }
  736. /** @fn testClientErrorResponse
  737. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  738. response contains a client error specified by an error messsage sent from the backend.
  739. */
  740. - (void)testClientErrorResponse {
  741. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  742. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  743. __block NSError *callbackerror;
  744. __block BOOL callBackInvoked;
  745. [_RPCImplementation postWithRequest:request
  746. response:response
  747. callback:^(NSError *error) {
  748. callBackInvoked = YES;
  749. callbackerror = error;
  750. }];
  751. NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil];
  752. NSString *customErrorMessage =
  753. [NSString stringWithFormat:@"%@%@%@", kUserDisabledErrorMessage, kServerErrorDetailMarker,
  754. kFakeUserDisabledCustomErrorMessage];
  755. [_RPCIssuer respondWithServerErrorMessage:customErrorMessage error:error];
  756. XCTAssertNotNil(callbackerror, @"An error should be returned from callback.");
  757. XCTAssert(callBackInvoked);
  758. XCTAssertEqual(callbackerror.code, FIRAuthErrorCodeUserDisabled);
  759. NSString *customMessage = callbackerror.userInfo[NSLocalizedDescriptionKey];
  760. XCTAssertEqualObjects(customMessage, kFakeUserDisabledCustomErrorMessage);
  761. }
  762. /** @fn testUndecodableSuccessResponse
  763. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  764. response isn't decodable by the response class but no error condition was expected. We are
  765. expecting to receive an @c NSError with the code
  766. @c FIRAuthErrorCodeUnexpectedServerResponse and the error from @c setWithDictionary:error:
  767. as the value of the underlyingError.
  768. */
  769. - (void)testUndecodableSuccessResponse {
  770. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  771. FIRFakeResponse *response = [FIRFakeResponse fakeResponseWithDecodingError];
  772. __block NSError *callbackError;
  773. __block BOOL callbackInvoked;
  774. [_RPCImplementation postWithRequest:request
  775. response:response
  776. callback:^(NSError *error) {
  777. callbackInvoked = YES;
  778. callbackError = error;
  779. }];
  780. // It doesn't matter what we respond with here, as long as it's not an error response. The fake
  781. // response will deterministicly simulate a decoding error regardless of the response value it was
  782. // given.
  783. [_RPCIssuer respondWithJSON:@{}];
  784. XCTAssert(callbackInvoked);
  785. XCTAssertNotNil(callbackError);
  786. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  787. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  788. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  789. XCTAssertNotNil(underlyingError);
  790. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  791. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeRPCResponseDecodingError);
  792. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  793. XCTAssertNotNil(deserializedResponse);
  794. XCTAssert([deserializedResponse isKindOfClass:[NSDictionary class]]);
  795. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  796. XCTAssertNil(dataResponse);
  797. }
  798. /** @fn testSuccessfulResponse
  799. @brief Tests that a decoded dictionary is handed to the response instance.
  800. */
  801. - (void)testSuccessfulResponse {
  802. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  803. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  804. __block NSError *callbackError;
  805. __block BOOL callbackInvoked;
  806. [_RPCImplementation postWithRequest:request
  807. response:response
  808. callback:^(NSError *error) {
  809. callbackInvoked = YES;
  810. callbackError = error;
  811. }];
  812. [_RPCIssuer respondWithJSON:@{kTestKey : kTestValue}];
  813. XCTAssert(callbackInvoked);
  814. XCTAssertNil(callbackError);
  815. XCTAssertNotNil(response.receivedDictionary);
  816. XCTAssertEqualObjects(response.receivedDictionary[kTestKey], kTestValue);
  817. }
  818. @end