Files
firebase-ios-sdk/FirebaseFunctions/Tests/ObjCIntegration/ObjCAPITests.m
T
0cbe4f2920 Firebase App Check One-time Use Tokens for Callable Functions SDK (#11270)
* draft pr for callable functions

* Adjust Functions podspec dependency on AppCheckInterop

* Add 'HTTPSCallableOptions' class

* Re-implement with new HTTPSCallableOptions type

* Revert and update Objective-C API tests

* Mark new AppCheckInterop API optional for backwards compatibility

* Preserve existing codable Functions API

* Revert integration tests

* Style

* Fix some test build breakages

* Add changelog entry

* Style

* Fix AppCheck tests

* Cleanup current approach

* Re-organize tests

* Add 'options' param to 'getContext' call

* Add success case unit test

* Shorten expectation waiting timeout

* Add remaining unit tests

* Amend current test

* Rename 'limitedUseTokens' to 'requireLimitedUseTokens'

* Fix build and tests

* Fix some renaming misses

* Fix some renaming misses (1)

* Update FirebaseFunctions/CHANGELOG.md

Co-authored-by: Andrew Heard <andrewheard@google.com>

* Update FirebaseFunctions/Sources/Functions.swift

Co-authored-by: Andrew Heard <andrewheard@google.com>

* Update FirebaseFunctions/Sources/Functions.swift

Co-authored-by: Andrew Heard <andrewheard@google.com>

* Update FirebaseFunctions/Sources/Functions.swift

Co-authored-by: Andrew Heard <andrewheard@google.com>

* Update FirebaseFunctions/Sources/Functions.swift

Co-authored-by: Andrew Heard <andrewheard@google.com>

* Update FirebaseFunctions/Sources/HTTPSCallableOptions.swift

Co-authored-by: Andrew Heard <andrewheard@google.com>

* [App Check] Always return fresh limitedUseToken (#11298)

Updated `limitedUseTokenWithCompletion:` to always return a fresh limited-used token in every invocation (removed the `ongoingLimitedUseTokenPromise` property).

---------

Co-authored-by: Nick Cooke <nickcooke@google.com>
Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com>
Co-authored-by: Andrew Heard <andrewheard@google.com>
2023-05-16 18:33:15 -04:00

87 lines
3.1 KiB
Objective-C

// Copyright 2022 Google LLC
//
// 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 FirebaseCore;
@import FirebaseFunctions;
@interface ObjCAPICoverage : XCTestCase
@end
@implementation ObjCAPICoverage
- (void)apis {
#pragma mark - Functions
FIRApp *app = [FIRApp defaultApp];
FIRFunctions *func = [FIRFunctions functions];
func = [FIRFunctions functionsForApp:app];
func = [FIRFunctions functionsForRegion:@"my-region"];
func = [FIRFunctions functionsForCustomDomain:@"my-domain"];
func = [FIRFunctions functionsForApp:app region:@"my-region"];
func = [FIRFunctions functionsForApp:app customDomain:@"my-domain"];
NSURL *url = [NSURL URLWithString:@"http://localhost:5050/project/location/name"];
FIRHTTPSCallable *callable = [func HTTPSCallableWithURL:url];
callable = [func HTTPSCallableWithName:@"name"];
FIRHTTPSCallableOptions *options =
[[FIRHTTPSCallableOptions alloc] initWithRequireLimitedUseAppCheckTokens:YES];
__unused BOOL requireLimitedUseAppCheckTokens = options.requireLimitedUseAppCheckTokens;
callable = [func HTTPSCallableWithURL:url options:options];
callable = [func HTTPSCallableWithName:@"name" options:options];
[func useEmulatorWithHost:@"host" port:123];
#pragma mark - HTTPSCallable and HTTPSCallableResult
[callable
callWithCompletion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) {
__unused id data = result.data;
}];
[callable callWithObject:nil
completion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) {
[result data];
}];
callable.timeoutInterval = 60;
[callable timeoutInterval];
}
#pragma mark - FunctionsError
- (FIRFunctionsErrorCode)errorCodes:(NSError *)error {
switch (error.code) {
case FIRFunctionsErrorCodeOK:
case FIRFunctionsErrorCodeCancelled:
case FIRFunctionsErrorCodeUnknown:
case FIRFunctionsErrorCodeInvalidArgument:
case FIRFunctionsErrorCodeDeadlineExceeded:
case FIRFunctionsErrorCodeNotFound:
case FIRFunctionsErrorCodeAlreadyExists:
case FIRFunctionsErrorCodePermissionDenied:
case FIRFunctionsErrorCodeResourceExhausted:
case FIRFunctionsErrorCodeFailedPrecondition:
case FIRFunctionsErrorCodeAborted:
case FIRFunctionsErrorCodeOutOfRange:
case FIRFunctionsErrorCodeUnimplemented:
case FIRFunctionsErrorCodeInternal:
case FIRFunctionsErrorCodeUnavailable:
case FIRFunctionsErrorCodeDataLoss:
case FIRFunctionsErrorCodeUnauthenticated:
return error.code;
}
return error.code;
}
@end