DeleteAccountTests.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. rpcIssuer?.respondBlock = {
  59. try self.rpcIssuer?.respond(withJSON: [:])
  60. }
  61. let rpcResponse = try await AuthBackend.call(with: makeDeleteAccountRequest())
  62. XCTAssertNotNil(rpcResponse)
  63. }
  64. private func makeDeleteAccountRequest() -> DeleteAccountRequest {
  65. return DeleteAccountRequest(localID: kLocalID,
  66. accessToken: "Access Token",
  67. requestConfiguration: makeRequestConfiguration())
  68. }
  69. }