Skip to content

Add an initial version of App Check integration test #1098

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

Merged
merged 17 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions Android/firebase_dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class Dependencies {
def getAnalytics() {
libSet.add('analytics')
}
def getAppCheck() {
libSet.add('app_check')
}
def getAuth() {
libSet.add('auth')
}
Expand Down
8 changes: 8 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,13 @@ if (IOS)
${analytics_generated_headers_dir}/event_names.h
${analytics_generated_headers_dir}/parameter_names.h
${analytics_generated_headers_dir}/user_property_names.h)
set(app_check_HDRS
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check.h
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check/app_attest_provider.h
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check/debug_provider.h
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check/device_check_provider.h
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check/play_integrity_provider.h
${FIREBASE_SOURCE_DIR}/app_check/src/include/firebase/app_check/safety_net_provider.h)
set(auth_HDRS
${FIREBASE_SOURCE_DIR}/auth/src/include/firebase/auth.h
${FIREBASE_SOURCE_DIR}/auth/src/include/firebase/auth/credential.h
Expand Down Expand Up @@ -565,6 +572,7 @@ if (IOS)
src/include/firebase/internal/platform.h
${admob_HDRS}
${analytics_HDRS}
${app_check_HDRS}
${auth_HDRS}
${database_HDRS}
${dynamic_links_HDRS}
Expand Down
44 changes: 44 additions & 0 deletions app_check/integration_test/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/* 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.
*/
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.firebase.cpp.appcheck.testapp"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28" />
<application android:label="@string/app_name">
<activity android:name="android.app.NativeActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|screenSize">
<meta-data android:name="android.app.lib_name"
android:value="android_integration_test_main" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.google.intent.action.TEST_LOOP"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/javascript"/>
</intent-filter>
</activity>
<meta-data android:name="com.google.test.loops" android:value="1" />
</application>
</manifest>
227 changes: 227 additions & 0 deletions app_check/integration_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
# 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.

# Cmake file for a single C++ integration test build.

cmake_minimum_required(VERSION 2.8)

set(FIREBASE_PYTHON_EXECUTABLE "python" CACHE FILEPATH
"The Python interpreter to use, such as one from a venv")

# User settings for Firebase integration tests.
# Path to Firebase SDK.
# Try to read the path to the Firebase C++ SDK from an environment variable.
if (NOT "$ENV{FIREBASE_CPP_SDK_DIR}" STREQUAL "")
set(DEFAULT_FIREBASE_CPP_SDK_DIR "$ENV{FIREBASE_CPP_SDK_DIR}")
else()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../cpp_sdk_version.json")
set(DEFAULT_FIREBASE_CPP_SDK_DIR "${CMAKE_CURRENT_LIST_DIR}/../..")
else()
set(DEFAULT_FIREBASE_CPP_SDK_DIR "firebase_cpp_sdk")
endif()
endif()
if ("${FIREBASE_CPP_SDK_DIR}" STREQUAL "")
set(FIREBASE_CPP_SDK_DIR ${DEFAULT_FIREBASE_CPP_SDK_DIR})
endif()
if(NOT EXISTS ${FIREBASE_CPP_SDK_DIR})
message(FATAL_ERROR "The Firebase C++ SDK directory does not exist: ${FIREBASE_CPP_SDK_DIR}. See the readme.md for more information")
endif()

# Copy all prerequisite files for integration tests to run.
if(NOT ANDROID)
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../setup_integration_tests.py)
# If this is running from inside the SDK directory, run the setup script.
execute_process(COMMAND ${FIREBASE_PYTHON_EXECUTABLE} "${CMAKE_CURRENT_LIST_DIR}/../../setup_integration_tests.py" "${CMAKE_CURRENT_LIST_DIR}")
endif()
endif()

# Windows runtime mode, either MD or MT depending on whether you are using
# /MD or /MT. For more information see:
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
set(MSVC_RUNTIME_MODE MD)

project(firebase_testapp)

# Integration test source files.
set(FIREBASE_APP_FRAMEWORK_SRCS
src/app_framework.cc
src/app_framework.h
)

set(FIREBASE_TEST_FRAMEWORK_SRCS
src/firebase_test_framework.h
src/firebase_test_framework.cc
)

set(FIREBASE_INTEGRATION_TEST_SRCS
src/integration_test.cc
)

# The include directory for the testapp.
include_directories(src)

# Integration test uses some features that require C++ 11, such as lambdas.
set (CMAKE_CXX_STANDARD 11)

# Download and unpack googletest (and googlemock) at configure time
set(GOOGLETEST_ROOT ${CMAKE_CURRENT_LIST_DIR}/external/googletest)
# Note: Once googletest is downloaded once, it won't be updated or
# downloaded again unless you delete the "external/googletest"
# directory.
if (NOT EXISTS ${GOOGLETEST_ROOT}/src/googletest/src/gtest-all.cc)
configure_file(googletest.cmake
${CMAKE_CURRENT_LIST_DIR}/external/googletest/CMakeLists.txt COPYONLY)
execute_process(COMMAND ${CMAKE_COMMAND} .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external/googletest )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external/googletest )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
endif()

if(ANDROID)
# Build an Android application.

# Source files used for the Android build.
set(FIREBASE_APP_FRAMEWORK_ANDROID_SRCS
src/android/android_app_framework.cc
)

# Source files used for the Android build.
set(FIREBASE_TEST_FRAMEWORK_ANDROID_SRCS
src/android/android_firebase_test_framework.cc
)

# Build native_app_glue as a static lib
add_library(native_app_glue STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

# Export ANativeActivity_onCreate(),
# Refer to: https://github.com/android-ndk/ndk/issues/381.
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")

add_library(gtest STATIC
${GOOGLETEST_ROOT}/src/googletest/src/gtest-all.cc)
target_include_directories(gtest
PRIVATE ${GOOGLETEST_ROOT}/src/googletest
PUBLIC ${GOOGLETEST_ROOT}/src/googletest/include)
add_library(gmock STATIC
${GOOGLETEST_ROOT}/src/googlemock/src/gmock-all.cc)
target_include_directories(gmock
PRIVATE ${GOOGLETEST_ROOT}/src/googletest
PRIVATE ${GOOGLETEST_ROOT}/src/googlemock
PUBLIC ${GOOGLETEST_ROOT}/src/googletest/include
PUBLIC ${GOOGLETEST_ROOT}/src/googlemock/include)

# Define the target as a shared library, as that is what gradle expects.
set(integration_test_target_name "android_integration_test_main")
add_library(${integration_test_target_name} SHARED
${FIREBASE_APP_FRAMEWORK_SRCS}
${FIREBASE_APP_FRAMEWORK_ANDROID_SRCS}
${FIREBASE_INTEGRATION_TEST_SRCS}
${FIREBASE_TEST_FRAMEWORK_SRCS}
${FIREBASE_TEST_FRAMEWORK_ANDROID_SRCS}
)

target_include_directories(${integration_test_target_name} PRIVATE
${ANDROID_NDK}/sources/android/native_app_glue)

set(ADDITIONAL_LIBS log android atomic native_app_glue)
else()
# Build a desktop application.
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/external/googletest/src
${CMAKE_CURRENT_LIST_DIR}/external/googletest/build
EXCLUDE_FROM_ALL)

# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
include_directories("${gmock_SOURCE_DIR}/include")
endif()

# Windows runtime mode, either MD or MT depending on whether you are using
# /MD or /MT. For more information see:
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
set(MSVC_RUNTIME_MODE MD)

# Platform abstraction layer for the desktop integration test.
set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS
src/desktop/desktop_app_framework.cc
)

set(integration_test_target_name "integration_test")
add_executable(${integration_test_target_name}
${FIREBASE_APP_FRAMEWORK_SRCS}
${FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS}
${FIREBASE_TEST_FRAMEWORK_SRCS}
${FIREBASE_INTEGRATION_TEST_SRCS}
)

if(APPLE)
set(ADDITIONAL_LIBS
gssapi_krb5
pthread
"-framework CoreFoundation"
"-framework Foundation"
"-framework GSS"
"-framework Security"
)
elseif(MSVC)
set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32 iphlpapi psapi userenv shell32)
else()
set(ADDITIONAL_LIBS pthread)
endif()

# If a config file is present, copy it into the binary location so that it's
# possible to create the default Firebase app.
set(FOUND_JSON_FILE FALSE)
foreach(config "google-services-desktop.json" "google-services.json")
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/${config}")
add_custom_command(
TARGET ${integration_test_target_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_LIST_DIR}/${config}" $<TARGET_FILE_DIR:${integration_test_target_name}>)
set(FOUND_JSON_FILE TRUE)
break()
endif()
endforeach()
if(NOT FOUND_JSON_FILE)
message(WARNING "Failed to find either google-services-desktop.json or google-services.json. See the readme.md for more information.")
endif()
endif()

# Add the Firebase libraries to the target using the function from the SDK.
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
# Note that firebase_app needs to be last in the list.
set(firebase_libs firebase_app_check firebase_database firebase_auth firebase_app)
set(gtest_libs gtest gmock)
target_link_libraries(${integration_test_target_name} ${firebase_libs}
${gtest_libs} ${ADDITIONAL_LIBS})
Loading