FIRSetAccountInfoResponseTests.m 20 KB

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