FIRGetOOBConfirmationCodeResponseTests.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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/FIRActionCodeSettings.h"
  18. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuthErrors.h"
  19. #import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
  20. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetOOBConfirmationCodeRequest.h"
  21. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetOOBConfirmationCodeResponse.h"
  22. #import "FirebaseAuth/Tests/Unit/FIRFakeBackendRPCIssuer.h"
  23. /** @var kTestEmail
  24. @brief Testing user email adadress.
  25. */
  26. static NSString *const kTestEmail = @"test@gmail.com";
  27. /** @var kTestAccessToken
  28. @brief Testing access token.
  29. */
  30. static NSString *const kTestAccessToken = @"ACCESS_TOKEN";
  31. /** @var kTestAPIKey
  32. @brief Fake API key used for testing.
  33. */
  34. static NSString *const kTestAPIKey = @"APIKey";
  35. /** @var kOOBCodeKey
  36. @brief The name of the field in the response JSON for the OOB code.
  37. */
  38. static NSString *const kOOBCodeKey = @"oobCode";
  39. /** @var kTestOOBCode
  40. @brief Fake OOB Code used for testing.
  41. */
  42. static NSString *const kTestOOBCode = @"OOBCode";
  43. /** @var kEmailNotFoundMessage
  44. @brief The value of the "message" field returned for an "email not found" error.
  45. */
  46. static NSString *const kEmailNotFoundMessage = @"EMAIL_NOT_FOUND: fake custom message";
  47. /** @var kMissingEmailErrorMessage
  48. @brief The value of the "message" field returned for a "missing email" error.
  49. */
  50. static NSString *const kMissingEmailErrorMessage = @"MISSING_EMAIL";
  51. /** @var kInvalidEmailErrorMessage
  52. @brief The error returned by the server if the email is invalid.
  53. */
  54. static NSString *const kInvalidEmailErrorMessage = @"INVALID_EMAIL:";
  55. /** @var kInvalidMessagePayloadErrorMessage
  56. @brief This is the prefix for the error message the server responds with if an invalid message
  57. payload was sent.
  58. */
  59. static NSString *const kInvalidMessagePayloadErrorMessage = @"INVALID_MESSAGE_PAYLOAD";
  60. /** @var kInvalidSenderErrorMessage
  61. @brief This is the prefix for the error message the server responds with if invalid sender is
  62. used to send the email for updating user's email address.
  63. */
  64. static NSString *const kInvalidSenderErrorMessage = @"INVALID_SENDER";
  65. /** @var kMissingIosBundleIDErrorMessage
  66. @brief This is the error message the server will respond with if iOS bundle ID is missing but
  67. the iOS App store ID is provided.
  68. */
  69. static NSString *const kMissingIosBundleIDErrorMessage = @"MISSING_IOS_BUNDLE_ID";
  70. /** @var kMissingAndroidPackageNameErrorMessage
  71. @brief This is the error message the server will respond with if Android Package Name is missing
  72. but the flag indicating the app should be installed is set to true.
  73. */
  74. static NSString *const kMissingAndroidPackageNameErrorMessage = @"MISSING_ANDROID_PACKAGE_NAME";
  75. /** @var kUnauthorizedDomainErrorMessage
  76. @brief This is the error message the server will respond with if the domain of the continue URL
  77. specified is not whitelisted in the firebase console.
  78. */
  79. static NSString *const kUnauthorizedDomainErrorMessage = @"UNAUTHORIZED_DOMAIN";
  80. /** @var kInvalidRecipientEmailErrorMessage
  81. @brief This is the prefix for the error message the server responds with if the recipient email
  82. is invalid.
  83. */
  84. static NSString *const kInvalidRecipientEmailErrorMessage = @"INVALID_RECIPIENT_EMAIL";
  85. /** @var kInvalidContinueURIErrorMessage
  86. @brief This is the error returned by the backend if the continue URL provided in the request
  87. is invalid.
  88. */
  89. static NSString *const kInvalidContinueURIErrorMessage = @"INVALID_CONTINUE_URI";
  90. /** @var kMissingContinueURIErrorMessage
  91. @brief This is the error message the server will respond with if there was no continue URI
  92. present in a request that required one.
  93. */
  94. static NSString *const kMissingContinueURIErrorMessage = @"MISSING_CONTINUE_URI";
  95. /** @var kIosBundleID
  96. @brief Fake iOS bundle ID for testing.
  97. */
  98. static NSString *const kIosBundleID = @"testBundleID";
  99. /** @class FIRGetOOBConfirmationCodeResponseTests
  100. @brief Tests for @c FIRGetOOBConfirmationCodeResponse.
  101. */
  102. @interface FIRGetOOBConfirmationCodeResponseTests : XCTestCase
  103. @end
  104. @implementation FIRGetOOBConfirmationCodeResponseTests {
  105. /** @var _RPCIssuer
  106. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  107. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  108. */
  109. FIRFakeBackendRPCIssuer *_RPCIssuer;
  110. /** @var _requestConfiguration
  111. @brief This is the request configuration used for testing.
  112. */
  113. FIRAuthRequestConfiguration *_requestConfiguration;
  114. }
  115. - (void)setUp {
  116. [super setUp];
  117. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  118. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  119. _RPCIssuer = RPCIssuer;
  120. _requestConfiguration = [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey];
  121. }
  122. - (void)tearDown {
  123. _requestConfiguration = nil;
  124. _RPCIssuer = nil;
  125. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  126. [super tearDown];
  127. }
  128. /** @fn testSuccessfulPasswordResetResponse
  129. @brief This test simulates a complete password reset response (with OOB Code) and makes sure
  130. it succeeds, and we get the OOB Code decoded correctly.
  131. */
  132. - (void)testSuccessfulPasswordResetResponse {
  133. FIRGetOOBConfirmationCodeRequest *request =
  134. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  135. actionCodeSettings:[self fakeActionCodeSettings]
  136. requestConfiguration:_requestConfiguration];
  137. __block BOOL callbackInvoked;
  138. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  139. __block NSError *RPCError;
  140. [FIRAuthBackend getOOBConfirmationCode:request
  141. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  142. NSError *_Nullable error) {
  143. callbackInvoked = YES;
  144. RPCResponse = response;
  145. RPCError = error;
  146. }];
  147. [_RPCIssuer respondWithJSON:@{kOOBCodeKey : kTestOOBCode}];
  148. XCTAssert(callbackInvoked);
  149. XCTAssertNil(RPCError);
  150. XCTAssertNotNil(RPCResponse);
  151. XCTAssertEqualObjects(RPCResponse.OOBCode, kTestOOBCode);
  152. }
  153. /** @fn testSuccessfulPasswordResetResponseWithoutOOBCode
  154. @brief This test simulates a password reset request where we don't receive the optional OOBCode
  155. response value. It should still succeed.
  156. */
  157. - (void)testSuccessfulPasswordResetResponseWithoutOOBCode {
  158. FIRGetOOBConfirmationCodeRequest *request =
  159. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  160. actionCodeSettings:[self fakeActionCodeSettings]
  161. requestConfiguration:_requestConfiguration];
  162. __block BOOL callbackInvoked;
  163. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  164. __block NSError *RPCError;
  165. [FIRAuthBackend getOOBConfirmationCode:request
  166. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  167. NSError *_Nullable error) {
  168. callbackInvoked = YES;
  169. RPCResponse = response;
  170. RPCError = error;
  171. }];
  172. [_RPCIssuer respondWithJSON:@{}];
  173. XCTAssert(callbackInvoked);
  174. XCTAssertNil(RPCError);
  175. XCTAssertNotNil(RPCResponse);
  176. XCTAssertNil(RPCResponse.OOBCode);
  177. }
  178. /** @fn testEmailNotFoundError
  179. @brief This test checks for email not found responses, and makes sure they are decoded to the
  180. correct error response.
  181. */
  182. - (void)testEmailNotFoundError {
  183. FIRGetOOBConfirmationCodeRequest *request =
  184. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  185. actionCodeSettings:[self fakeActionCodeSettings]
  186. requestConfiguration:_requestConfiguration];
  187. __block BOOL callbackInvoked;
  188. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  189. __block NSError *RPCError;
  190. [FIRAuthBackend getOOBConfirmationCode:request
  191. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  192. NSError *_Nullable error) {
  193. callbackInvoked = YES;
  194. RPCResponse = response;
  195. RPCError = error;
  196. }];
  197. [_RPCIssuer respondWithServerErrorMessage:kEmailNotFoundMessage];
  198. XCTAssert(callbackInvoked);
  199. XCTAssertNotNil(RPCError);
  200. XCTAssertEqualObjects(RPCError.domain, FIRAuthErrorDomain);
  201. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeUserNotFound);
  202. XCTAssertNil(RPCResponse);
  203. }
  204. /** @fn testMissingEmailError
  205. @brief This test checks for missing email responses, and makes sure they are decoded to the
  206. correct error response.
  207. */
  208. - (void)testMissingEmailError {
  209. FIRGetOOBConfirmationCodeRequest *request = [FIRGetOOBConfirmationCodeRequest
  210. verifyEmailRequestWithAccessToken:kTestAccessToken
  211. actionCodeSettings:[self fakeActionCodeSettings]
  212. requestConfiguration:_requestConfiguration];
  213. __block BOOL callbackInvoked;
  214. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  215. __block NSError *RPCError;
  216. [FIRAuthBackend getOOBConfirmationCode:request
  217. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  218. NSError *_Nullable error) {
  219. callbackInvoked = YES;
  220. RPCResponse = response;
  221. RPCError = error;
  222. }];
  223. [_RPCIssuer respondWithServerErrorMessage:kMissingEmailErrorMessage];
  224. XCTAssert(callbackInvoked);
  225. XCTAssertNotNil(RPCError);
  226. XCTAssertEqualObjects(RPCError.domain, FIRAuthErrorDomain);
  227. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeMissingEmail);
  228. XCTAssertNil(RPCResponse);
  229. }
  230. /** @fn testInvalidEmailError
  231. @brief This test checks for the INVALID_EMAIL error message from the backend.
  232. */
  233. - (void)testInvalidEmailError {
  234. FIRGetOOBConfirmationCodeRequest *request =
  235. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  236. actionCodeSettings:[self fakeActionCodeSettings]
  237. requestConfiguration:_requestConfiguration];
  238. __block BOOL callbackInvoked;
  239. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  240. __block NSError *RPCError;
  241. [FIRAuthBackend getOOBConfirmationCode:request
  242. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  243. NSError *_Nullable error) {
  244. callbackInvoked = YES;
  245. RPCResponse = response;
  246. RPCError = error;
  247. }];
  248. [_RPCIssuer respondWithServerErrorMessage:kInvalidEmailErrorMessage];
  249. XCTAssert(callbackInvoked);
  250. XCTAssertNotNil(RPCError);
  251. XCTAssertEqualObjects(RPCError.domain, FIRAuthErrorDomain);
  252. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidEmail);
  253. XCTAssertNil(RPCResponse);
  254. }
  255. /** @fn testInvalidMessagePayloadError
  256. @brief Tests for @c FIRAuthErrorCodeInvalidMessagePayload.
  257. */
  258. - (void)testInvalidMessagePayloadError {
  259. FIRGetOOBConfirmationCodeRequest *request =
  260. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  261. actionCodeSettings:[self fakeActionCodeSettings]
  262. requestConfiguration:_requestConfiguration];
  263. __block BOOL callbackInvoked;
  264. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  265. __block NSError *RPCError;
  266. [FIRAuthBackend getOOBConfirmationCode:request
  267. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  268. NSError *_Nullable error) {
  269. callbackInvoked = YES;
  270. RPCResponse = response;
  271. RPCError = error;
  272. }];
  273. [_RPCIssuer respondWithServerErrorMessage:kInvalidMessagePayloadErrorMessage];
  274. XCTAssert(callbackInvoked);
  275. XCTAssertNil(RPCResponse);
  276. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidMessagePayload);
  277. }
  278. /** @fn testInvalidSenderError
  279. @brief Tests for @c FIRAuthErrorCodeInvalidSender.
  280. */
  281. - (void)testInvalidSenderError {
  282. FIRGetOOBConfirmationCodeRequest *request =
  283. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  284. actionCodeSettings:[self fakeActionCodeSettings]
  285. requestConfiguration:_requestConfiguration];
  286. __block BOOL callbackInvoked;
  287. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  288. __block NSError *RPCError;
  289. [FIRAuthBackend getOOBConfirmationCode:request
  290. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  291. NSError *_Nullable error) {
  292. callbackInvoked = YES;
  293. RPCResponse = response;
  294. RPCError = error;
  295. }];
  296. [_RPCIssuer respondWithServerErrorMessage:kInvalidSenderErrorMessage];
  297. XCTAssert(callbackInvoked);
  298. XCTAssertNil(RPCResponse);
  299. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidSender);
  300. }
  301. /** @fn testMissingIosBundleIDError
  302. @brief Tests for @c FIRAuthErrorCodeMissingIosBundleID.
  303. */
  304. - (void)testMissingIosBundleIDError {
  305. FIRGetOOBConfirmationCodeRequest *request =
  306. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  307. actionCodeSettings:[self fakeActionCodeSettings]
  308. requestConfiguration:_requestConfiguration];
  309. __block BOOL callbackInvoked;
  310. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  311. __block NSError *RPCError;
  312. [FIRAuthBackend getOOBConfirmationCode:request
  313. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  314. NSError *_Nullable error) {
  315. callbackInvoked = YES;
  316. RPCResponse = response;
  317. RPCError = error;
  318. }];
  319. [_RPCIssuer respondWithServerErrorMessage:kMissingIosBundleIDErrorMessage];
  320. XCTAssert(callbackInvoked);
  321. XCTAssertNil(RPCResponse);
  322. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeMissingIosBundleID);
  323. }
  324. /** @fn testMissingAndroidPackageNameError
  325. @brief Tests for @c FIRAuthErrorCodeMissingAndroidPackageName.
  326. */
  327. - (void)testMissingAndroidPackageNameError {
  328. FIRGetOOBConfirmationCodeRequest *request =
  329. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  330. actionCodeSettings:[self fakeActionCodeSettings]
  331. requestConfiguration:_requestConfiguration];
  332. __block BOOL callbackInvoked;
  333. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  334. __block NSError *RPCError;
  335. [FIRAuthBackend getOOBConfirmationCode:request
  336. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  337. NSError *_Nullable error) {
  338. callbackInvoked = YES;
  339. RPCResponse = response;
  340. RPCError = error;
  341. }];
  342. [_RPCIssuer respondWithServerErrorMessage:kMissingAndroidPackageNameErrorMessage];
  343. XCTAssert(callbackInvoked);
  344. XCTAssertNil(RPCResponse);
  345. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeMissingAndroidPackageName);
  346. }
  347. /** @fn testUnauthorizedDomainError
  348. @brief Tests for @c FIRAuthErrorCodeUnauthorizedDomain.
  349. */
  350. - (void)testUnauthorizedDomainError {
  351. FIRGetOOBConfirmationCodeRequest *request =
  352. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  353. actionCodeSettings:[self fakeActionCodeSettings]
  354. requestConfiguration:_requestConfiguration];
  355. __block BOOL callbackInvoked;
  356. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  357. __block NSError *RPCError;
  358. [FIRAuthBackend getOOBConfirmationCode:request
  359. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  360. NSError *_Nullable error) {
  361. callbackInvoked = YES;
  362. RPCResponse = response;
  363. RPCError = error;
  364. }];
  365. [_RPCIssuer respondWithServerErrorMessage:kUnauthorizedDomainErrorMessage];
  366. XCTAssert(callbackInvoked);
  367. XCTAssertNil(RPCResponse);
  368. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeUnauthorizedDomain);
  369. }
  370. /** @fn testInvalidContinueURIError
  371. @brief Tests for @c FIRAuthErrorCodeInvalidContinueAuthURI.
  372. */
  373. - (void)testInvalidContinueURIError {
  374. FIRGetOOBConfirmationCodeRequest *request =
  375. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  376. actionCodeSettings:[self fakeActionCodeSettings]
  377. requestConfiguration:_requestConfiguration];
  378. __block BOOL callbackInvoked;
  379. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  380. __block NSError *RPCError;
  381. [FIRAuthBackend getOOBConfirmationCode:request
  382. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  383. NSError *_Nullable error) {
  384. callbackInvoked = YES;
  385. RPCResponse = response;
  386. RPCError = error;
  387. }];
  388. [_RPCIssuer respondWithServerErrorMessage:kInvalidContinueURIErrorMessage];
  389. XCTAssert(callbackInvoked);
  390. XCTAssertNil(RPCResponse);
  391. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidContinueURI);
  392. }
  393. /** @fn testMissingContinueURIError
  394. @brief Tests for @c FIRAuthErrorCodeMissingContinueURI.
  395. */
  396. - (void)testMissingContinueURIError {
  397. FIRGetOOBConfirmationCodeRequest *request =
  398. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  399. actionCodeSettings:[self fakeActionCodeSettings]
  400. requestConfiguration:_requestConfiguration];
  401. __block BOOL callbackInvoked;
  402. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  403. __block NSError *RPCError;
  404. [FIRAuthBackend getOOBConfirmationCode:request
  405. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  406. NSError *_Nullable error) {
  407. callbackInvoked = YES;
  408. RPCResponse = response;
  409. RPCError = error;
  410. }];
  411. [_RPCIssuer respondWithServerErrorMessage:kMissingContinueURIErrorMessage];
  412. XCTAssert(callbackInvoked);
  413. XCTAssertNil(RPCResponse);
  414. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeMissingContinueURI);
  415. }
  416. /** @fn testInvalidRecipientEmailError
  417. @brief Tests for @c FIRAuthErrorCodeInvalidRecipientEmail.
  418. */
  419. - (void)testInvalidRecipientEmailError {
  420. FIRGetOOBConfirmationCodeRequest *request =
  421. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  422. actionCodeSettings:[self fakeActionCodeSettings]
  423. requestConfiguration:_requestConfiguration];
  424. __block BOOL callbackInvoked;
  425. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  426. __block NSError *RPCError;
  427. [FIRAuthBackend getOOBConfirmationCode:request
  428. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  429. NSError *_Nullable error) {
  430. callbackInvoked = YES;
  431. RPCResponse = response;
  432. RPCError = error;
  433. }];
  434. [_RPCIssuer respondWithServerErrorMessage:kInvalidRecipientEmailErrorMessage];
  435. XCTAssert(callbackInvoked);
  436. XCTAssertNil(RPCResponse);
  437. XCTAssertEqual(RPCError.code, FIRAuthErrorCodeInvalidRecipientEmail);
  438. }
  439. /** @fn testSuccessfulEmailVerificationResponse
  440. @brief This test is really not much different than the original test for password reset. But
  441. it's here for completeness sake.
  442. */
  443. - (void)testSuccessfulEmailVerificationResponse {
  444. FIRGetOOBConfirmationCodeRequest *request =
  445. [FIRGetOOBConfirmationCodeRequest passwordResetRequestWithEmail:kTestEmail
  446. actionCodeSettings:[self fakeActionCodeSettings]
  447. requestConfiguration:_requestConfiguration];
  448. __block BOOL callbackInvoked;
  449. __block FIRGetOOBConfirmationCodeResponse *RPCResponse;
  450. __block NSError *RPCError;
  451. [FIRAuthBackend getOOBConfirmationCode:request
  452. callback:^(FIRGetOOBConfirmationCodeResponse *_Nullable response,
  453. NSError *_Nullable error) {
  454. callbackInvoked = YES;
  455. RPCResponse = response;
  456. RPCError = error;
  457. }];
  458. [_RPCIssuer respondWithJSON:@{kOOBCodeKey : kTestOOBCode}];
  459. XCTAssert(callbackInvoked);
  460. XCTAssertNil(RPCError);
  461. XCTAssertNotNil(RPCResponse);
  462. XCTAssertEqualObjects(RPCResponse.OOBCode, kTestOOBCode);
  463. }
  464. #pragma mark - Helpers
  465. /** @fn fakeActionCodeSettings
  466. @brief Constructs and returns a fake instance of @c FIRActionCodeSettings for testing.
  467. @return An instance of @c FIRActionCodeSettings for testing.
  468. */
  469. - (FIRActionCodeSettings *)fakeActionCodeSettings {
  470. FIRActionCodeSettings *actionCodeSettings = [[FIRActionCodeSettings alloc] init];
  471. [actionCodeSettings setIOSBundleID:kIosBundleID];
  472. return actionCodeSettings;
  473. }
  474. @end