GIDSignInCallbackSchemesTest.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <XCTest/XCTest.h>
  15. #import "GoogleSignIn/Sources/GIDSignInCallbackSchemes.h"
  16. #import "GoogleSignIn/Tests/Unit/GIDFakeMainBundle.h"
  17. static NSString *const kClientId = @"FakeClientID";
  18. static NSString *const kBundleId = @"FakeBundleID";
  19. @interface GIDSignInCallbackSchemesTest : XCTestCase
  20. @end
  21. @implementation GIDSignInCallbackSchemesTest {
  22. GIDFakeMainBundle *_fakeMainBundle;
  23. }
  24. - (void)setUp {
  25. _fakeMainBundle = [[GIDFakeMainBundle alloc] init];
  26. [_fakeMainBundle startFakingWithBundleId:kBundleId clientId:kClientId];
  27. }
  28. - (void)tearDown {
  29. [_fakeMainBundle stopFaking];
  30. }
  31. #pragma mark - Tests
  32. - (void)testClientIdentifierScheme {
  33. GIDSignInCallbackSchemes *schemes =
  34. [[GIDSignInCallbackSchemes alloc] initWithClientIdentifier:kClientId];
  35. XCTAssertEqualObjects(schemes.clientIdentifierScheme, kClientId.lowercaseString);
  36. }
  37. - (void)testAllSchemes {
  38. GIDSignInCallbackSchemes *schemes =
  39. [[GIDSignInCallbackSchemes alloc] initWithClientIdentifier:kClientId];
  40. XCTAssertEqual(schemes.allSchemes.count, 1U);
  41. for (NSString *scheme in schemes.allSchemes) {
  42. if ([scheme isEqual:kClientId.lowercaseString]) {
  43. continue;
  44. }
  45. XCTAssert(NO, @"Found unknown scheme in schemes list.");
  46. }
  47. }
  48. /**
  49. * @fn testUnsupportedSchemes
  50. * @brief Makes sure that various permutations of the info.plist work with the unsupportedSchemes
  51. * method. Specifically, checks that missing schemes are properly returned, that
  52. * case-sensitivity issues don't cause a problem, and that the different ways of representing
  53. * multiple schemes in the info.plist all work correctly.
  54. */
  55. - (void)testUnsupportedSchemes {
  56. GIDSignInCallbackSchemes *schemes =
  57. [[GIDSignInCallbackSchemes alloc] initWithClientIdentifier:kClientId];
  58. [_fakeMainBundle fakeAllSchemesSupported];
  59. XCTAssertEqual([schemes unsupportedSchemes].count, 0ul);
  60. [_fakeMainBundle fakeAllSchemesSupportedAndMerged];
  61. XCTAssertEqual([schemes unsupportedSchemes].count, 0ul);
  62. [_fakeMainBundle fakeOtherSchemesAndAllSchemes];
  63. XCTAssertEqual([schemes unsupportedSchemes].count, 0ul);
  64. [_fakeMainBundle fakeAllSchemesSupportedWithCasesMangled];
  65. XCTAssertEqual([schemes unsupportedSchemes].count, 0ul);
  66. [_fakeMainBundle fakeMissingClientIdScheme];
  67. XCTAssertEqual([schemes unsupportedSchemes].count, 1ul);
  68. [_fakeMainBundle fakeMissingAllSchemes];
  69. XCTAssertEqual([schemes unsupportedSchemes].count, 1ul);
  70. [_fakeMainBundle fakeOtherSchemes];
  71. XCTAssertEqual([schemes unsupportedSchemes].count, 1ul);
  72. }
  73. - (void)testURLSchemeIsCallbackScheme {
  74. GIDSignInCallbackSchemes *schemes =
  75. [[GIDSignInCallbackSchemes alloc] initWithClientIdentifier:kClientId];
  76. NSURL *clientIdentifierURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@:/", kClientId]];
  77. NSURL *junkIdentifierURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@:/", @"junk"]];
  78. XCTAssert([schemes URLSchemeIsCallbackScheme:clientIdentifierURL]);
  79. XCTAssertFalse([schemes URLSchemeIsCallbackScheme:junkIdentifierURL]);
  80. }
  81. @end