FIRAppCheckValidatorTests.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/Sources/Public/FirebaseCore/FIROptions.h"
  19. @interface FIRAppCheckValidatorTests : XCTestCase
  20. @end
  21. @implementation FIRAppCheckValidatorTests
  22. - (void)test_tokenExchangeMissingFieldsInOptions_noMissingFields {
  23. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:@"TEST_GoogleAppID"
  24. GCMSenderID:@"TEST_GCMSenderID"];
  25. options.APIKey = @"TEST_APIKey";
  26. options.projectID = @"TEST_ProjectID";
  27. NSArray *missingFields = [FIRAppCheckValidator tokenExchangeMissingFieldsInOptions:options];
  28. XCTAssertEqual(missingFields.count, 0);
  29. }
  30. - (void)test_tokenExchangeMissingFieldsInOptions_singleMissingField {
  31. // Google App ID is empty:
  32. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:@""
  33. GCMSenderID:@"TEST_GCMSenderID"];
  34. options.APIKey = @"TEST_APIKey";
  35. options.projectID = @"TEST_ProjectID";
  36. NSArray *missingFields = [FIRAppCheckValidator tokenExchangeMissingFieldsInOptions:options];
  37. XCTAssertTrue([missingFields isEqualToArray:@[ @"googleAppID" ]]);
  38. }
  39. - (void)test_tokenExchangeMissingFieldsInOptions_multipleMissingFields {
  40. // Google App ID is empty, and API Key and Project ID are not set:
  41. FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:@""
  42. GCMSenderID:@"TEST_GCMSenderID"];
  43. NSArray *missingFields = [FIRAppCheckValidator tokenExchangeMissingFieldsInOptions:options];
  44. NSArray *expectedMissingFields = @[ @"APIKey", @"projectID", @"googleAppID" ];
  45. XCTAssertTrue([missingFields isEqualToArray:expectedMissingFields]);
  46. }
  47. @end