FIRAuthTests.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2017 Google
  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 <FirebaseAuthInterop/FIRAuthInterop.h>
  18. #import <FirebaseCore/FIRAppInternal.h>
  19. #import <FirebaseCore/FIRComponent.h>
  20. #import <FirebaseCore/FIRComponentContainer.h>
  21. #import "FIRAuthInteropFake.h"
  22. #import "FIRDatabaseConfig_Private.h"
  23. #import "FIRTestAuthTokenProvider.h"
  24. #import "FTestAuthTokenGenerator.h"
  25. #import "FTestBase.h"
  26. #import "FTestHelpers.h"
  27. @interface FIRAuthTests : FTestBase
  28. @end
  29. @implementation FIRAuthTests
  30. - (void)setUp {
  31. [super setUp];
  32. }
  33. - (void)tearDown {
  34. [super tearDown];
  35. }
  36. - (void)testListensAndAuthRaceCondition {
  37. [FIRDatabase setLoggingEnabled:YES];
  38. FIRAuthInteropFake *auth = [[FIRAuthInteropFake alloc] initWithToken:nil userID:nil error:nil];
  39. id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderWithAuth:auth];
  40. FIRDatabaseConfig *config = [FTestHelpers configForName:@"testWritesRestoredAfterAuth"];
  41. config.authTokenProvider = authTokenProvider;
  42. FIRDatabaseReference *ref = [[[FIRDatabaseReference alloc] initWithConfig:config] childByAutoId];
  43. __block BOOL done = NO;
  44. [[[ref root] child:@".info/connected"]
  45. observeEventType:FIRDataEventTypeValue
  46. withBlock:^void(FIRDataSnapshot *snapshot) {
  47. if ([snapshot.value boolValue]) {
  48. // Start a listen before auth credentials are restored.
  49. [ref observeEventType:FIRDataEventTypeValue
  50. withBlock:^(FIRDataSnapshot *snapshot){
  51. }];
  52. // subsequent writes should complete successfully.
  53. [ref setValue:@42
  54. withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
  55. done = YES;
  56. }];
  57. }
  58. }];
  59. WAIT_FOR(done);
  60. }
  61. @end