Files
firebase-ios-sdk/Example/Database/Tests/Integration/FIRAuthTests.m
T

77 lines
2.4 KiB
Objective-C
Raw Normal View History

2017-05-15 12:27:07 -07:00
/*
* Copyright 2017 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <XCTest/XCTest.h>
2017-11-22 09:19:10 -08:00
2018-11-22 06:44:42 -05:00
#import <FirebaseAuthInterop/FIRAuthInterop.h>
#import <FirebaseCore/FIRAppInternal.h>
#import <FirebaseCore/FIRComponent.h>
#import <FirebaseCore/FIRComponentContainer.h>
2017-11-22 09:19:10 -08:00
2018-11-22 06:44:42 -05:00
#import "FIRAuthInteropFake.h"
2018-11-19 09:52:42 -05:00
#import "FIRDatabaseConfig_Private.h"
2018-11-22 06:44:42 -05:00
#import "FIRTestAuthTokenProvider.h"
#import "FTestAuthTokenGenerator.h"
2018-11-19 09:52:42 -05:00
#import "FTestBase.h"
2018-11-22 06:44:42 -05:00
#import "FTestHelpers.h"
2017-05-15 12:27:07 -07:00
@interface FIRAuthTests : FTestBase
@end
@implementation FIRAuthTests
- (void)setUp {
2018-11-22 06:44:42 -05:00
[super setUp];
2017-05-15 12:27:07 -07:00
}
- (void)tearDown {
2018-11-22 06:44:42 -05:00
[super tearDown];
2017-05-15 12:27:07 -07:00
}
- (void)testListensAndAuthRaceCondition {
2018-11-22 06:44:42 -05:00
[FIRDatabase setLoggingEnabled:YES];
FIRAuthInteropFake *auth = [[FIRAuthInteropFake alloc] initWithToken:nil userID:nil error:nil];
id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderWithAuth:auth];
2017-05-15 12:27:07 -07:00
2018-11-22 06:44:42 -05:00
FIRDatabaseConfig *config = [FTestHelpers configForName:@"testWritesRestoredAfterAuth"];
config.authTokenProvider = authTokenProvider;
2017-05-15 12:27:07 -07:00
2018-11-22 06:44:42 -05:00
FIRDatabaseReference *ref = [[[FIRDatabaseReference alloc] initWithConfig:config] childByAutoId];
2017-05-15 12:27:07 -07:00
2018-11-22 06:44:42 -05:00
__block BOOL done = NO;
2017-05-15 12:27:07 -07:00
2018-11-22 06:44:42 -05:00
[[[ref root] child:@".info/connected"]
observeEventType:FIRDataEventTypeValue
withBlock:^void(FIRDataSnapshot *snapshot) {
if ([snapshot.value boolValue]) {
// Start a listen before auth credentials are restored.
[ref observeEventType:FIRDataEventTypeValue
withBlock:^(FIRDataSnapshot *snapshot){
2017-05-15 12:27:07 -07:00
2018-11-22 06:44:42 -05:00
}];
2017-05-15 12:27:07 -07:00
2018-11-22 06:44:42 -05:00
// subsequent writes should complete successfully.
[ref setValue:@42
withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
done = YES;
}];
}
}];
2017-05-15 12:27:07 -07:00
2018-11-22 06:44:42 -05:00
WAIT_FOR(done);
2017-05-15 12:27:07 -07:00
}
@end