RevokeTokenTests.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 RevokeTokenTests: RPCBaseTests {
  19. private let kAPPTokenKey = "appToken"
  20. private let kFakeAppToken = "kAPPTokenKey"
  21. private let kFakeTokenKey = "token"
  22. private let kFakeToken = "fakeToken"
  23. private let kFakeIDTokenKey = "idToken"
  24. private let kFakeIDToken = "fakeIDToken"
  25. private let kFakeProviderIDKey = "providerId"
  26. private let kFakeTokenTypeKey = "tokenType"
  27. private let kExpectedAPIURL =
  28. "https://identitytoolkit.googleapis.com/v2/accounts:revokeToken?key=APIKey"
  29. /** @fn testRevokeTokenRequest
  30. @brief Tests the RevokeToken request.
  31. */
  32. func testRevokeTokenRequest() async throws {
  33. let request = makeRevokeTokenRequest()
  34. try await checkRequest(
  35. request: request,
  36. expected: kExpectedAPIURL,
  37. key: kFakeTokenKey,
  38. value: kFakeToken
  39. )
  40. let requestDictionary = try XCTUnwrap(rpcIssuer.decodedRequest as? [String: AnyHashable])
  41. XCTAssertEqual(requestDictionary[kFakeProviderIDKey], AuthProviderID.apple.rawValue)
  42. XCTAssertEqual(requestDictionary[kFakeTokenTypeKey], "3")
  43. }
  44. /** @fn testSuccessfulRevokeTokenResponse
  45. @brief Tests a successful attempt of the verify password flow.
  46. */
  47. func testSuccessfulRevokeTokenResponse() async throws {
  48. rpcIssuer.respondBlock = {
  49. try self.rpcIssuer?.respond(withJSON: [:])
  50. }
  51. let rpcResponse = try await AuthBackend.call(with: makeRevokeTokenRequest())
  52. XCTAssertNotNil(rpcResponse)
  53. }
  54. private func makeRevokeTokenRequest() -> RevokeTokenRequest {
  55. return RevokeTokenRequest(withToken: kFakeToken,
  56. idToken: kFakeIDToken,
  57. requestConfiguration: makeRequestConfiguration())
  58. }
  59. }