FIRAuthUseUserAccessGroupTests.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2020 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 <OCMock/OCMock.h>
  17. #import <XCTest/XCTest.h>
  18. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FirebaseAuth.h"
  19. #import "FirebaseAuth/Sources/SystemService/FIRAuthStoredUserManager.h"
  20. #import "FirebaseAuth/Tests/Unit/FIRApp+FIRAuthUnitTests.h"
  21. @interface FIRAuth (Test)
  22. @property(nonatomic, strong, nullable) FIRAuthStoredUserManager *storedUserManager;
  23. + (NSString *)keychainServiceNameForAppName:(NSString *)appName;
  24. @end
  25. @interface UseUserAccessGroupTests : XCTestCase
  26. @end
  27. @implementation UseUserAccessGroupTests
  28. - (void)setUp {
  29. [super setUp];
  30. [FIRApp resetAppForAuthUnitTests];
  31. }
  32. - (void)testUseUserAccessGroup {
  33. id classMock = OCMClassMock([FIRAuth class]);
  34. OCMStub([classMock keychainServiceNameForAppName:OCMOCK_ANY]).andReturn(nil);
  35. FIRAuthStoredUserManager *myManager =
  36. [[FIRAuthStoredUserManager alloc] initWithServiceName:@"MyService"];
  37. [myManager setStoredUserAccessGroup:@"MyGroup" error:nil];
  38. FIRAuth *auth = [FIRAuth auth];
  39. XCTAssertNotNil(auth);
  40. id partialMock = OCMPartialMock(auth);
  41. OCMStub([partialMock storedUserManager]).andReturn(myManager);
  42. XCTAssertNotNil([auth.storedUserManager getStoredUserAccessGroupWithError:nil]);
  43. XCTAssertTrue([auth useUserAccessGroup:@"id.com.example.group1" error:nil]);
  44. XCTAssertTrue([auth useUserAccessGroup:@"id.com.example.group2" error:nil]);
  45. XCTAssertTrue([auth useUserAccessGroup:nil error:nil]);
  46. [partialMock stopMocking];
  47. }
  48. @end