diff options
author | Xiangtian Dai <xiangtian@google.com> | 2017-07-28 17:44:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-28 17:44:46 -0700 |
commit | e5524db414ee4ad43301efa12c0029564b6eb253 (patch) | |
tree | ffe4aa0a42f6447341599884515083a6fdded38c /Example | |
parent | 925a1cc0a27a3afb17b862a0740b56e56c3ae669 (diff) |
APNs token handling improvements. (#157)
* APNs token handling improvements.
- Calls VerifyClient without token anyway if the APNs token cannot be retrieved.
This allows server to use discretion if needed in future. The developer will
receive the same error as before.
- Moves token formatting code to the token class itself to make the main logic
in the provider class more clear. This also eliminates duplicated code in the
sample app.
* Adds a comment about a string constant used in test.
Diffstat (limited to 'Example')
-rw-r--r-- | Example/Auth/Tests/FIRAuthAPNSTokenTests.m | 7 | ||||
-rw-r--r-- | Example/Auth/Tests/FIRPhoneAuthProviderTests.m | 13 |
2 files changed, 17 insertions, 3 deletions
diff --git a/Example/Auth/Tests/FIRAuthAPNSTokenTests.m b/Example/Auth/Tests/FIRAuthAPNSTokenTests.m index d2cd0b5..6eeabd3 100644 --- a/Example/Auth/Tests/FIRAuthAPNSTokenTests.m +++ b/Example/Auth/Tests/FIRAuthAPNSTokenTests.m @@ -27,14 +27,15 @@ NS_ASSUME_NONNULL_BEGIN @end @implementation FIRAuthAPNSTokenTests -/** @fn testInitializer - @brief Tests the initializer of the class. +/** @fn testProperties + @brief Tests the properties of the class. */ -- (void)testInitializer { +- (void)testProperties { NSData *data = [@"asdf" dataUsingEncoding:NSUTF8StringEncoding]; FIRAuthAPNSToken *token = [[FIRAuthAPNSToken alloc] initWithData:data type:FIRAuthAPNSTokenTypeProd]; XCTAssertEqualObjects(token.data, data); + XCTAssertEqualObjects(token.string, @"61736466"); // hex string representation of "asdf" XCTAssertEqual(token.type, FIRAuthAPNSTokenTypeProd); } diff --git a/Example/Auth/Tests/FIRPhoneAuthProviderTests.m b/Example/Auth/Tests/FIRPhoneAuthProviderTests.m index 05f3774..5d67ac8 100644 --- a/Example/Auth/Tests/FIRPhoneAuthProviderTests.m +++ b/Example/Auth/Tests/FIRPhoneAuthProviderTests.m @@ -275,12 +275,25 @@ static const NSTimeInterval kExpectationTimeout = 1; OCMExpect([_mockAppCredentialManager credential]).andReturn(nil); OCMExpect([_mockAPNSTokenManager getTokenWithCallback:OCMOCK_ANY]) .andCallBlock1(^(FIRAuthAPNSTokenCallback callback) { callback(nil); }); + // Expect verify client request to the backend wth empty token. + OCMExpect([_mockBackend verifyClient:[OCMArg any] callback:[OCMArg any]]) + .andCallBlock2(^(FIRVerifyClientRequest *request, + FIRVerifyClientResponseCallback callback) { + XCTAssertNil(request.appToken); + dispatch_async(FIRAuthGlobalWorkQueue(), ^() { + // The backend is supposed to return an error. + callback(nil, [NSError errorWithDomain:FIRAuthErrorDomain + code:FIRAuthErrorCodeMissingAppToken + userInfo:nil]); + }); + }); XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [_provider verifyPhoneNumber:kTestPhoneNumber completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(verificationID); + XCTAssertEqualObjects(error.domain, FIRAuthErrorDomain); XCTAssertEqual(error.code, FIRAuthErrorCodeMissingAppToken); [expectation fulfill]; }]; |