FIRAuthTests.m 2.5 KB

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