FIRAuthTests.m 2.6 KB

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