Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Integration Test for Phone Number Authentication in Firebase #13538

Open
wants to merge 21 commits into
base: rce-phone-tests
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
8848765129D314A400780FA6 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 8848764F29D3149200780FA6 /* GoogleService-Info.plist */; };
B8F672CF2C805B5300DFDFD4 /* PhoneAuthTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8F672CE2C805B5200DFDFD4 /* PhoneAuthTest.swift */; };
pragatimodi marked this conversation as resolved.
Show resolved Hide resolved
B8F672D72C806E6A00DFDFD4 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B8F672D62C806E6A00DFDFD4 /* GoogleService-Info.plist */; };
srushtisv marked this conversation as resolved.
Show resolved Hide resolved
DE8B636F2BEC2DC300607B82 /* FirebaseAuth in Frameworks */ = {isa = PBXBuildFile; productRef = DE8B636E2BEC2DC300607B82 /* FirebaseAuth */; };
DE8B63722BEC2FB900607B82 /* GoogleSignIn in Frameworks */ = {isa = PBXBuildFile; productRef = DE8B63712BEC2FB900607B82 /* GoogleSignIn */; };
DE8B63742BEC2FB900607B82 /* GoogleSignInSwift in Frameworks */ = {isa = PBXBuildFile; productRef = DE8B63732BEC2FB900607B82 /* GoogleSignInSwift */; };
Expand All @@ -31,9 +32,8 @@
DE8FD4942A7D9E2700B6831A /* PhoneMultiFactorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE8FD4912A7D9D9E00B6831A /* PhoneMultiFactorTests.swift */; };
DEC2E5DD2A95331E0090260A /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2E5DC2A95331D0090260A /* SettingsViewController.swift */; };
DEC2E5DF2A9583CA0090260A /* AppManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2E5DE2A9583CA0090260A /* AppManager.swift */; };
DEC2E5E42A966DE20090260A /* GoogleService-Info_multi.plist in Resources */ = {isa = PBXBuildFile; fileRef = DEC2E5E32A966DE20090260A /* GoogleService-Info_multi.plist */; };
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
DED37F632AB0C4F7003A67E4 /* SettingsUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED37F622AB0C4F7003A67E4 /* SettingsUITests.swift */; };
DEE261C52C21E9F500EECAC5 /* RecaptchaEnterprise in Frameworks */ = {isa = PBXBuildFile; productRef = DEE261C42C21E9F500EECAC5 /* RecaptchaEnterprise */; };
DEE261C52C21E9F500EECAC5 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
srushtisv marked this conversation as resolved.
Show resolved Hide resolved
EA02F68524A000E00079D000 /* UserActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA02F68424A000E00079D000 /* UserActions.swift */; };
EA02F68D24A063E90079D000 /* LoginDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA02F68C24A063E90079D000 /* LoginDelegate.swift */; };
EA062D5D24A0FEB6006714D3 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = EA062D5C24A0FEB6006714D3 /* README.md */; };
Expand Down Expand Up @@ -87,7 +87,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
8848764F29D3149200780FA6 /* GoogleService-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "GoogleService-Info.plist"; sourceTree = SOURCE_ROOT; };
B8F672CE2C805B5200DFDFD4 /* PhoneAuthTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhoneAuthTest.swift; sourceTree = "<group>"; };
B8F672D62C806E6A00DFDFD4 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
srushtisv marked this conversation as resolved.
Show resolved Hide resolved
DE4D8E1F2A8B0311001952B6 /* SwiftApplication.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = SwiftApplication.plist; sourceTree = "<group>"; };
DE8FD4682A7D660A00B6831A /* Credentials.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Credentials.swift; sourceTree = "<group>"; };
DE8FD4692A7D660A00B6831A /* AccountInfoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountInfoTests.swift; sourceTree = "<group>"; };
Expand All @@ -109,7 +110,6 @@
DE8FD4972A7DB00600B6831A /* AuthCredentials.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AuthCredentials.h; sourceTree = "<group>"; };
DEC2E5DC2A95331D0090260A /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
DEC2E5DE2A9583CA0090260A /* AppManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppManager.swift; sourceTree = "<group>"; };
DEC2E5E32A966DE20090260A /* GoogleService-Info_multi.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "GoogleService-Info_multi.plist"; sourceTree = SOURCE_ROOT; };
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
DED37F622AB0C4F7003A67E4 /* SettingsUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsUITests.swift; sourceTree = "<group>"; };
EA02F68424A000E00079D000 /* UserActions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserActions.swift; sourceTree = "<group>"; };
EA02F68C24A063E90079D000 /* LoginDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -157,7 +157,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
DEE261C52C21E9F500EECAC5 /* RecaptchaEnterprise in Frameworks */,
DEE261C52C21E9F500EECAC5 /* (null) in Frameworks */,
srushtisv marked this conversation as resolved.
Show resolved Hide resolved
DE8B63772BEC302200607B82 /* FacebookLogin in Frameworks */,
DE8B63742BEC2FB900607B82 /* GoogleSignInSwift in Frameworks */,
DE8B636F2BEC2DC300607B82 /* FirebaseAuth in Frameworks */,
Expand Down Expand Up @@ -305,7 +305,7 @@
EAE4CBC324855E3A00245E92 /* AuthenticationExample */ = {
isa = PBXGroup;
children = (
DEC2E5E32A966DE20090260A /* GoogleService-Info_multi.plist */,
B8F672D62C806E6A00DFDFD4 /* GoogleService-Info.plist */,
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
DE4D8E1F2A8B0311001952B6 /* SwiftApplication.plist */,
EA062D5C24A0FEB6006714D3 /* README.md */,
EA20B506249CA63300B5E581 /* AuthenticationExample.entitlements */,
Expand All @@ -316,7 +316,6 @@
EA20B47724973BB100B5E581 /* CustomViews */,
EAB3A17A2494626F00385291 /* Utility */,
EAE4CBCD24855E3D00245E92 /* Assets.xcassets */,
8848764F29D3149200780FA6 /* GoogleService-Info.plist */,
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
EA217894248979E200736757 /* LaunchScreen.storyboard */,
DEC2E5DE2A9583CA0090260A /* AppManager.swift */,
);
Expand All @@ -326,6 +325,7 @@
EAE4CBDA24855E3E00245E92 /* SwiftApiTests */ = {
isa = PBXGroup;
children = (
B8F672CE2C805B5200DFDFD4 /* PhoneAuthTest.swift */,
DE8FD4912A7D9D9E00B6831A /* PhoneMultiFactorTests.swift */,
DE8FD4692A7D660A00B6831A /* AccountInfoTests.swift */,
DE8FD46E2A7D660B00B6831A /* AnonymousTests.swift */,
Expand Down Expand Up @@ -390,7 +390,6 @@
DE8B63712BEC2FB900607B82 /* GoogleSignIn */,
DE8B63732BEC2FB900607B82 /* GoogleSignInSwift */,
DE8B63762BEC302200607B82 /* FacebookLogin */,
DEE261C42C21E9F500EECAC5 /* RecaptchaEnterprise */,
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
);
productName = "Swifty Auth";
productReference = EAE4CBC124855E3A00245E92 /* AuthenticationExample.app */;
Expand Down Expand Up @@ -504,8 +503,7 @@
buildActionMask = 2147483647;
files = (
EA217895248979E200736757 /* LaunchScreen.storyboard in Resources */,
8848765129D314A400780FA6 /* GoogleService-Info.plist in Resources */,
DEC2E5E42A966DE20090260A /* GoogleService-Info_multi.plist in Resources */,
B8F672D72C806E6A00DFDFD4 /* GoogleService-Info.plist in Resources */,
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
EAE4CBCE24855E3D00245E92 /* Assets.xcassets in Resources */,
EA062D5D24A0FEB6006714D3 /* README.md in Resources */,
);
Expand Down Expand Up @@ -584,6 +582,7 @@
DE8FD4702A7D660B00B6831A /* AccountInfoTests.swift in Sources */,
DE8FD4942A7D9E2700B6831A /* PhoneMultiFactorTests.swift in Sources */,
DE8FD4742A7D660B00B6831A /* TestsBase.swift in Sources */,
B8F672CF2C805B5300DFDFD4 /* PhoneAuthTest.swift in Sources */,
DE8FD4712A7D660B00B6831A /* FacebookTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -788,6 +787,7 @@
"CODE_SIGN_IDENTITY[sdk=*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = EQHXZ8M8AV;
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
INFOPLIST_FILE = AuthenticationExample/SwiftApplication.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -797,6 +797,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.google.FirebaseExperimental1;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "FirebaseAuthSDKSampleApp Dev";
ncooke3 marked this conversation as resolved.
Show resolved Hide resolved
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
};
Expand Down
63 changes: 63 additions & 0 deletions FirebaseAuth/Tests/SampleSwift/SwiftApiTests/PhoneAuthTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2024 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 FirebaseAuth
import Foundation
import XCTest

class PhoneAuthTests: TestsBase {
let phoneNumber = "+12345678910"
// This test verification code is specified for the given test phone number in the developer
// console.
let verificationCode = "123456"

func testSignInWithPhoneNumber() throws {
Auth.auth().settings?.isAppVerificationDisabledForTesting = true
let auth = Auth.auth()
let expectation = self.expectation(description: "Sign in with phone number")

// PhoneAuthProvider used to initiate the Verification process and obtain a verificationID.
PhoneAuthProvider.provider()
.verifyPhoneNumber(phoneNumber, uiDelegate: nil) { verificationID, error in
if let error {
XCTAssertNil(error, "Verification error should be nil")
XCTAssertNotNil(verificationID, "Verification ID should not be nil")
}

// Create a credential using the test verification code.
let credential = PhoneAuthProvider.provider().credential(
withVerificationID: verificationID ?? "",
verificationCode: self.verificationCode
)
// Signs in using the credential and verifies that the user is signed in correctly by
// checking auth.currentUser.
auth.signIn(with: credential) { authResult, error in
if let error {
XCTAssertNil(error, "Sign in error should be nil")
XCTAssertNotNil(authResult, "AuthResult should not be nil")
XCTAssertEqual(
auth.currentUser?.phoneNumber,
self.phoneNumber,
"Phone number does not match"
)
}
expectation.fulfill()
}
}

waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
}
}
Loading