DeleteAccountTests.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. import XCTest
  16. @testable import FirebaseAuth
  17. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  18. class DeleteAccountTests: RPCBaseTests {
  19. /** @var kLocalIDKey
  20. @brief The name of the "localID" property in the request.
  21. */
  22. let kLocalIDKey = "localId"
  23. /** @var kExpectedAPIURL
  24. @brief The expected URL for the test calls.
  25. */
  26. let kExpectedAPIURL =
  27. "https://www.googleapis.com/identitytoolkit/v3/relyingparty/deleteAccount?key=APIKey"
  28. func testDeleteAccount() async throws {
  29. let kUserDisabledErrorMessage = "USER_DISABLED"
  30. let kInvalidUserTokenErrorMessage = "INVALID_ID_TOKEN:"
  31. let kCredentialTooOldErrorMessage = "CREDENTIAL_TOO_OLD_LOGIN_AGAIN:"
  32. try await checkRequest(
  33. request: makeDeleteAccountRequest(),
  34. expected: kExpectedAPIURL,
  35. key: kLocalIDKey,
  36. value: kLocalID
  37. )
  38. try await checkBackendError(
  39. request: makeDeleteAccountRequest(),
  40. message: kUserDisabledErrorMessage,
  41. errorCode: AuthErrorCode.userDisabled
  42. )
  43. try await checkBackendError(
  44. request: makeDeleteAccountRequest(),
  45. message: kInvalidUserTokenErrorMessage,
  46. errorCode: AuthErrorCode.invalidUserToken
  47. )
  48. try await checkBackendError(
  49. request: makeDeleteAccountRequest(),
  50. message: kCredentialTooOldErrorMessage,
  51. errorCode: AuthErrorCode.requiresRecentLogin
  52. )
  53. }
  54. /** @fn testSuccessfulDeleteAccount
  55. @brief This test checks for a successful response
  56. */
  57. func testSuccessfulDeleteAccountResponse() async throws {
  58. let rpcIssuer = try XCTUnwrap(self.rpcIssuer)
  59. rpcIssuer.respondBlock = {
  60. try self.rpcIssuer.respond(withJSON: [:])
  61. }
  62. let rpcResponse = try await authBackend.call(with: makeDeleteAccountRequest())
  63. XCTAssertNotNil(rpcResponse)
  64. }
  65. private func makeDeleteAccountRequest() -> DeleteAccountRequest {
  66. return DeleteAccountRequest(localID: kLocalID,
  67. accessToken: "Access Token",
  68. requestConfiguration: makeRequestConfiguration())
  69. }
  70. }