FIRSetAccountInfoResponseTests.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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/Public/FirebaseAuth/FIRAuthErrors.h"
  18. #import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
  19. #import "FirebaseAuth/Sources/Backend/RPC/FIRSetAccountInfoRequest.h"
  20. #import "FirebaseAuth/Sources/Backend/RPC/FIRSetAccountInfoResponse.h"
  21. #import "FirebaseAuth/Tests/Unit/FIRFakeBackendRPCIssuer.h"
  22. /** @var kTestAPIKey
  23. @brief Fake API key used for testing.
  24. */
  25. static NSString *const kTestAPIKey = @"APIKey";
  26. /** @var kTestFirebaseAppID
  27. @brief Fake Firebase app ID used for testing.
  28. */
  29. static NSString *const kTestFirebaseAppID = @"appID";
  30. /** @var kEmailExistsErrorMessage
  31. @brief This is the error message the server will respond with if the user entered an invalid
  32. email address.
  33. */
  34. static NSString *const kEmailExistsErrorMessage = @"EMAIL_EXISTS";
  35. /** @var kVerifiedProviderKey
  36. @brief The name of the "VerifiedProvider" property in the response.
  37. */
  38. static NSString *const kProviderUserInfoKey = @"providerUserInfo";
  39. /** @var kPhotoUrlKey
  40. @brief The name of the "photoURL" property in the response.
  41. */
  42. static NSString *const kPhotoUrlKey = @"photoUrl";
  43. /** @var kTestPhotoURL
  44. @brief The fake photoUrl property value in the response.
  45. */
  46. static NSString *const kTestPhotoURL = @"testPhotoURL";
  47. /** @var kIDTokenKey
  48. @brief The name of the "IDToken" property in the response.
  49. */
  50. static NSString *const kIDTokenKey = @"idToken";
  51. /** @var kTestIDToken
  52. @brief Testing ID token for verifying assertion.
  53. */
  54. static NSString *const kTestIDToken = @"ID_TOKEN";
  55. /** @var kExpiresInKey
  56. @brief The name of the "expiresIn" property in the response.
  57. */
  58. static NSString *const kExpiresInKey = @"expiresIn";
  59. /** @var kTestExpiresIn
  60. @brief Fake token expiration time.
  61. */
  62. static NSString *const kTestExpiresIn = @"12345";
  63. /** @var kRefreshTokenKey
  64. @brief The name of the "refreshToken" property in the response.
  65. */
  66. static NSString *const kRefreshTokenKey = @"refreshToken";
  67. /** @var kTestRefreshToken
  68. @brief Fake refresh token.
  69. */
  70. static NSString *const kTestRefreshToken = @"REFRESH_TOKEN";
  71. /** @var kEmailSignUpNotAllowedErrorMessage
  72. @brief This is the error message the server will respond with if admin disables password
  73. account.
  74. */
  75. static NSString *const kEmailSignUpNotAllowedErrorMessage = @"OPERATION_NOT_ALLOWED";
  76. /** @var kPasswordLoginDisabledErrorMessage
  77. @brief This is the error message the server responds with if password login is disabled.
  78. */
  79. static NSString *const kPasswordLoginDisabledErrorMessage = @"PASSWORD_LOGIN_DISABLED";
  80. /** @var kCredentialTooOldErrorMessage
  81. @brief This is the error message the server responds with if account change is attempted 5
  82. minutes after signing in.
  83. */
  84. static NSString *const kCredentialTooOldErrorMessage = @"CREDENTIAL_TOO_OLD_LOGIN_AGAIN";
  85. /** @var kinvalidUserTokenErrorMessage
  86. @brief This is the error message the server will respond with if the user's saved auth
  87. credential is invalid, the user has to sign-in again.
  88. */
  89. static NSString *const kinvalidUserTokenErrorMessage = @"INVALID_ID_TOKEN";
  90. /** @var kUserDisabledErrorMessage
  91. @brief This is the error message the server will respond with if the user's account has been
  92. disabled.
  93. */
  94. static NSString *const kUserDisabledErrorMessage = @"USER_DISABLED";
  95. /** @var kInvalidEmailErrorMessage
  96. @brief The error returned by the server if the email is invalid.
  97. */
  98. static NSString *const kInvalidEmailErrorMessage = @"INVALID_EMAIL";
  99. /** @var kWeakPasswordErrorMessage
  100. @brief This is the error message the server will respond with if the user's new password
  101. is too weak that it is too short.
  102. */
  103. static NSString *const kWeakPasswordErrorMessage =
  104. @"WEAK_PASSWORD : Password should be at least 6 characters";
  105. /** @var kWeakPasswordClientErrorMessage
  106. @brief This is the error message the client will see if the user's new password is too weak
  107. that it is too short.
  108. @remarks This message should be derived from @c kWeakPasswordErrorMessage .
  109. */
  110. static NSString *const kWeakPasswordClientErrorMessage =
  111. @"Password should be at least 6 characters";
  112. /** @var kExpiredActionCodeErrorMessage
  113. @brief This is the error message the server will respond with if the action code is expired.
  114. */
  115. static NSString *const kExpiredActionCodeErrorMessage = @"EXPIRED_OOB_CODE:";
  116. /** @var kInvalidActionCodeErrorMessage
  117. @brief This is the error message the server will respond with if the action code is invalid.
  118. */
  119. static NSString *const kInvalidActionCodeErrorMessage = @"INVALID_OOB_CODE";
  120. /** @var kInvalidMessagePayloadErrorMessage
  121. @brief This is the prefix for the error message the server responds with if an invalid message
  122. payload was sent.
  123. */
  124. static NSString *const kInvalidMessagePayloadErrorMessage = @"INVALID_MESSAGE_PAYLOAD";
  125. /** @var kInvalidSenderErrorMessage
  126. @brief This is the prefix for the error message the server responds with if invalid sender is
  127. used to send the email for updating user's email address.
  128. */
  129. static NSString *const kInvalidSenderErrorMessage = @"INVALID_SENDER";
  130. /** @var kInvalidRecipientEmailErrorMessage
  131. @brief This is the prefix for the error message the server responds with if the recipient email
  132. is invalid.
  133. */
  134. static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_EMAIL";
  135. /** @var kAllowedTimeDifference
  136. @brief Allowed difference when comparing times because of execution time and floating point
  137. error.
  138. */
  139. static const double kAllowedTimeDifference = 0.1;
  140. /** @class FIRSetAccountInfoResponseTests
  141. @brief Tests for @c FIRSetAccountInfoResponse.
  142. */
  143. @interface FIRSetAccountInfoResponseTests : XCTestCase
  144. @end
  145. @implementation FIRSetAccountInfoResponseTests {
  146. /** @var _RPCIssuer
  147. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  148. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  149. */
  150. FIRFakeBackendRPCIssuer *_RPCIssuer;
  151. /** @var _requestConfiguration
  152. @brief This is the request configuration used for testing.
  153. */
  154. FIRAuthRequestConfiguration *_requestConfiguration;
  155. }
  156. - (void)setUp {
  157. [super setUp];
  158. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  159. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  160. _RPCIssuer = RPCIssuer;
  161. _requestConfiguration = [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey
  162. appID:kTestFirebaseAppID];
  163. }
  164. - (void)tearDown {
  165. _RPCIssuer = nil;
  166. _requestConfiguration = nil;
  167. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  168. [super tearDown];
  169. }
  170. /** @fn testEmailExistsError
  171. @brief This test simulates @c testSignUpNewUserEmailExistsError with @c
  172. FIRAuthErrorCodeEmailExists error.
  173. */
  174. - (void)testEmailExistsError {
  175. FIRSetAccountInfoRequest *request =
  176. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  177. __block BOOL callbackInvoked;
  178. __block FIRSetAccountInfoResponse *RPCResponse;
  179. __block NSError *RPCError;
  180. [FIRAuthBackend
  181. setAccountInfo:request
  182. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  183. callbackInvoked = YES;
  184. RPCResponse = response;
  185. RPCError = error;
  186. }];
  187. [_RPCIssuer respondWithServerErrorMessage:kEmailExistsErrorMessage];
  188. XCTAssert(callbackInvoked);
  189. XCTAssertNil(RPCResponse);
  190. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeEmailAlreadyInUse);
  191. }
  192. /** @fn testEmailSignUpNotAllowedError
  193. @brief This test simulates @c testEmailSignUpNotAllowedError with @c
  194. FIRAuthErrorCodeOperationNotAllowed error.
  195. */
  196. - (void)testEmailSignUpNotAllowedError {
  197. FIRSetAccountInfoRequest *request =
  198. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  199. __block BOOL callbackInvoked;
  200. __block FIRSetAccountInfoResponse *RPCResponse;
  201. __block NSError *RPCError;
  202. [FIRAuthBackend
  203. setAccountInfo:request
  204. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  205. callbackInvoked = YES;
  206. RPCResponse = response;
  207. RPCError = error;
  208. }];
  209. [_RPCIssuer respondWithServerErrorMessage:kEmailSignUpNotAllowedErrorMessage];
  210. XCTAssert(callbackInvoked);
  211. XCTAssertNil(RPCResponse);
  212. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeOperationNotAllowed);
  213. }
  214. /** @fn testPasswordLoginDisabledError
  215. @brief This test simulates @c passwordLoginDisabledError with @c
  216. FIRAuthErrorCodeOperationNotAllowed error.
  217. */
  218. - (void)testPasswordLoginDisabledError {
  219. FIRSetAccountInfoRequest *request =
  220. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  221. __block BOOL callbackInvoked;
  222. __block FIRSetAccountInfoResponse *RPCResponse;
  223. __block NSError *RPCError;
  224. [FIRAuthBackend
  225. setAccountInfo:request
  226. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  227. callbackInvoked = YES;
  228. RPCResponse = response;
  229. RPCError = error;
  230. }];
  231. [_RPCIssuer respondWithServerErrorMessage:kPasswordLoginDisabledErrorMessage];
  232. XCTAssert(callbackInvoked);
  233. XCTAssertNil(RPCResponse);
  234. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeOperationNotAllowed);
  235. }
  236. /** @fn testUserDisabledError
  237. @brief This test simulates @c testUserDisabledError with @c FIRAuthErrorCodeUserDisabled error.
  238. */
  239. - (void)testUserDisabledError {
  240. FIRSetAccountInfoRequest *request =
  241. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  242. __block BOOL callbackInvoked;
  243. __block FIRSetAccountInfoResponse *RPCResponse;
  244. __block NSError *RPCError;
  245. [FIRAuthBackend
  246. setAccountInfo:request
  247. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  248. callbackInvoked = YES;
  249. RPCResponse = response;
  250. RPCError = error;
  251. }];
  252. [_RPCIssuer respondWithServerErrorMessage:kUserDisabledErrorMessage];
  253. XCTAssert(callbackInvoked);
  254. XCTAssertNil(RPCResponse);
  255. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeUserDisabled);
  256. }
  257. /** @fn testInvalidUserTokenError
  258. @brief This test simulates @c testinvalidUserTokenError with @c
  259. FIRAuthErrorCodeCredentialTooOld error.
  260. */
  261. - (void)testInvalidUserTokenError {
  262. FIRSetAccountInfoRequest *request =
  263. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  264. __block BOOL callbackInvoked;
  265. __block FIRSetAccountInfoResponse *RPCResponse;
  266. __block NSError *RPCError;
  267. [FIRAuthBackend
  268. setAccountInfo:request
  269. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  270. callbackInvoked = YES;
  271. RPCResponse = response;
  272. RPCError = error;
  273. }];
  274. [_RPCIssuer respondWithServerErrorMessage:kinvalidUserTokenErrorMessage];
  275. XCTAssert(callbackInvoked);
  276. XCTAssertNil(RPCResponse);
  277. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidUserToken);
  278. }
  279. /** @fn testrequiresRecentLogin
  280. @brief This test simulates @c testCredentialTooOldError with @c
  281. FIRAuthErrorCodeRequiresRecentLogin error.
  282. */
  283. - (void)testrequiresRecentLogin {
  284. FIRSetAccountInfoRequest *request =
  285. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  286. __block BOOL callbackInvoked;
  287. __block FIRSetAccountInfoResponse *RPCResponse;
  288. __block NSError *RPCError;
  289. [FIRAuthBackend
  290. setAccountInfo:request
  291. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  292. callbackInvoked = YES;
  293. RPCResponse = response;
  294. RPCError = error;
  295. }];
  296. [_RPCIssuer respondWithServerErrorMessage:kCredentialTooOldErrorMessage];
  297. XCTAssert(callbackInvoked);
  298. XCTAssertNil(RPCResponse);
  299. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeRequiresRecentLogin);
  300. }
  301. /** @fn testWeakPasswordError
  302. @brief This test simulates @c FIRAuthErrorCodeWeakPassword error.
  303. */
  304. - (void)testWeakPasswordError {
  305. FIRSetAccountInfoRequest *request =
  306. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  307. __block BOOL callbackInvoked;
  308. __block FIRSetAccountInfoResponse *RPCResponse;
  309. __block NSError *RPCError;
  310. [FIRAuthBackend
  311. setAccountInfo:request
  312. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  313. callbackInvoked = YES;
  314. RPCResponse = response;
  315. RPCError = error;
  316. }];
  317. [_RPCIssuer respondWithServerErrorMessage:kWeakPasswordErrorMessage];
  318. XCTAssert(callbackInvoked);
  319. XCTAssertNil(RPCResponse);
  320. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeWeakPassword);
  321. XCTAssertEqualObjects(RPCError.userInfo[NSLocalizedFailureReasonErrorKey],
  322. kWeakPasswordClientErrorMessage);
  323. }
  324. /** @fn testInvalidEmailError
  325. @brief This test simulates @c FIRAuthErrorCodeInvalidEmail error code.
  326. */
  327. - (void)testInvalidEmailError {
  328. FIRSetAccountInfoRequest *request =
  329. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  330. __block BOOL callbackInvoked;
  331. __block FIRSetAccountInfoResponse *RPCResponse;
  332. __block NSError *RPCError;
  333. [FIRAuthBackend
  334. setAccountInfo:request
  335. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  336. callbackInvoked = YES;
  337. RPCResponse = response;
  338. RPCError = error;
  339. }];
  340. [_RPCIssuer respondWithServerErrorMessage:kInvalidEmailErrorMessage];
  341. XCTAssert(callbackInvoked);
  342. XCTAssertNil(RPCResponse);
  343. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidEmail);
  344. }
  345. /** @fn testInvalidActionCodeError
  346. @brief This test simulates @c FIRAuthErrorCodeInvalidActionCode error code.
  347. */
  348. - (void)testInvalidActionCodeError {
  349. FIRSetAccountInfoRequest *request =
  350. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  351. __block BOOL callbackInvoked;
  352. __block FIRSetAccountInfoResponse *RPCResponse;
  353. __block NSError *RPCError;
  354. [FIRAuthBackend
  355. setAccountInfo:request
  356. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  357. callbackInvoked = YES;
  358. RPCResponse = response;
  359. RPCError = error;
  360. }];
  361. [_RPCIssuer respondWithServerErrorMessage:kInvalidActionCodeErrorMessage];
  362. XCTAssert(callbackInvoked);
  363. XCTAssertNil(RPCResponse);
  364. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidActionCode);
  365. }
  366. /** @fn testExpiredActionCodeError
  367. @brief This test simulates @c FIRAuthErrorCodeExpiredActionCode error code.
  368. */
  369. - (void)testExpiredActionCodeError {
  370. FIRSetAccountInfoRequest *request =
  371. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  372. __block BOOL callbackInvoked;
  373. __block FIRSetAccountInfoResponse *RPCResponse;
  374. __block NSError *RPCError;
  375. [FIRAuthBackend
  376. setAccountInfo:request
  377. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  378. callbackInvoked = YES;
  379. RPCResponse = response;
  380. RPCError = error;
  381. }];
  382. [_RPCIssuer respondWithServerErrorMessage:kExpiredActionCodeErrorMessage];
  383. XCTAssert(callbackInvoked);
  384. XCTAssertNil(RPCResponse);
  385. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeExpiredActionCode);
  386. }
  387. /** @fn testInvalidMessagePayloadError
  388. @brief Tests for @c FIRAuthErrorCodeInvalidMessagePayload.
  389. */
  390. - (void)testInvalidMessagePayloadError {
  391. FIRSetAccountInfoRequest *request =
  392. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  393. __block BOOL callbackInvoked;
  394. __block FIRSetAccountInfoResponse *RPCResponse;
  395. __block NSError *RPCError;
  396. [FIRAuthBackend
  397. setAccountInfo:request
  398. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  399. RPCResponse = response;
  400. RPCError = error;
  401. callbackInvoked = YES;
  402. }];
  403. [_RPCIssuer respondWithServerErrorMessage:kInvalidMessagePayloadErrorMessage];
  404. XCTAssert(callbackInvoked);
  405. XCTAssertNil(RPCResponse);
  406. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidMessagePayload);
  407. }
  408. /** @fn testInvalidSenderError
  409. @brief Tests for @c FIRAuthErrorCodeInvalidSender.
  410. */
  411. - (void)testInvalidSenderError {
  412. FIRSetAccountInfoRequest *request =
  413. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  414. __block BOOL callbackInvoked;
  415. __block FIRSetAccountInfoResponse *RPCResponse;
  416. __block NSError *RPCError;
  417. [FIRAuthBackend
  418. setAccountInfo:request
  419. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  420. RPCResponse = response;
  421. RPCError = error;
  422. callbackInvoked = YES;
  423. }];
  424. [_RPCIssuer respondWithServerErrorMessage:kInvalidSenderErrorMessage];
  425. XCTAssert(callbackInvoked);
  426. XCTAssertNil(RPCResponse);
  427. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidSender);
  428. }
  429. /** @fn testInvalidRecipientEmailError
  430. @brief Tests for @c FIRAuthErrorCodeInvalidRecipientEmail.
  431. */
  432. - (void)testInvalidRecipientEmailError {
  433. FIRSetAccountInfoRequest *request =
  434. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  435. __block BOOL callbackInvoked;
  436. __block FIRSetAccountInfoResponse *RPCResponse;
  437. __block NSError *RPCError;
  438. [FIRAuthBackend
  439. setAccountInfo:request
  440. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  441. RPCResponse = response;
  442. RPCError = error;
  443. callbackInvoked = YES;
  444. }];
  445. [_RPCIssuer respondWithServerErrorMessage:kInvalidRecipientEmailErrorMessage];
  446. XCTAssert(callbackInvoked);
  447. XCTAssertNil(RPCResponse);
  448. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidRecipientEmail);
  449. }
  450. /** @fn testSuccessfulSetAccountInfoResponse
  451. @brief This test simulates a successful @c SetAccountInfo flow.
  452. */
  453. - (void)testSuccessfulSetAccountInfoResponse {
  454. FIRSetAccountInfoRequest *request =
  455. [[FIRSetAccountInfoRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  456. __block BOOL callbackInvoked;
  457. __block FIRSetAccountInfoResponse *RPCResponse;
  458. __block NSError *RPCError;
  459. [FIRAuthBackend
  460. setAccountInfo:request
  461. callback:^(FIRSetAccountInfoResponse *_Nullable response, NSError *_Nullable error) {
  462. callbackInvoked = YES;
  463. RPCResponse = response;
  464. RPCError = error;
  465. }];
  466. [_RPCIssuer respondWithJSON:@{
  467. kProviderUserInfoKey : @[ @{kPhotoUrlKey : kTestPhotoURL} ],
  468. kIDTokenKey : kTestIDToken,
  469. kExpiresInKey : kTestExpiresIn,
  470. kRefreshTokenKey : kTestRefreshToken
  471. }];
  472. XCTAssert(callbackInvoked);
  473. XCTAssertNil(RPCError);
  474. XCTAssertNotNil(RPCResponse);
  475. if ([RPCResponse.providerUserInfo count]) {
  476. NSURL *responsePhotoUrl = RPCResponse.providerUserInfo[0].photoURL;
  477. XCTAssertEqualObjects(responsePhotoUrl.absoluteString, kTestPhotoURL);
  478. }
  479. XCTAssertEqualObjects(RPCResponse.IDToken, kTestIDToken);
  480. NSTimeInterval expiresIn = [RPCResponse.approximateExpirationDate timeIntervalSinceNow];
  481. XCTAssertEqualWithAccuracy(expiresIn, [kTestExpiresIn doubleValue], kAllowedTimeDifference);
  482. XCTAssertEqualObjects(RPCResponse.refreshToken, kTestRefreshToken);
  483. }
  484. @end