Skip to content

Instantly share code, notes, and snippets.

@rvprasad
Last active March 12, 2018 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvprasad/9ada252e8f044cdc9d7c969a2d4de51a to your computer and use it in GitHub Desktop.
Save rvprasad/9ada252e8f044cdc9d7c969a2d4de51a to your computer and use it in GitHub Desktop.
(Ghera) Automating multi-app functional testing against different versions of Android
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
repositories {
jcenter()
google()
}
apply plugin: 'com.android.application'
android {
dependencies {
androidTestImplementation 'com.android.support:support-annotations:26.0.0'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test:rules:1.0.1'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
}
defaultConfig {
applicationId "edu.ksu.cs.benign"
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
apply from: '../../../../Misc/sdkFlavors.gradle'
}
// Ghera -- https://bitbucket.org/secure-it-i/android-app-vulnerability-benchmarks/
# The AVDs should be named Nexus_5X_API_<api #>, e.g., Nexus_5X_API_23.
#
# Here are resources to help understand various tool features used in this script.
# - https://stuff.mit.edu/afs/sipb/project/android/docs/tools/testing/testing_ui.html
# - https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html
# - https://developer.android.com/studio/test/command-line.html
# - https://developer.android.com/studio/command-line/adb.html
# - https://developer.android.com/studio/run/emulator-commandline.html
execute_gradle () {
pushd $1
./gradlew clean $2
if [ $? -ne 0 ] ; then
exit $?
fi
popd
}
execute_gradle Benign assembleDebug
execute_gradle Malicious assembleDebug
execute_gradle Secure assembleDebug
execute_gradle Testing assembleAndroidTest
wait_for_boot_completion () {
$ANDROID_HOME/platform-tools/adb wait-for-device
while [ "`$ANDROID_HOME/platform-tools/adb shell getprop sys.boot_completed | tr -d '\r' `" != "1" ] ; do
sleep 1
done
}
clean_data() {
# add all data clean up commands here
# e.g., $ANDROID_HOME/platform-tools/adb shell rm -f /sdcard/*
:
}
strict=0
for i in 19 21 22 23 24 25 ; do
echo "Testing against API $i"
$ANDROID_HOME/tools/emulator -avd Nexus_5X_API_$i -wipe-data &
emulator_pid=$!
wait_for_boot_completion
api_version="api$i"
echo "Testing Vulnerable"
clean_data
$ANDROID_HOME/platform-tools/adb install \
Benign/app/build/outputs/apk/$api_version/debug/app-$api_version-debug.apk
$ANDROID_HOME/platform-tools/adb install \
Malicious/app/build/outputs/apk/$api_version/debug/app-$api_version-debug.apk
$ANDROID_HOME/platform-tools/adb install -t \
Testing/benign_app/build/outputs/apk/androidTest/$api_version/debug/benign_app-$api_version-debug-androidTest.apk
$ANDROID_HOME/platform-tools/adb shell am instrument -w \
edu.ksu.cs.benign.test/android.support.test.runner.AndroidJUnitRunner \
> vulnerable-$api_version-test.log
$ANDROID_HOME/platform-tools/adb shell pm uninstall edu.ksu.cs.benign
$ANDROID_HOME/platform-tools/adb shell pm uninstall edu.ksu.cs.malicious
$ANDROID_HOME/platform-tools/adb shell pm uninstall edu.ksu.cs.benign.test
if [ $strict -ne 0 ] ; then
$ANDROID_HOME/platform-tools/adb reboot
wait_for_boot_completion
fi
echo "Testing Secure"
clean_data
$ANDROID_HOME/platform-tools/adb install \
Secure/app/build/outputs/apk/$api_version/debug/app-$api_version-debug.apk
$ANDROID_HOME/platform-tools/adb install \
Malicious/app/build/outputs/apk/$api_version/debug/app-$api_version-debug.apk
$ANDROID_HOME/platform-tools/adb install -t \
Testing/secure_app/build/outputs/apk/androidTest/$api_version/debug/secure_app-$api_version-debug-androidTest.apk
$ANDROID_HOME/platform-tools/adb shell am instrument -w \
edu.ksu.cs.benign.test/android.support.test.runner.AndroidJUnitRunner \
> secure-$api_version-test.log
$ANDROID_HOME/platform-tools/adb shell pm uninstall edu.ksu.cs.benign
$ANDROID_HOME/platform-tools/adb shell pm uninstall edu.ksu.cs.malicious
$ANDROID_HOME/platform-tools/adb shell pm uninstall edu.ksu.cs.benign.test
kill $emulator_pid
wait $emulator_pid
done
#
# Ghera -- https://bitbucket.org/secure-it-i/android-app-vulnerability-benchmarks/
android {
flavorDimensions 'api'
productFlavors {
compileSdkVersion 25
[19, 21, 22, 23, 24, 25].each { i ->
"api$i" {
dimension 'api'
minSdkVersion "$i"
targetSdkVersion "$i"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
}
}
// Ghera -- https://bitbucket.org/secure-it-i/android-app-vulnerability-benchmarks/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment