FIRAuthTests.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "FirebaseAuth/Interop/FIRAuthInterop.h"
  18. #import "FirebaseCore/Extension/FirebaseCoreInternal.h"
  19. #import "FirebaseDatabase/Sources/FIRDatabaseConfig_Private.h"
  20. #import "FirebaseDatabase/Tests/Helpers/FTestBase.h"
  21. #import "FirebaseDatabase/Tests/Helpers/FTestHelpers.h"
  22. #import "SharedTestUtilities/AppCheckFake/FIRAppCheckFake.h"
  23. #import "SharedTestUtilities/AppCheckFake/FIRAppCheckTokenResultFake.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<FIRAppCheckInterop> appCheck = [[FIRAppCheckFake alloc] init];
  38. id<FIRDatabaseConnectionContextProvider> contextProvider =
  39. [FIRDatabaseConnectionContextProvider contextProviderWithAuth:auth appCheck:appCheck];
  40. FIRDatabaseConfig *config = [FTestHelpers configForName:@"testWritesRestoredAfterAuth"];
  41. config.contextProvider = contextProvider;
  42. FIRDatabaseReference *ref = [[[FTestHelpers databaseForConfig:config] reference] 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