FIRAuthBackendRPCImplementationTests.m 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  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 "FIRAuthErrorUtils.h"
  18. #import "FIRAuthInternalErrors.h"
  19. #import "FIRAuthBackend.h"
  20. #import "FIRAuthRequestConfiguration.h"
  21. #import "FIRAuthRPCRequest.h"
  22. #import "FIRAuthRPCResponse.h"
  23. #import "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. /** @extension FIRAuthBackend
  113. @brief This class extension exposes the otherwise private @c implementation method. We use this
  114. here to directly call the @c postWithRequest:response:callback: method of
  115. @c FIRAuthBackendRPCImplementation in some of the tests.
  116. */
  117. @interface FIRAuthBackend ()
  118. /** @fn implementation
  119. @brief Exposes the otherwise private @c implementation method. We use this here to directly call
  120. the @c postWithRequest:response:callback: method of @c FIRAuthBackendRPCImplementation in
  121. some of the tests.
  122. */
  123. + (FIRAuthBackendRPCImplementation *)implementation;
  124. @end
  125. /** @class FIRFakeRequest
  126. @brief Allows us to fake a request with deterministic request bodies and encoding errors
  127. returned from the @c FIRAuthRPCRequest-specified @c unencodedHTTPRequestBodyWithError:
  128. method.
  129. */
  130. @interface FIRFakeRequest : NSObject <FIRAuthRPCRequest>
  131. /** @fn fakeRequest
  132. @brief A "normal" request which returns an encodable request object with no error.
  133. */
  134. + (nullable instancetype)fakeRequest;
  135. /** @fn fakeRequestWithEncodingError
  136. @brief A request which returns a fake error during the encoding process.
  137. */
  138. + (nullable instancetype)fakeRequestWithEncodingError:(NSError *)error;
  139. /** @fn fakeRequestWithUnserializableRequestBody
  140. @brief A request which returns a request object which can not be properly serialized by
  141. @c NSJSONSerialization.
  142. */
  143. + (nullable instancetype)fakeRequestWithUnserializableRequestBody;
  144. /** @fn fakeRequestWithNoBody
  145. @brief A request which returns a nil request body but no error.
  146. */
  147. + (nullable instancetype)fakeRequestWithNoBody;
  148. /** @fn init
  149. @brief Please use initWithRequestBody:encodingError:
  150. */
  151. - (nullable instancetype)init NS_UNAVAILABLE;
  152. /** @fn initWithRequestBody:encodingError:
  153. @brief Designated initializer.
  154. @param requestBody The fake request body to return when @c unencodedHTTPRequestBodyWithError: is
  155. invoked.
  156. @param encodingError The fake error to return when @c unencodedHTTPRequestBodyWithError is
  157. invoked.
  158. */
  159. - (nullable instancetype)initWithRequestBody:(nullable id)requestBody
  160. encodingError:(nullable NSError *)encodingError
  161. NS_DESIGNATED_INITIALIZER;
  162. @end
  163. @implementation FIRFakeRequest {
  164. /** @var _requestBody
  165. @brief The fake request body object we will return when @c unencodedHTTPRequestBodyWithError:
  166. is invoked.
  167. */
  168. id _Nullable _requestBody;
  169. /** @var _requestEncodingError
  170. @brief The fake error object we will return when @c unencodedHTTPRequestBodyWithError:
  171. is invoked.
  172. */
  173. NSError *_Nullable _requestEncodingError;
  174. }
  175. + (nullable instancetype)fakeRequest {
  176. return [[self alloc] initWithRequestBody:@{ } encodingError:nil];
  177. }
  178. + (nullable instancetype)fakeRequestWithEncodingError:(NSError *)error {
  179. return [[self alloc] initWithRequestBody:nil encodingError:error];
  180. }
  181. + (nullable instancetype)fakeRequestWithUnserializableRequestBody {
  182. return [[self alloc] initWithRequestBody:@{ @"unencodableValue" : self } encodingError:nil];
  183. }
  184. + (nullable instancetype)fakeRequestWithNoBody {
  185. return [[self alloc] initWithRequestBody:nil encodingError:nil];
  186. }
  187. - (nullable instancetype)initWithRequestBody:(nullable id)requestBody
  188. encodingError:(nullable NSError *)encodingError {
  189. self = [super init];
  190. if (self) {
  191. _requestBody = requestBody;
  192. _requestEncodingError = encodingError;
  193. }
  194. return self;
  195. }
  196. - (NSURL *)requestURL {
  197. return [NSURL URLWithString:kFakeRequestURL];
  198. }
  199. - (BOOL)containsPostBody {
  200. return YES;
  201. }
  202. - (FIRAuthRequestConfiguration *)requestConfiguration {
  203. FIRAuthRequestConfiguration *fakeConfiguration =
  204. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kFakeAPIkey];
  205. return fakeConfiguration;
  206. }
  207. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  208. if (error) {
  209. *error = _requestEncodingError;
  210. }
  211. return _requestBody;
  212. }
  213. @end
  214. /** @class FIRFakeResponse
  215. @brief Allows us to inspect the dictionaries received by @c FIRAuthRPCResponse classes, and
  216. provide deterministic responses to the @c setWithDictionary:error:
  217. methods.
  218. */
  219. @interface FIRFakeResponse : NSObject <FIRAuthRPCResponse>
  220. /** @property receivedDictionary
  221. @brief The dictionary passed to the @c setWithDictionary:error: method.
  222. */
  223. @property(nonatomic, strong, readonly, nullable) NSDictionary *receivedDictionary;
  224. /** @fn fakeResponse
  225. @brief A "normal" sucessful response (no error, no expected kind.)
  226. */
  227. + (nullable instancetype)fakeResponse;
  228. /** @fn fakeResponseWithDecodingError
  229. @brief A response which returns a fake error during the decoding process.
  230. */
  231. + (nullable instancetype)fakeResponseWithDecodingError;
  232. /** @fn init
  233. @brief Please use initWithDecodingError:
  234. */
  235. - (nullable instancetype)init NS_UNAVAILABLE;
  236. - (nullable instancetype)initWithDecodingError:(nullable NSError *)decodingError
  237. NS_DESIGNATED_INITIALIZER;
  238. @end
  239. @implementation FIRFakeResponse {
  240. /** @var _responseDecodingError
  241. @brief The value to return for an error when the @c setWithDictionary:error: method is
  242. invoked.
  243. */
  244. NSError *_Nullable _responseDecodingError;
  245. }
  246. + (nullable instancetype)fakeResponse {
  247. return [[self alloc] initWithDecodingError:nil];
  248. }
  249. + (nullable instancetype)fakeResponseWithDecodingError {
  250. NSError *decodingError = [FIRAuthErrorUtils unexpectedErrorResponseWithDeserializedResponse:self];
  251. return [[self alloc] initWithDecodingError:decodingError];
  252. }
  253. - (nullable instancetype)initWithDecodingError:(nullable NSError *)decodingError {
  254. self = [super init];
  255. if (self) {
  256. _responseDecodingError = decodingError;
  257. }
  258. return self;
  259. }
  260. - (BOOL)setWithDictionary:(NSDictionary *)dictionary
  261. error:(NSError *_Nullable *_Nullable)error {
  262. if (_responseDecodingError) {
  263. if (error) {
  264. *error = _responseDecodingError;
  265. }
  266. return NO;
  267. }
  268. _receivedDictionary = dictionary;
  269. return YES;
  270. }
  271. @end
  272. /** @class FIRAuthBackendRPCImplementationTests
  273. @brief This set of unit tests is designed primarily to test the possible outcomes of the
  274. @c FIRAuthBackendRPCImplementation.postWithRequest:response:callback: method.
  275. */
  276. @interface FIRAuthBackendRPCImplementationTests : XCTestCase
  277. @end
  278. @implementation FIRAuthBackendRPCImplementationTests {
  279. /** @var _RPCIssuer
  280. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  281. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  282. */
  283. FIRFakeBackendRPCIssuer *_RPCIssuer;
  284. /** @var _RPCImplementation
  285. @brief This backend RPC implementation is used to make fake network requests for each test in
  286. the suite.
  287. */
  288. FIRAuthBackendRPCImplementation *_RPCImplementation;
  289. }
  290. - (void)setUp {
  291. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  292. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  293. _RPCIssuer = RPCIssuer;
  294. _RPCImplementation = [FIRAuthBackend implementation];
  295. }
  296. - (void)tearDown {
  297. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  298. _RPCIssuer = nil;
  299. _RPCImplementation = nil;
  300. }
  301. /** @fn testRequestEncodingError
  302. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  303. request passed returns an error during it's unencodedHTTPRequestBodyWithError: method.
  304. The error returned should be delivered to the caller without any change.
  305. */
  306. - (void)testRequestEncodingError {
  307. NSError *encodingError =
  308. [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{ }];
  309. FIRFakeRequest *request = [FIRFakeRequest fakeRequestWithEncodingError:encodingError];
  310. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  311. __block NSError *callbackError;
  312. __block BOOL callbackInvoked;
  313. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  314. callbackInvoked = YES;
  315. callbackError = error;
  316. }];
  317. // There is no need to call [_RPCIssuer respondWithError:...] in this test because a request
  318. // should never have been tried - and we we know that's the case when we test @c callbackInvoked.
  319. XCTAssert(callbackInvoked);
  320. XCTAssertNotNil(callbackError);
  321. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  322. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  323. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  324. XCTAssertNotNil(underlyingError);
  325. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  326. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeRPCRequestEncodingError);
  327. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  328. XCTAssertNotNil(underlyingUnderlyingError);
  329. XCTAssertEqualObjects(underlyingUnderlyingError.domain, kFakeErrorDomain);
  330. XCTAssertEqual(underlyingUnderlyingError.code, kFakeErrorCode);
  331. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  332. XCTAssertNil(deserializedResponse);
  333. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  334. XCTAssertNil(dataResponse);
  335. }
  336. /** @fn testBodyDataSerializationError
  337. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  338. request returns an object which isn't serializable by @c NSJSONSerialization.
  339. The error from @c NSJSONSerialization should be returned as the underlyingError for an
  340. @c NSError with the code @c FIRAuthErrorCodeJSONSerializationError.
  341. */
  342. - (void)testBodyDataSerializationError {
  343. FIRFakeRequest *request = [FIRFakeRequest fakeRequestWithUnserializableRequestBody];
  344. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  345. __block NSError *callbackError;
  346. __block BOOL callbackInvoked;
  347. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  348. callbackInvoked = YES;
  349. callbackError = error;
  350. }];
  351. // There is no need to call [_RPCIssuer respondWithError:...] in this test because a request
  352. // should never have been tried - and we we know that's the case when we test @c callbackInvoked.
  353. XCTAssert(callbackInvoked);
  354. XCTAssertNotNil(callbackError);
  355. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  356. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  357. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  358. XCTAssertNotNil(underlyingError);
  359. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  360. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeJSONSerializationError);
  361. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  362. XCTAssertNil(underlyingUnderlyingError);
  363. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  364. XCTAssertNil(deserializedResponse);
  365. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  366. XCTAssertNil(dataResponse);
  367. }
  368. /** @fn testNetworkError
  369. @brief This test checks to make sure a network error is properly wrapped and forwarded with the
  370. correct code (FIRAuthErrorCodeNetworkError).
  371. */
  372. - (void)testNetworkError {
  373. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  374. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  375. __block NSError *callbackError;
  376. __block BOOL callbackInvoked;
  377. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  378. callbackInvoked = YES;
  379. callbackError = error;
  380. }];
  381. // It shouldn't matter what the error domain/code/userInfo are, any junk values are suitable. The
  382. // implementation should treat any error with no response data as a network error.
  383. NSError *responseError = [NSError errorWithDomain:kFakeErrorDomain
  384. code:kFakeErrorCode
  385. userInfo:nil];
  386. [_RPCIssuer respondWithError:responseError];
  387. XCTAssert(callbackInvoked);
  388. XCTAssertNotNil(callbackError);
  389. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  390. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeNetworkError);
  391. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  392. XCTAssertNotNil(underlyingError);
  393. XCTAssertEqualObjects(underlyingError.domain, kFakeErrorDomain);
  394. XCTAssertEqual(underlyingError.code, kFakeErrorCode);
  395. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  396. XCTAssertNil(underlyingUnderlyingError);
  397. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  398. XCTAssertNil(deserializedResponse);
  399. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  400. XCTAssertNil(dataResponse);
  401. }
  402. /** @fn testUnparsableErrorResponse
  403. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  404. response isn't deserializable by @c NSJSONSerialization and an error
  405. condition (with an associated error response message) was expected. We are expecting to
  406. receive the original network error wrapped in an @c NSError with the code
  407. @c FIRAuthErrorCodeUnexpectedHTTPResponse.
  408. */
  409. - (void)testUnparsableErrorResponse {
  410. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  411. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  412. __block NSError *callbackError;
  413. __block BOOL callbackInvoked;
  414. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  415. callbackInvoked = YES;
  416. callbackError = error;
  417. }];
  418. NSData *data =
  419. [@"<html><body>An error occurred.</body></html>" dataUsingEncoding:NSUTF8StringEncoding];
  420. NSError *error =
  421. [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{ }];
  422. [_RPCIssuer respondWithData:data error:error];
  423. XCTAssert(callbackInvoked);
  424. XCTAssertNotNil(callbackError);
  425. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  426. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  427. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  428. XCTAssertNotNil(underlyingError);
  429. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  430. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  431. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  432. XCTAssertNotNil(underlyingUnderlyingError);
  433. XCTAssertEqualObjects(underlyingUnderlyingError.domain, kFakeErrorDomain);
  434. XCTAssertEqual(underlyingUnderlyingError.code, kFakeErrorCode);
  435. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  436. XCTAssertNil(deserializedResponse);
  437. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  438. XCTAssertNotNil(dataResponse);
  439. XCTAssertEqualObjects(dataResponse, data);
  440. }
  441. /** @fn testUnparsableSuccessResponse
  442. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  443. response isn't deserializable by @c NSJSONSerialization and no error
  444. condition was indicated. We are expecting to
  445. receive the @c NSJSONSerialization error wrapped in an @c NSError with the code
  446. @c FIRAuthErrorCodeUnexpectedServerResponse.
  447. */
  448. - (void)testUnparsableSuccessResponse {
  449. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  450. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  451. __block NSError *callbackError;
  452. __block BOOL callbackInvoked;
  453. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  454. callbackInvoked = YES;
  455. callbackError = error;
  456. }];
  457. NSData *data =
  458. [@"<xml>Some non-JSON value.</xml>" dataUsingEncoding:NSUTF8StringEncoding];
  459. [_RPCIssuer respondWithData:data error:nil];
  460. XCTAssert(callbackInvoked);
  461. XCTAssertNotNil(callbackError);
  462. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  463. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  464. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  465. XCTAssertNotNil(underlyingError);
  466. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  467. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedResponse);
  468. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  469. XCTAssertNotNil(underlyingUnderlyingError);
  470. XCTAssertEqualObjects(underlyingUnderlyingError.domain, NSCocoaErrorDomain);
  471. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  472. XCTAssertNil(deserializedResponse);
  473. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  474. XCTAssertNotNil(dataResponse);
  475. XCTAssertEqualObjects(dataResponse, data);
  476. }
  477. /** @fn testNonDictionaryErrorResponse
  478. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  479. response deserialized by @c NSJSONSerialization is not a dictionary, and an error was
  480. expected. We are expecting to receive an @c NSError with the code
  481. @c FIRAuthErrorCodeUnexpectedErrorServerResponse with the decoded response in the
  482. @c NSError.userInfo dictionary associated with the key
  483. @c FIRAuthErrorUserInfoDecodedResponseKey.
  484. */
  485. - (void)testNonDictionaryErrorResponse {
  486. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  487. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  488. __block NSError *callbackError;
  489. __block BOOL callbackInvoked;
  490. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  491. callbackInvoked = YES;
  492. callbackError = error;
  493. }];
  494. // We are responding with a JSON-encoded string value representing an array - which is unexpected.
  495. // It should normally be a dictionary, and we need to check for this sort of thing. Because we can
  496. // successfully decode this value, however, we do return it in the error results. We check for
  497. // this array later in the test.
  498. NSData *data = [@"[]" dataUsingEncoding:NSUTF8StringEncoding];
  499. NSError *error =
  500. [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{ }];
  501. [_RPCIssuer respondWithData:data error:error];
  502. XCTAssert(callbackInvoked);
  503. XCTAssertNotNil(callbackError);
  504. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  505. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  506. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  507. XCTAssertNotNil(underlyingError);
  508. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  509. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  510. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  511. XCTAssertNil(underlyingUnderlyingError);
  512. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  513. XCTAssertNotNil(deserializedResponse);
  514. XCTAssert([deserializedResponse isKindOfClass:[NSArray class]]);
  515. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  516. XCTAssertNil(dataResponse);
  517. }
  518. /** @fn testNonDictionarySuccessResponse
  519. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  520. response deserialized by @c NSJSONSerialization is not a dictionary, and no error was
  521. expected. We are expecting to receive an @c NSError with the code
  522. @c FIRAuthErrorCodeUnexpectedServerResponse with the decoded response in the
  523. @c NSError.userInfo dictionary associated with the key
  524. @c FIRAuthErrorUserInfoDecodedResponseKey.
  525. */
  526. - (void)testNonDictionarySuccessResponse {
  527. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  528. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  529. __block NSError *callbackError;
  530. __block BOOL callbackInvoked;
  531. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  532. callbackInvoked = YES;
  533. callbackError = error;
  534. }];
  535. // We are responding with a JSON-encoded string value representing an array - which is unexpected.
  536. // It should normally be a dictionary, and we need to check for this sort of thing. Because we can
  537. // successfully decode this value, however, we do return it in the error results. We check for
  538. // this array later in the test.
  539. NSData *data = [@"[]" dataUsingEncoding:NSUTF8StringEncoding];
  540. [_RPCIssuer respondWithData:data error:nil];
  541. XCTAssert(callbackInvoked);
  542. XCTAssertNotNil(callbackError);
  543. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  544. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  545. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  546. XCTAssertNotNil(underlyingError);
  547. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  548. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedResponse);
  549. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  550. XCTAssertNil(underlyingUnderlyingError);
  551. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  552. XCTAssertNotNil(deserializedResponse);
  553. XCTAssert([deserializedResponse isKindOfClass:[NSArray class]]);
  554. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  555. XCTAssertNil(dataResponse);
  556. }
  557. /** @fn testCaptchaRequiredResponse
  558. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  559. we get an error message indicating captcha is required. The backend should not be returning
  560. this error to mobile clients. If it does, we should wrap it in an @c NSError with the code
  561. @c FIRAuthErrorCodeUnexpectedServerResponse with the decoded error message in the
  562. @c NSError.userInfo dictionary associated with the key
  563. @c FIRAuthErrorUserInfoDecodedErrorResponseKey.
  564. */
  565. - (void)testCaptchaRequiredResponse {
  566. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  567. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  568. __block NSError *callbackError;
  569. __block BOOL callbackInvoked;
  570. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  571. callbackInvoked = YES;
  572. callbackError = error;
  573. }];
  574. NSError *error =
  575. [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{ }];
  576. [_RPCIssuer respondWithServerErrorMessage:kErrorMessageCaptchaRequired error:error];
  577. XCTAssert(callbackInvoked);
  578. XCTAssertNotNil(callbackError);
  579. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  580. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  581. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  582. XCTAssertNotNil(underlyingError);
  583. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  584. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  585. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  586. XCTAssertNil(underlyingUnderlyingError);
  587. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  588. XCTAssertNotNil(deserializedResponse);
  589. XCTAssert([deserializedResponse isKindOfClass:[NSDictionary class]]);
  590. XCTAssertNotNil(deserializedResponse[@"message"]);
  591. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  592. XCTAssertNil(dataResponse);
  593. }
  594. /** @fn testCaptchaCheckFailedResponse
  595. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  596. we get an error message indicating captcha check failed. The backend should not be returning
  597. this error to mobile clients. If it does, we should wrap it in an @c NSError with the code
  598. @c FIRAuthErrorCodeUnexpectedServerResponse with the decoded error message in the
  599. @c NSError.userInfo dictionary associated with the key
  600. @c FIRAuthErrorUserInfoDecodedErrorResponseKey.
  601. */
  602. - (void)testCaptchaCheckFailedResponse {
  603. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  604. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  605. __block NSError *callbackError;
  606. __block BOOL callbackInvoked;
  607. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  608. callbackInvoked = YES;
  609. callbackError = error;
  610. }];
  611. NSError *error =
  612. [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 response:response callback:^(NSError *error) {
  634. callbackInvoked = YES;
  635. callbackError = error;
  636. }];
  637. NSError *error =
  638. [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{ }];
  639. [_RPCIssuer respondWithServerErrorMessage:kErrorMessageCaptchaRequiredInvalidPassword
  640. error:error];
  641. XCTAssert(callbackInvoked);
  642. XCTAssertNotNil(callbackError);
  643. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  644. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  645. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  646. XCTAssertNotNil(underlyingError);
  647. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  648. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  649. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  650. XCTAssertNil(underlyingUnderlyingError);
  651. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  652. XCTAssertNotNil(deserializedResponse);
  653. XCTAssert([deserializedResponse isKindOfClass:[NSDictionary class]]);
  654. XCTAssertNotNil(deserializedResponse[@"message"]);
  655. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  656. XCTAssertNil(dataResponse);
  657. }
  658. /** @fn testDecodableErrorResponseWithUnknownMessage
  659. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  660. response deserialized by @c NSJSONSerialization represents a valid error response (and an
  661. error was indicated) but we didn't receive an error message we know about. We are expecting
  662. an @c NSError with the code @c FIRAuthErrorCodeUnexpectedServerResponse with the decoded
  663. error message in the @c NSError.userInfo dictionary associated with the key
  664. @c FIRAuthErrorUserInfoDecodedErrorResponseKey.
  665. */
  666. - (void)testDecodableErrorResponseWithUnknownMessage {
  667. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  668. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  669. __block NSError *callbackError;
  670. __block BOOL callbackInvoked;
  671. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  672. callbackInvoked = YES;
  673. callbackError = error;
  674. }];
  675. // We need to return a valid "error" response here, but we are going to intentionally use a bogus
  676. // error message.
  677. NSError *error =
  678. [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{ }];
  679. [_RPCIssuer respondWithServerErrorMessage:kUnknownServerErrorMessage error:error];
  680. XCTAssert(callbackInvoked);
  681. XCTAssertNotNil(callbackError);
  682. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  683. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  684. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  685. XCTAssertNotNil(underlyingError);
  686. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  687. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  688. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  689. XCTAssertNil(underlyingUnderlyingError);
  690. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  691. XCTAssertNotNil(deserializedResponse);
  692. XCTAssert([deserializedResponse isKindOfClass:[NSDictionary class]]);
  693. XCTAssertNotNil(deserializedResponse[@"message"]);
  694. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  695. XCTAssertNil(dataResponse);
  696. }
  697. /** @fn testErrorResponseWithNoErrorMessage
  698. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  699. response deserialized by @c NSJSONSerialization is a dictionary, and an error was indicated,
  700. but no error information was present in the decoded response. We are expecting an @c NSError
  701. with the code @c FIRAuthErrorCodeUnexpectedServerResponse with the decoded
  702. response message in the @c NSError.userInfo dictionary associated with the key
  703. @c FIRAuthErrorUserInfoDecodedResponseKey.
  704. */
  705. - (void)testErrorResponseWithNoErrorMessage {
  706. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  707. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  708. __block NSError *callbackError;
  709. __block BOOL callbackInvoked;
  710. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  711. callbackInvoked = YES;
  712. callbackError = error;
  713. }];
  714. NSError *error =
  715. [NSError errorWithDomain:kFakeErrorDomain code:kFakeErrorCode userInfo:@{ }];
  716. [_RPCIssuer respondWithJSON:@{ } error:error];
  717. XCTAssert(callbackInvoked);
  718. XCTAssertNotNil(callbackError);
  719. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  720. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  721. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  722. XCTAssertNotNil(underlyingError);
  723. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  724. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeUnexpectedErrorResponse);
  725. NSError *underlyingUnderlyingError = underlyingError.userInfo[NSUnderlyingErrorKey];
  726. XCTAssertNil(underlyingUnderlyingError);
  727. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  728. XCTAssertNotNil(deserializedResponse);
  729. XCTAssert([deserializedResponse isKindOfClass:[NSDictionary class]]);
  730. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  731. XCTAssertNil(dataResponse);
  732. }
  733. /** @fn testClientErrorResponse
  734. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  735. response contains a client error specified by an error messsage sent from the backend.
  736. */
  737. - (void)testClientErrorResponse {
  738. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  739. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  740. __block NSError *callbackerror;
  741. __block BOOL callBackInvoked;
  742. [_RPCImplementation postWithRequest: request response:response callback:^(NSError *error) {
  743. callBackInvoked = YES;
  744. callbackerror = error;
  745. }];
  746. NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil];
  747. NSString *customErrorMessage =[NSString stringWithFormat:@"%@%@%@",
  748. kUserDisabledErrorMessage,
  749. kServerErrorDetailMarker,
  750. kFakeUserDisabledCustomErrorMessage];
  751. [_RPCIssuer respondWithServerErrorMessage:customErrorMessage error:error];
  752. XCTAssertNotNil(callbackerror, @"An error should be returned from callback.");
  753. XCTAssert(callBackInvoked);
  754. XCTAssertEqual(callbackerror.code, FIRAuthErrorCodeUserDisabled);
  755. NSString *customMessage = callbackerror.userInfo[NSLocalizedDescriptionKey];
  756. XCTAssertEqualObjects(customMessage, kFakeUserDisabledCustomErrorMessage);
  757. }
  758. /** @fn testUndecodableSuccessResponse
  759. @brief This test checks the behaviour of @c postWithRequest:response:callback: when the
  760. response isn't decodable by the response class but no error condition was expected. We are
  761. expecting to receive an @c NSError with the code
  762. @c FIRAuthErrorCodeUnexpectedServerResponse and the error from @c setWithDictionary:error:
  763. as the value of the underlyingError.
  764. */
  765. - (void)testUndecodableSuccessResponse {
  766. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  767. FIRFakeResponse *response = [FIRFakeResponse fakeResponseWithDecodingError];
  768. __block NSError *callbackError;
  769. __block BOOL callbackInvoked;
  770. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  771. callbackInvoked = YES;
  772. callbackError = error;
  773. }];
  774. // It doesn't matter what we respond with here, as long as it's not an error response. The fake
  775. // response will deterministicly simulate a decoding error regardless of the response value it was
  776. // given.
  777. [_RPCIssuer respondWithJSON:@{ }];
  778. XCTAssert(callbackInvoked);
  779. XCTAssertNotNil(callbackError);
  780. XCTAssertEqualObjects(callbackError.domain, FIRAuthErrorDomain);
  781. XCTAssertEqual(callbackError.code, FIRAuthErrorCodeInternalError);
  782. NSError *underlyingError = callbackError.userInfo[NSUnderlyingErrorKey];
  783. XCTAssertNotNil(underlyingError);
  784. XCTAssertEqualObjects(underlyingError.domain, FIRAuthInternalErrorDomain);
  785. XCTAssertEqual(underlyingError.code, FIRAuthInternalErrorCodeRPCResponseDecodingError);
  786. id deserializedResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDeserializedResponseKey];
  787. XCTAssertNotNil(deserializedResponse);
  788. XCTAssert([deserializedResponse isKindOfClass:[NSDictionary class]]);
  789. id dataResponse = underlyingError.userInfo[FIRAuthErrorUserInfoDataKey];
  790. XCTAssertNil(dataResponse);
  791. }
  792. /** @fn testSuccessfulResponse
  793. @brief Tests that a decoded dictionary is handed to the response instance.
  794. */
  795. - (void)testSuccessfulResponse {
  796. FIRFakeRequest *request = [FIRFakeRequest fakeRequest];
  797. FIRFakeResponse *response = [FIRFakeResponse fakeResponse];
  798. __block NSError *callbackError;
  799. __block BOOL callbackInvoked;
  800. [_RPCImplementation postWithRequest:request response:response callback:^(NSError *error) {
  801. callbackInvoked = YES;
  802. callbackError = error;
  803. }];
  804. [_RPCIssuer respondWithJSON:@{ kTestKey : kTestValue }];
  805. XCTAssert(callbackInvoked);
  806. XCTAssertNil(callbackError);
  807. XCTAssertNotNil(response.receivedDictionary);
  808. XCTAssertEqualObjects(response.receivedDictionary[kTestKey], kTestValue);
  809. }
  810. @end