FIRFakeBackendRPCIssuer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. /** @property completeRequest
  41. @brief The last request to be processed by the backend.
  42. */
  43. @property(atomic, readonly) NSURLRequest *completeRequest;
  44. /** @fn respondWithData:error:
  45. @brief Responds to a pending RPC request with data and an error.
  46. @remarks This is useful for simulating an error response with bogus data or unexpected data
  47. (like unexpectedly receiving an HTML body.)
  48. @param data The data to return as the body of an HTTP response.
  49. @param error The simulated error to return from GTM.
  50. */
  51. - (void)respondWithData:(nullable NSData *)data error:(nullable NSError *)error;
  52. /** @fn respondWithJSON:error:
  53. @brief Responds to a pending RPC request with JSON and an error.
  54. @remarks This is useful for simulating an error response with error JSON.
  55. @param JSON The JSON to return.
  56. @param error The simulated error to return from GTM.
  57. */
  58. - (nullable NSData *)respondWithJSON:(nullable NSDictionary *)JSON error:(nullable NSError *)error;
  59. /** @fn respondWithJSONError:
  60. @brief Responds to a pending RPC request with a JSON server error.
  61. @param JSON A dictionary which should be a server error encoded as JSON for fake response.
  62. */
  63. - (NSData *)respondWithJSONError:(NSDictionary *)JSON;
  64. /** @fn respondWithError:
  65. @brief Responds to a pending RPC request with an error. This is useful for simulating things
  66. like a network timeout or unreachable host.
  67. @param error The simulated error to return from GTM.
  68. */
  69. - (NSData *)respondWithError:(NSError *)error;
  70. /** @fn respondWithServerErrorMessage:error:
  71. @brief Responds to a pending RPC request with a server error message.
  72. @param errorMessage The simulated error message to return from the server.
  73. @param error The simulated error to return from GTM.
  74. */
  75. - (NSData *)respondWithServerErrorMessage:(NSString *)errorMessage error:(NSError *)error;
  76. /** @fn respondWithServerErrorMessage:
  77. @brief Responds to a pending RPC request with a server error message.
  78. @param errorMessage The simulated error message to return from the server.
  79. */
  80. - (NSData *)respondWithServerErrorMessage:(NSString *)errorMessage;
  81. /** @fn respondWithJSON:
  82. @brief Responds to a pending RPC request with JSON.
  83. @param JSON A dictionary which should be encoded as JSON for a fake response.
  84. */
  85. - (NSData *)respondWithJSON:(NSDictionary *)JSON;
  86. @end
  87. NS_ASSUME_NONNULL_END