mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-10 22:45:59 +05:45
* Allow Functions to be called without Auth. This was a regression from previous functionality, but is reverted mostly to the old functionality. Previously `context` would be `nil` in the completion handler if no Auth was available, but now `context` still contains `instanceIDToken` but no `authToken`. Also cover unit tests for the three states: no auth, auth error, and valid auth. * Style fixes. * Cast Auth fake to prevent warning.
74 lines
2.9 KiB
Objective-C
74 lines
2.9 KiB
Objective-C
// Copyright 2019 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>
|
|
|
|
#import "FIRAuthInteropFake.h"
|
|
#import "FUNContext.h"
|
|
|
|
@interface FUNContextProviderTests : XCTestCase
|
|
@end
|
|
|
|
@implementation FUNContextProviderTests
|
|
|
|
- (void)testContextWithAuth {
|
|
FIRAuthInteropFake *auth = [[FIRAuthInteropFake alloc] initWithToken:@"token"
|
|
userID:@"userID"
|
|
error:nil];
|
|
FUNContextProvider *provider = [[FUNContextProvider alloc] initWithAuth:(id<FIRAuthInterop>)auth];
|
|
XCTestExpectation *expectation =
|
|
[self expectationWithDescription:@"Context should have auth keys."];
|
|
[provider getContext:^(FUNContext *_Nullable context, NSError *_Nullable error) {
|
|
XCTAssert([context.authToken isEqualToString:@"token"]);
|
|
XCTAssert([context.instanceIDToken isEqualToString:@"iid"]);
|
|
XCTAssertNil(error);
|
|
[expectation fulfill];
|
|
}];
|
|
|
|
[self waitForExpectations:@[ expectation ] timeout:0.1];
|
|
}
|
|
|
|
- (void)testContextWithAuthError {
|
|
NSError *authError = [[NSError alloc] initWithDomain:@"com.functions.tests" code:4 userInfo:nil];
|
|
FIRAuthInteropFake *auth = [[FIRAuthInteropFake alloc] initWithToken:nil
|
|
userID:nil
|
|
error:authError];
|
|
FUNContextProvider *provider = [[FUNContextProvider alloc] initWithAuth:(id<FIRAuthInterop>)auth];
|
|
XCTestExpectation *expectation =
|
|
[self expectationWithDescription:@"Completion handler should fail with Auth error."];
|
|
[provider getContext:^(FUNContext *_Nullable context, NSError *_Nullable error) {
|
|
XCTAssertNil(context);
|
|
XCTAssertEqual(error, auth.error);
|
|
[expectation fulfill];
|
|
}];
|
|
|
|
[self waitForExpectations:@[ expectation ] timeout:0.1];
|
|
}
|
|
|
|
- (void)testContextWithoutAuth {
|
|
FUNContextProvider *provider = [[FUNContextProvider alloc] initWithAuth:nil];
|
|
XCTestExpectation *expectation =
|
|
[self expectationWithDescription:@"Completion handler should succeed without Auth."];
|
|
[provider getContext:^(FUNContext *_Nullable context, NSError *_Nullable error) {
|
|
XCTAssertNil(error);
|
|
XCTAssertNil(context.authToken);
|
|
XCTAssert([context.instanceIDToken isEqualToString:@"iid"]);
|
|
[expectation fulfill];
|
|
}];
|
|
|
|
[self waitForExpectations:@[ expectation ] timeout:0.1];
|
|
}
|
|
|
|
@end
|