Skip to content

Commit 07c75bc

Browse files
authored
Add an initial version of App Check integration test (#1098)
* Initial App Check integration test * Fix errors about the providers * Disable database tests for now * Add App Check to the testapp config * Add service files for App Check * Update the service files * Update service files * Update service files * Add app check to the ios build config * Add app check headers to iOS framework * Disable the tests in a better way * Update App Check with new iOS versions
1 parent 3213f0e commit 07c75bc

File tree

31 files changed

+2230
-2
lines changed

31 files changed

+2230
-2
lines changed

Android/firebase_dependencies.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class Dependencies {
7777
def getAnalytics() {
7878
libSet.add('analytics')
7979
}
80+
def getAppCheck() {
81+
libSet.add('app_check')
82+
}
8083
def getAuth() {
8184
libSet.add('auth')
8285
}

app/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,13 @@ if (IOS)
493493
${analytics_generated_headers_dir}/event_names.h
494494
${analytics_generated_headers_dir}/parameter_names.h
495495
${analytics_generated_headers_dir}/user_property_names.h)
496+
set(app_check_HDRS
497+
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check.h
498+
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check/app_attest_provider.h
499+
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check/debug_provider.h
500+
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check/device_check_provider.h
501+
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check/play_integrity_provider.h
502+
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check/safety_net_provider.h)
496503
set(auth_HDRS
497504
${FIREBASE_SOURCE_DIR}/auth/src/include/firebase/auth.h
498505
${FIREBASE_SOURCE_DIR}/auth/src/include/firebase/auth/credential.h
@@ -565,6 +572,7 @@ if (IOS)
565572
src/include/firebase/internal/platform.h
566573
${admob_HDRS}
567574
${analytics_HDRS}
575+
${app_check_HDRS}
568576
${auth_HDRS}
569577
${database_HDRS}
570578
${dynamic_links_HDRS}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/* Copyright 2022 Google LLC
4+
**
5+
** Licensed under the Apache License, Version 2.0 (the "License");
6+
** you may not use this file except in compliance with the License.
7+
** You may obtain a copy of the License at
8+
**
9+
** http://www.apache.org/licenses/LICENSE-2.0
10+
**
11+
** Unless required by applicable law or agreed to in writing, software
12+
** distributed under the License is distributed on an "AS IS" BASIS,
13+
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
** See the License for the specific language governing permissions and
15+
** limitations under the License.
16+
*/
17+
-->
18+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
19+
package="com.google.firebase.cpp.appcheck.testapp"
20+
android:versionCode="1"
21+
android:versionName="1.0">
22+
<uses-permission android:name="android.permission.INTERNET" />
23+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
24+
<uses-permission android:name="android.permission.WAKE_LOCK" />
25+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28" />
26+
<application android:label="@string/app_name">
27+
<activity android:name="android.app.NativeActivity"
28+
android:screenOrientation="portrait"
29+
android:configChanges="orientation|screenSize">
30+
<meta-data android:name="android.app.lib_name"
31+
android:value="android_integration_test_main" />
32+
<intent-filter>
33+
<action android:name="android.intent.action.MAIN" />
34+
<category android:name="android.intent.category.LAUNCHER" />
35+
</intent-filter>
36+
<intent-filter>
37+
<action android:name="com.google.intent.action.TEST_LOOP"/>
38+
<category android:name="android.intent.category.DEFAULT"/>
39+
<data android:mimeType="application/javascript"/>
40+
</intent-filter>
41+
</activity>
42+
<meta-data android:name="com.google.test.loops" android:value="1" />
43+
</application>
44+
</manifest>
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Cmake file for a single C++ integration test build.
16+
17+
cmake_minimum_required(VERSION 2.8)
18+
19+
set(FIREBASE_PYTHON_EXECUTABLE "python" CACHE FILEPATH
20+
"The Python interpreter to use, such as one from a venv")
21+
22+
# User settings for Firebase integration tests.
23+
# Path to Firebase SDK.
24+
# Try to read the path to the Firebase C++ SDK from an environment variable.
25+
if (NOT "$ENV{FIREBASE_CPP_SDK_DIR}" STREQUAL "")
26+
set(DEFAULT_FIREBASE_CPP_SDK_DIR "$ENV{FIREBASE_CPP_SDK_DIR}")
27+
else()
28+
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../cpp_sdk_version.json")
29+
set(DEFAULT_FIREBASE_CPP_SDK_DIR "${CMAKE_CURRENT_LIST_DIR}/../..")
30+
else()
31+
set(DEFAULT_FIREBASE_CPP_SDK_DIR "firebase_cpp_sdk")
32+
endif()
33+
endif()
34+
if ("${FIREBASE_CPP_SDK_DIR}" STREQUAL "")
35+
set(FIREBASE_CPP_SDK_DIR ${DEFAULT_FIREBASE_CPP_SDK_DIR})
36+
endif()
37+
if(NOT EXISTS ${FIREBASE_CPP_SDK_DIR})
38+
message(FATAL_ERROR "The Firebase C++ SDK directory does not exist: ${FIREBASE_CPP_SDK_DIR}. See the readme.md for more information")
39+
endif()
40+
41+
# Copy all prerequisite files for integration tests to run.
42+
if(NOT ANDROID)
43+
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../setup_integration_tests.py)
44+
# If this is running from inside the SDK directory, run the setup script.
45+
execute_process(COMMAND ${FIREBASE_PYTHON_EXECUTABLE} "${CMAKE_CURRENT_LIST_DIR}/../../setup_integration_tests.py" "${CMAKE_CURRENT_LIST_DIR}")
46+
endif()
47+
endif()
48+
49+
# Windows runtime mode, either MD or MT depending on whether you are using
50+
# /MD or /MT. For more information see:
51+
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
52+
set(MSVC_RUNTIME_MODE MD)
53+
54+
project(firebase_testapp)
55+
56+
# Integration test source files.
57+
set(FIREBASE_APP_FRAMEWORK_SRCS
58+
src/app_framework.cc
59+
src/app_framework.h
60+
)
61+
62+
set(FIREBASE_TEST_FRAMEWORK_SRCS
63+
src/firebase_test_framework.h
64+
src/firebase_test_framework.cc
65+
)
66+
67+
set(FIREBASE_INTEGRATION_TEST_SRCS
68+
src/integration_test.cc
69+
)
70+
71+
# The include directory for the testapp.
72+
include_directories(src)
73+
74+
# Integration test uses some features that require C++ 11, such as lambdas.
75+
set (CMAKE_CXX_STANDARD 11)
76+
77+
# Download and unpack googletest (and googlemock) at configure time
78+
set(GOOGLETEST_ROOT ${CMAKE_CURRENT_LIST_DIR}/external/googletest)
79+
# Note: Once googletest is downloaded once, it won't be updated or
80+
# downloaded again unless you delete the "external/googletest"
81+
# directory.
82+
if (NOT EXISTS ${GOOGLETEST_ROOT}/src/googletest/src/gtest-all.cc)
83+
configure_file(googletest.cmake
84+
${CMAKE_CURRENT_LIST_DIR}/external/googletest/CMakeLists.txt COPYONLY)
85+
execute_process(COMMAND ${CMAKE_COMMAND} .
86+
RESULT_VARIABLE result
87+
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external/googletest )
88+
if(result)
89+
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
90+
endif()
91+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
92+
RESULT_VARIABLE result
93+
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external/googletest )
94+
if(result)
95+
message(FATAL_ERROR "Build step for googletest failed: ${result}")
96+
endif()
97+
endif()
98+
99+
if(ANDROID)
100+
# Build an Android application.
101+
102+
# Source files used for the Android build.
103+
set(FIREBASE_APP_FRAMEWORK_ANDROID_SRCS
104+
src/android/android_app_framework.cc
105+
)
106+
107+
# Source files used for the Android build.
108+
set(FIREBASE_TEST_FRAMEWORK_ANDROID_SRCS
109+
src/android/android_firebase_test_framework.cc
110+
)
111+
112+
# Build native_app_glue as a static lib
113+
add_library(native_app_glue STATIC
114+
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
115+
116+
# Export ANativeActivity_onCreate(),
117+
# Refer to: https://github.com/android-ndk/ndk/issues/381.
118+
set(CMAKE_SHARED_LINKER_FLAGS
119+
"${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
120+
121+
add_library(gtest STATIC
122+
${GOOGLETEST_ROOT}/src/googletest/src/gtest-all.cc)
123+
target_include_directories(gtest
124+
PRIVATE ${GOOGLETEST_ROOT}/src/googletest
125+
PUBLIC ${GOOGLETEST_ROOT}/src/googletest/include)
126+
add_library(gmock STATIC
127+
${GOOGLETEST_ROOT}/src/googlemock/src/gmock-all.cc)
128+
target_include_directories(gmock
129+
PRIVATE ${GOOGLETEST_ROOT}/src/googletest
130+
PRIVATE ${GOOGLETEST_ROOT}/src/googlemock
131+
PUBLIC ${GOOGLETEST_ROOT}/src/googletest/include
132+
PUBLIC ${GOOGLETEST_ROOT}/src/googlemock/include)
133+
134+
# Define the target as a shared library, as that is what gradle expects.
135+
set(integration_test_target_name "android_integration_test_main")
136+
add_library(${integration_test_target_name} SHARED
137+
${FIREBASE_APP_FRAMEWORK_SRCS}
138+
${FIREBASE_APP_FRAMEWORK_ANDROID_SRCS}
139+
${FIREBASE_INTEGRATION_TEST_SRCS}
140+
${FIREBASE_TEST_FRAMEWORK_SRCS}
141+
${FIREBASE_TEST_FRAMEWORK_ANDROID_SRCS}
142+
)
143+
144+
target_include_directories(${integration_test_target_name} PRIVATE
145+
${ANDROID_NDK}/sources/android/native_app_glue)
146+
147+
set(ADDITIONAL_LIBS log android atomic native_app_glue)
148+
else()
149+
# Build a desktop application.
150+
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
151+
152+
# Prevent overriding the parent project's compiler/linker
153+
# settings on Windows
154+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
155+
156+
# Add googletest directly to our build. This defines
157+
# the gtest and gtest_main targets.
158+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/external/googletest/src
159+
${CMAKE_CURRENT_LIST_DIR}/external/googletest/build
160+
EXCLUDE_FROM_ALL)
161+
162+
# The gtest/gtest_main targets carry header search path
163+
# dependencies automatically when using CMake 2.8.11 or
164+
# later. Otherwise we have to add them here ourselves.
165+
if (CMAKE_VERSION VERSION_LESS 2.8.11)
166+
include_directories("${gtest_SOURCE_DIR}/include")
167+
include_directories("${gmock_SOURCE_DIR}/include")
168+
endif()
169+
170+
# Windows runtime mode, either MD or MT depending on whether you are using
171+
# /MD or /MT. For more information see:
172+
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
173+
set(MSVC_RUNTIME_MODE MD)
174+
175+
# Platform abstraction layer for the desktop integration test.
176+
set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS
177+
src/desktop/desktop_app_framework.cc
178+
)
179+
180+
set(integration_test_target_name "integration_test")
181+
add_executable(${integration_test_target_name}
182+
${FIREBASE_APP_FRAMEWORK_SRCS}
183+
${FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS}
184+
${FIREBASE_TEST_FRAMEWORK_SRCS}
185+
${FIREBASE_INTEGRATION_TEST_SRCS}
186+
)
187+
188+
if(APPLE)
189+
set(ADDITIONAL_LIBS
190+
gssapi_krb5
191+
pthread
192+
"-framework CoreFoundation"
193+
"-framework Foundation"
194+
"-framework GSS"
195+
"-framework Security"
196+
)
197+
elseif(MSVC)
198+
set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32 iphlpapi psapi userenv shell32)
199+
else()
200+
set(ADDITIONAL_LIBS pthread)
201+
endif()
202+
203+
# If a config file is present, copy it into the binary location so that it's
204+
# possible to create the default Firebase app.
205+
set(FOUND_JSON_FILE FALSE)
206+
foreach(config "google-services-desktop.json" "google-services.json")
207+
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/${config}")
208+
add_custom_command(
209+
TARGET ${integration_test_target_name} POST_BUILD
210+
COMMAND ${CMAKE_COMMAND} -E copy
211+
"${CMAKE_CURRENT_LIST_DIR}/${config}" $<TARGET_FILE_DIR:${integration_test_target_name}>)
212+
set(FOUND_JSON_FILE TRUE)
213+
break()
214+
endif()
215+
endforeach()
216+
if(NOT FOUND_JSON_FILE)
217+
message(WARNING "Failed to find either google-services-desktop.json or google-services.json. See the readme.md for more information.")
218+
endif()
219+
endif()
220+
221+
# Add the Firebase libraries to the target using the function from the SDK.
222+
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
223+
# Note that firebase_app needs to be last in the list.
224+
set(firebase_libs firebase_app_check firebase_database firebase_auth firebase_app)
225+
set(gtest_libs gtest gmock)
226+
target_link_libraries(${integration_test_target_name} ${firebase_libs}
227+
${gtest_libs} ${ADDITIONAL_LIBS})

0 commit comments

Comments
 (0)