FIRFakeBackendRPCIssuer.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/Backend/FIRAuthBackend.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** @class FIRFakeBackendRPCIssuer
  20. @brief An implementation of @c FIRAuthBackendRPCIssuer which is used to test backend request,
  21. response, and glue logic.
  22. */
  23. @interface FIRFakeBackendRPCIssuer : NSObject <FIRAuthBackendRPCIssuer>
  24. /** @property requestURL
  25. @brief The URL which was requested.
  26. */
  27. @property(nonatomic, readonly) NSURL *requestURL;
  28. /** @property requestData
  29. @brief The raw data in the POST body.
  30. */
  31. @property(nonatomic, readonly) NSData *requestData;
  32. /** @property decodedRequest
  33. @brief The raw data in the POST body decoded as JSON.
  34. */
  35. @property(nonatomic, readonly) NSDictionary *decodedRequest;
  36. /** @property contentType
  37. @brief The value of the content type HTTP header in the request.
  38. */
  39. @property(nonatomic, readonly) NSString *contentType;
  40. /** @fn respondWithData:error:
  41. @brief Responds to a pending RPC request with data and an error.
  42. @remarks This is useful for simulating an error response with bogus data or unexpected data
  43. (like unexpectedly receiving an HTML body.)
  44. @param data The data to return as the body of an HTTP response.
  45. @param error The simulated error to return from GTM.
  46. */
  47. - (void)respondWithData:(nullable NSData *)data error:(nullable NSError *)error;
  48. /** @fn respondWithJSON:error:
  49. @brief Responds to a pending RPC request with JSON and an error.
  50. @remarks This is useful for simulating an error response with error JSON.
  51. @param JSON The JSON to return.
  52. @param error The simulated error to return from GTM.
  53. */
  54. - (nullable NSData *)respondWithJSON:(nullable NSDictionary *)JSON error:(nullable NSError *)error;
  55. /** @fn respondWithJSONError:
  56. @brief Responds to a pending RPC request with a JSON server error.
  57. @param JSON A dictionary which should be a server error encoded as JSON for fake response.
  58. */
  59. - (NSData *)respondWithJSONError:(NSDictionary *)JSON;
  60. /** @fn respondWithError:
  61. @brief Responds to a pending RPC request with an error. This is useful for simulating things
  62. like a network timeout or unreachable host.
  63. @param error The simulated error to return from GTM.
  64. */
  65. - (NSData *)respondWithError:(NSError *)error;
  66. /** @fn respondWithServerErrorMessage:error:
  67. @brief Responds to a pending RPC request with a server error message.
  68. @param errorMessage The simulated error message to return from the server.
  69. @param error The simulated error to return from GTM.
  70. */
  71. - (NSData *)respondWithServerErrorMessage:(NSString *)errorMessage error:(NSError *)error;
  72. /** @fn respondWithServerErrorMessage:
  73. @brief Responds to a pending RPC request with a server error message.
  74. @param errorMessage The simulated error message to return from the server.
  75. */
  76. - (NSData *)respondWithServerErrorMessage:(NSString *)errorMessage;
  77. /** @fn respondWithJSON:
  78. @brief Responds to a pending RPC request with JSON.
  79. @param JSON A dictionary which should be encoded as JSON for a fake response.
  80. */
  81. - (NSData *)respondWithJSON:(NSDictionary *)JSON;
  82. @end
  83. NS_ASSUME_NONNULL_END