FIRAuthTests.m 2.0 KB

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