GIDFailingOIDAuthState.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2023 Google LLC
  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 "GIDFailingOIDAuthState.h"
  17. #import "GoogleSignIn/Tests/Unit/OIDAuthState+Testing.h"
  18. #import "GoogleSignIn/Tests/Unit/OIDAuthorizationResponse+Testing.h"
  19. #import "GoogleSignIn/Tests/Unit/OIDTokenResponse+Testing.h"
  20. @implementation GIDFailingOIDAuthState
  21. + (instancetype)testInstance {
  22. OIDAuthorizationResponse *testAuthResponse = [OIDAuthorizationResponse testInstance];
  23. OIDTokenResponse *testTokenResponse = [OIDTokenResponse testInstance];
  24. return [[GIDFailingOIDAuthState alloc] initWithAuthorizationResponse:testAuthResponse
  25. tokenResponse:testTokenResponse];
  26. }
  27. - (void)performActionWithFreshTokens:(OIDAuthStateAction)action
  28. additionalRefreshParameters:
  29. (nullable NSDictionary<NSString *, NSString *> *)additionalParameters {
  30. [self performActionWithFreshTokens:action
  31. additionalRefreshParameters:additionalParameters
  32. dispatchQueue:dispatch_get_main_queue()];
  33. }
  34. // Forces the OIDAuthState to fail with the error below to simulate an error handled by EMM support
  35. - (void)performActionWithFreshTokens:(OIDAuthStateAction)action
  36. additionalRefreshParameters:(NSDictionary<NSString *,NSString *> *)additionalParameters
  37. dispatchQueue:(dispatch_queue_t)dispatchQueue {
  38. NSDictionary<NSString *, id> *userInfo = @{
  39. @"OIDOAuthErrorResponseErrorKey": @{@"error": @"emm_passcode_required"},
  40. NSUnderlyingErrorKey: [NSError errorWithDomain:@"SomeUnderlyingError" code:0 userInfo:nil]
  41. };
  42. NSError *error = [NSError errorWithDomain:@"org.openid.appauth.resourceserver"
  43. code:0
  44. userInfo:userInfo];
  45. action(nil, nil, error);
  46. }
  47. @end