FIRAppCheckValidatorTests.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 2024 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 <XCTest/XCTest.h>
  17. #import "FirebaseAppCheck/Sources/Core/FIRAppCheckValidator.h"
  18. #import "FirebaseCore/Extension/FIROptionsInternal.h"
  19. @interface FIRAppCheckValidatorTests : XCTestCase
  20. @end
  21. @implementation FIRAppCheckValidatorTests
  22. - (void)test_tokenExchangeMissingFieldsInOptions_noMissingFields {
  23. FIROptions *options = [[FIROptions alloc] initInternalWithOptionsDictionary:@{
  24. kFIRGoogleAppID : @"TEST_GoogleAppID",
  25. kFIRAPIKey : @"TEST_APIKey",
  26. kFIRProjectID : @"TEST_ProjectID"
  27. }];
  28. NSArray *missingFields = [FIRAppCheckValidator tokenExchangeMissingFieldsInOptions:options];
  29. XCTAssertEqual(missingFields.count, 0);
  30. }
  31. - (void)test_tokenExchangeMissingFieldsInOptions_singleMissingField {
  32. // Google App ID is empty:
  33. FIROptions *options = [[FIROptions alloc] initInternalWithOptionsDictionary:@{
  34. kFIRGoogleAppID : @"",
  35. kFIRAPIKey : @"TEST_APIKey",
  36. kFIRProjectID : @"TEST_ProjectID"
  37. }];
  38. NSArray *missingFields = [FIRAppCheckValidator tokenExchangeMissingFieldsInOptions:options];
  39. XCTAssertTrue([missingFields isEqualToArray:@[ @"googleAppID" ]]);
  40. }
  41. - (void)test_tokenExchangeMissingFieldsInOptions_multipleMissingFields {
  42. // Google App ID is empty, and API Key and Project ID are not set:
  43. FIROptions *options =
  44. [[FIROptions alloc] initInternalWithOptionsDictionary:@{kFIRGoogleAppID : @""}];
  45. NSArray *missingFields = [FIRAppCheckValidator tokenExchangeMissingFieldsInOptions:options];
  46. NSArray *expectedMissingFields = @[ @"APIKey", @"projectID", @"googleAppID" ];
  47. XCTAssertTrue([missingFields isEqualToArray:expectedMissingFields]);
  48. }
  49. @end