From 121ed4d4b7c6c6f3eb60ef3b27721781fb0aaca3 Mon Sep 17 00:00:00 2001 From: Tomas Kypta Date: Wed, 20 Dec 2023 11:12:38 +0100 Subject: [PATCH 1/9] Refactor build scripts to Gradle Kotlin DSL --- build.gradle | 55 ------------- build.gradle.kts | 35 +++++++++ buildSrc/.gitignore | 1 + buildSrc/build.gradle.kts | 32 ++++++++ buildSrc/gradle.properties | 20 +++++ buildSrc/src/main/kotlin/Constants.kt | 41 ++++++++++ library/build.gradle | 98 ----------------------- library/build.gradle.kts | 103 +++++++++++++++++++++++++ settings.gradle => settings.gradle.kts | 13 +++- 9 files changed, 242 insertions(+), 156 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 buildSrc/.gitignore create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/gradle.properties create mode 100644 buildSrc/src/main/kotlin/Constants.kt delete mode 100644 library/build.gradle create mode 100644 library/build.gradle.kts rename settings.gradle => settings.gradle.kts (70%) diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 53a303c..0000000 --- a/build.gradle +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2018 Wultra s.r.o. - * - * 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. - */ - -buildscript { - ext.kotlinVersion = '1.8.20' - ext.dokkaVersion = '1.8.10' - ext.jacocoVersion = "0.8.8" - repositories { - mavenCentral() - google() - } - dependencies { - classpath "com.android.tools.build:gradle:7.4.2" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" - classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion" - // releasing - classpath "org.jacoco:org.jacoco.core:${jacocoVersion}" - } -} - -allprojects { - repositories { - mavenCentral() - google() - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} - -ext { - compileSdkVersion = 33 - targetSdkVersion = 33 - minSdkVersion = 19 - - powerAuthSdkVersion = "1.7.8" - gsonVersion = "2.10.1" - - mockitoVersion = "3.4.6" - powermockVersion = "2.0.7" -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..5f5e83c --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,35 @@ +/* + * Copyright 2018 Wultra s.r.o. + * + * 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. + */ + +buildscript { + repositories { + mavenCentral() + google() + } + dependencies { + classpath("com.android.tools.build:gradle:${Constants.BuildScript.androidPluginVersion}") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Constants.BuildScript.kotlinVersion}") + classpath("org.jetbrains.dokka:dokka-gradle-plugin:${Constants.BuildScript.dokkaVersion}") + classpath("org.jacoco:org.jacoco.core:${Constants.BuildScript.jacocoVersion}") + } +} + +tasks.register("clean", Delete::class) { + delete(rootProject.buildDir) +} + +// a hack to make buildSrc constant available in applied .gradle scripts +project.extra["jacocoVersion"] = Constants.BuildScript.jacocoVersion \ No newline at end of file diff --git a/buildSrc/.gitignore b/buildSrc/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/buildSrc/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..edb8a9b --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,32 @@ +/* + * Copyright 2023 Wultra s.r.o. + * + * 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. + */ + +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() + google() +} + +val androidPluginVersion: String by System.getProperties() +val kotlinVersion: String by System.getProperties() + +dependencies { + implementation("com.android.tools.build", "gradle", androidPluginVersion) + implementation(kotlin("gradle-plugin", kotlinVersion)) +} \ No newline at end of file diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties new file mode 100644 index 0000000..34c578e --- /dev/null +++ b/buildSrc/gradle.properties @@ -0,0 +1,20 @@ +# +# Copyright 2023 Wultra s.r.o. +# +# 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. +# + +systemProp.kotlinVersion=1.8.20 +systemProp.androidPluginVersion=7.4.2 +systemProp.dokkaVersion=1.8.10 +systemProp.jacocoVersion=0.8.11 \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Constants.kt b/buildSrc/src/main/kotlin/Constants.kt new file mode 100644 index 0000000..38884aa --- /dev/null +++ b/buildSrc/src/main/kotlin/Constants.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2023 Wultra s.r.o. + * + * 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 org.gradle.api.JavaVersion + +object Constants { + object BuildScript { + // These have to be defined in buildSrc/gradle.properties + // It's the only way to make them available in buildSrc/build.gradle.kts.kts + val androidPluginVersion: String by System.getProperties() + val kotlinVersion: String by System.getProperties() + val dokkaVersion: String by System.getProperties() + val jacocoVersion: String by System.getProperties() + } + + object Java { + val sourceCompatibility = JavaVersion.VERSION_1_8 + val targetCompatibility = JavaVersion.VERSION_1_8 + const val kotlinJvmTarget = "1.8" + } + + object Android { + const val compileSdkVersion = 33 + const val targetSdkVersion = 33 + const val minSdkVersion = 19 + const val buildToolsVersion = "33.0.2" + } +} diff --git a/library/build.gradle b/library/build.gradle deleted file mode 100644 index b4cc12d..0000000 --- a/library/build.gradle +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2018 Wultra s.r.o. - * - * 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. - */ - -plugins { - id 'com.android.library' - id 'org.jetbrains.kotlin.android' - id 'org.jetbrains.dokka' - id 'maven-publish' - id 'signing' -} - -android { - namespace "com.wultra.android.sslpinning" - testNamespace "com.wultra.android.sslpinning.test" - compileSdkVersion rootProject.ext.compileSdkVersion - - defaultConfig { - minSdkVersion rootProject.ext.minSdkVersion - targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName VERSION_NAME - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments clearPackageData: 'true' - } - - buildTypes { - debug { - testCoverageEnabled true - } - release { - minifyEnabled false - consumerProguardFiles 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - // avoids a gradle warning, otherwise unused due to custom config in android-release-aar.gradle - publishing { - singleVariant('release') { - withSourcesJar() - withJavadocJar() - } - } - - lintOptions { - // to handle warning coming from a transitive dependency - // - obsolete 'androidx.fragment' through 'powerauth-sdk' - disable 'ObsoleteLintCustomCheck' - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - - compileOnly "com.wultra.android.powerauth:powerauth-sdk:${powerAuthSdkVersion}" - - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" - implementation "com.google.code.gson:gson:${gsonVersion}" - implementation "androidx.annotation:annotation:1.7.0" - - testImplementation "com.wultra.android.powerauth:powerauth-sdk:${powerAuthSdkVersion}" - testImplementation 'junit:junit:4.13.2' - testImplementation("io.mockk:mockk:1.13.5") - testImplementation 'org.bouncycastle:bcprov-jdk15on:1.70' - testImplementation "io.getlime.security:powerauth-java-crypto:1.4.0" - -// androidTestImplementation 'androidx.core:core-ktx:+' - androidTestImplementation "androidx.test:runner:1.5.2" - androidTestImplementation "androidx.test:rules:1.5.0" - androidTestImplementation "androidx.test.ext:junit:1.1.5" - androidTestImplementation "com.wultra.android.powerauth:powerauth-sdk:${powerAuthSdkVersion}" - androidTestImplementation 'com.squareup.okhttp3:okhttp:4.10.0' - - constraints { - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion") { - because "Avoids conflicts with 'kotlin-stdlib'" - } - } -} - -apply from: 'android-release-aar.gradle' -apply from: 'android-coverage.gradle' \ No newline at end of file diff --git a/library/build.gradle.kts b/library/build.gradle.kts new file mode 100644 index 0000000..9fb4717 --- /dev/null +++ b/library/build.gradle.kts @@ -0,0 +1,103 @@ +/* + * Copyright 2018 Wultra s.r.o. + * + * 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. + */ + +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.android") + id("org.jetbrains.dokka") + id("maven-publish") + id("signing") +} + +android { + namespace = "com.wultra.android.sslpinning" + testNamespace = "com.wultra.android.sslpinning.test" + compileSdk = Constants.Android.compileSdkVersion + + defaultConfig { + minSdk = Constants.Android.minSdkVersion + @Suppress("DEPRECATION") + targetSdk = Constants.Android.targetSdkVersion + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunnerArguments["clearPackageData"] = "true" + } + + buildTypes { + debug { + enableUnitTestCoverage = true + enableAndroidTestCoverage = true + } + release { + isMinifyEnabled = false + consumerProguardFiles("proguard-rules.pro") + } + } + + compileOptions { + sourceCompatibility = Constants.Java.sourceCompatibility + targetCompatibility = Constants.Java.targetCompatibility + } + + kotlinOptions { + jvmTarget = Constants.Java.kotlinJvmTarget + } + + // avoids a gradle warning, otherwise unused due to custom config in android-release-aar.gradle + publishing { + singleVariant("release") { + withSourcesJar() + withJavadocJar() + } + } + + lint { + // to handle warning coming from a transitive dependency + // - obsolete 'androidx.fragment' through 'powerauth-sdk' + disable.add("ObsoleteLintCustomCheck") + } +} + +dependencies { + val powerAuthSdkVersion = "1.7.8" + + compileOnly("com.wultra.android.powerauth:powerauth-sdk:${powerAuthSdkVersion}") + + implementation("org.jetbrains.kotlin:kotlin-stdlib:${Constants.BuildScript.kotlinVersion}") + implementation("com.google.code.gson:gson:2.10.1") + implementation("androidx.annotation:annotation:1.7.1") + + testImplementation("com.wultra.android.powerauth:powerauth-sdk:${powerAuthSdkVersion}") + testImplementation("junit:junit:4.13.2") + testImplementation("io.mockk:mockk:1.13.5") + testImplementation("org.bouncycastle:bcprov-jdk15on:1.70") + testImplementation("io.getlime.security:powerauth-java-crypto:1.4.0") + + androidTestImplementation("androidx.test:runner:1.5.2") + androidTestImplementation("androidx.test:rules:1.5.0") + androidTestImplementation("androidx.test.ext:junit:1.1.5") + androidTestImplementation("com.wultra.android.powerauth:powerauth-sdk:${powerAuthSdkVersion}") + androidTestImplementation("com.squareup.okhttp3:okhttp:4.10.0") + + constraints { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${Constants.BuildScript.kotlinVersion}") { + because("Avoids conflicts with 'kotlin-stdlib'") + } + } +} + +apply("android-release-aar.gradle") +apply("android-coverage.gradle") \ No newline at end of file diff --git a/settings.gradle b/settings.gradle.kts similarity index 70% rename from settings.gradle rename to settings.gradle.kts index 2357313..068409d 100644 --- a/settings.gradle +++ b/settings.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2018 Wultra s.r.o. + * Copyright 2023 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,5 +13,12 @@ * See the License for the specific language governing permissions * and limitations under the License. */ - -include ':library' +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + mavenCentral() + mavenLocal() + google() + } +} +include(":library") From 67bc6806d94658021540efcc0356f5ce764d3964 Mon Sep 17 00:00:00 2001 From: Tomas Kypta Date: Wed, 20 Dec 2023 11:17:19 +0100 Subject: [PATCH 2/9] Remove useless script for generating coverage reports --- library/android-coverage.gradle | 76 --------------------------------- library/build.gradle.kts | 3 +- 2 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 library/android-coverage.gradle diff --git a/library/android-coverage.gradle b/library/android-coverage.gradle deleted file mode 100644 index 7d9927d..0000000 --- a/library/android-coverage.gradle +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2018 Wultra s.r.o. - * - * 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. - */ -apply plugin: 'jacoco' - - -jacoco { - toolVersion = rootProject.ext.jacocoVersion -} - -/** - * Create coverage report for unit tests ('src/test' source set). - */ -task unitTestCoverageReport(type: JacocoReport, - group: 'verification', - description: 'Creates unit test coverage report (for tests under \'test\' source set).', - dependsOn: ['testDebugUnitTest']) { - - reports { - html.required = true - } - - doFirst { - def mainSrc = "${project.projectDir}/src/main/java" - def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*'] - def debugKotlinTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter) - def debugJavaTree = fileTree(dir: "$project.buildDir/intermediates/javac/debug", excludes: fileFilter) - - sourceDirectories = files([mainSrc]) - classDirectories = files([debugKotlinTree, debugJavaTree]) - executionData = fileTree(dir: "$buildDir", includes: [ - "jacoco/testDebugUnitTest.exec" - ]) - } -} - -/** - * Create unified coverage report for unit tests and instrumented tests ('src/test' and 'src/androidTest' source sets). - */ -task unifiedCoverageReport(type: JacocoReport, - group: 'verification', - description: 'Creates unified test coverage report for unit tests (under \'test\' source set)' + - ' and instrumentation tests (under \'androidTest\' source set).', - dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport', 'unitTestCoverageReport']) { - - reports { - html.required = true - } - - doFirst { - def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*'] - def debugKotlinTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter) - def debugJavaTree = fileTree(dir: "$project.buildDir/intermediates/javac/debug", excludes: fileFilter) - def mainSrc = "${project.projectDir}/src/main/java" - - sourceDirectories = files([mainSrc]) - classDirectories = files([debugKotlinTree, debugJavaTree]) - executionData = fileTree(dir: "$buildDir", includes: [ - "jacoco/testDebugUnitTest.exec", - "intermediates/jacoco_coverage_dir/debugAndroidTest/connectedDebugAndroidTest/code-coverage/*coverage.ec" - ]) - } -} - diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 9fb4717..0652bb8 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -99,5 +99,4 @@ dependencies { } } -apply("android-release-aar.gradle") -apply("android-coverage.gradle") \ No newline at end of file +apply("android-release-aar.gradle") \ No newline at end of file From 476ef4d36ae5e1878df210581ce7d475e5c3f863 Mon Sep 17 00:00:00 2001 From: Tomas Kypta Date: Wed, 20 Dec 2023 11:23:29 +0100 Subject: [PATCH 3/9] Move common dependency to Constants --- buildSrc/src/main/kotlin/Constants.kt | 5 +++++ library/build.gradle.kts | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/kotlin/Constants.kt b/buildSrc/src/main/kotlin/Constants.kt index 38884aa..931628e 100644 --- a/buildSrc/src/main/kotlin/Constants.kt +++ b/buildSrc/src/main/kotlin/Constants.kt @@ -38,4 +38,9 @@ object Constants { const val minSdkVersion = 19 const val buildToolsVersion = "33.0.2" } + + + object Dependencies { + const val powerAuthSdkVersion = "1.7.8" + } } diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 0652bb8..9ee730c 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -72,15 +72,13 @@ android { } dependencies { - val powerAuthSdkVersion = "1.7.8" - - compileOnly("com.wultra.android.powerauth:powerauth-sdk:${powerAuthSdkVersion}") + compileOnly("com.wultra.android.powerauth:powerauth-sdk:${Constants.Dependencies.powerAuthSdkVersion}") implementation("org.jetbrains.kotlin:kotlin-stdlib:${Constants.BuildScript.kotlinVersion}") implementation("com.google.code.gson:gson:2.10.1") implementation("androidx.annotation:annotation:1.7.1") - testImplementation("com.wultra.android.powerauth:powerauth-sdk:${powerAuthSdkVersion}") + testImplementation("com.wultra.android.powerauth:powerauth-sdk:${Constants.Dependencies.powerAuthSdkVersion}") testImplementation("junit:junit:4.13.2") testImplementation("io.mockk:mockk:1.13.5") testImplementation("org.bouncycastle:bcprov-jdk15on:1.70") @@ -89,7 +87,7 @@ dependencies { androidTestImplementation("androidx.test:runner:1.5.2") androidTestImplementation("androidx.test:rules:1.5.0") androidTestImplementation("androidx.test.ext:junit:1.1.5") - androidTestImplementation("com.wultra.android.powerauth:powerauth-sdk:${powerAuthSdkVersion}") + androidTestImplementation("com.wultra.android.powerauth:powerauth-sdk:${Constants.Dependencies.powerAuthSdkVersion}") androidTestImplementation("com.squareup.okhttp3:okhttp:4.10.0") constraints { From 614fdfc9adbaabc0970ea6f1ee59a46012160f4f Mon Sep 17 00:00:00 2001 From: Tomas Kypta Date: Wed, 20 Dec 2023 12:41:35 +0100 Subject: [PATCH 4/9] Add Gradle plugin for providing server configurations to tests --- .github/workflows/build.yml | 5 +- .../sslpinning/WultraSslPinningTestPlugin.kt | 52 +++++++++++++++++++ ....wultra.android.sslpinning.test.properties | 1 + library/build.gradle.kts | 1 + .../sslpinning/CertStoreChallengeTest.kt | 22 ++++++-- .../wultra/android/sslpinning/CommonTest.kt | 2 +- 6 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 buildSrc/src/main/kotlin/com/wultra/gradle/sslpinning/WultraSslPinningTestPlugin.kt create mode 100644 buildSrc/src/main/resources/META-INF/gradle-plugins/com.wultra.android.sslpinning.test.properties diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 630e9b6..88f9a72 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -95,7 +95,10 @@ jobs: uses: reactivecircus/android-emulator-runner@v2 with: api-level: 29 - script: ./gradlew library:connectedAndroidTest + script: > + ./gradlew library:connectedAndroidTest + -Ptest.sslPinning.baseUrl=${{ secrets.SSL_PINNING_TEST_BASE_URL }} + -Ptest.sslPinning.appName=${{ secrets.SSL_PINNING_TEST_APP_NAME }} - name: Upload instrumentation test results artifact if: always() diff --git a/buildSrc/src/main/kotlin/com/wultra/gradle/sslpinning/WultraSslPinningTestPlugin.kt b/buildSrc/src/main/kotlin/com/wultra/gradle/sslpinning/WultraSslPinningTestPlugin.kt new file mode 100644 index 0000000..7b5857f --- /dev/null +++ b/buildSrc/src/main/kotlin/com/wultra/gradle/sslpinning/WultraSslPinningTestPlugin.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2023 Wultra s.r.o. + * + * 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. + */ + +package com.wultra.gradle.sslpinning + +import com.android.build.gradle.BaseExtension +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.getByType + +/** + * Plugin for handling server configurations for instrumentation tests. + */ +class WultraSslPinningTestPlugin : Plugin { + + override fun apply(target: Project) { + target.loadPropertiesFromGradleProps() + target.addInstrumentationArgumentsToDefaultConfig() + } + + private val instrumentationArgumentKeys = setOf("test.sslPinning.baseUrl", "test.sslPinning.appName") + private val instrumentationArguments = mutableMapOf() + + private fun Project.loadPropertiesFromGradleProps() { + for (key in instrumentationArgumentKeys) { + instrumentationArguments[key] = project.properties[key]?.toString() ?: "" + } + } + + private fun Project.addInstrumentationArgumentsToDefaultConfig() { + project.extensions.getByType().let { + it.defaultConfig { + for (entry in instrumentationArguments) { + this.testInstrumentationRunnerArguments[entry.key] = entry.value + } + } + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/com.wultra.android.sslpinning.test.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/com.wultra.android.sslpinning.test.properties new file mode 100644 index 0000000..5cde6a3 --- /dev/null +++ b/buildSrc/src/main/resources/META-INF/gradle-plugins/com.wultra.android.sslpinning.test.properties @@ -0,0 +1 @@ +implementation-class=com.wultra.gradle.sslpinning.WultraSslPinningTestPlugin diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 9ee730c..9684c9e 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -20,6 +20,7 @@ plugins { id("org.jetbrains.dokka") id("maven-publish") id("signing") + id("com.wultra.android.sslpinning.test") } android { diff --git a/library/src/androidTest/java/com/wultra/android/sslpinning/CertStoreChallengeTest.kt b/library/src/androidTest/java/com/wultra/android/sslpinning/CertStoreChallengeTest.kt index 7273b8d..7f67562 100644 --- a/library/src/androidTest/java/com/wultra/android/sslpinning/CertStoreChallengeTest.kt +++ b/library/src/androidTest/java/com/wultra/android/sslpinning/CertStoreChallengeTest.kt @@ -18,7 +18,10 @@ package com.wultra.android.sslpinning import androidx.test.ext.junit.runners.AndroidJUnit4 import android.util.Base64 +import androidx.test.platform.app.InstrumentationRegistry import com.wultra.android.sslpinning.integration.powerauth.powerAuthCertStore +import org.junit.Assume +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import java.net.URL @@ -26,17 +29,28 @@ import java.net.URL @RunWith(AndroidJUnit4::class) class CertStoreChallengeTest: CommonTest() { - private val baseUrl = "https://mobile-utility-server.herokuapp.com/app" - private val appName = "rb-ekonto" + private lateinit var baseUrl: String + private lateinit var appName: String + + @Before + override fun setUp() { + super.setUp() + InstrumentationRegistry.getArguments().getString("test.sslPinning.baseUrl")?.let { + baseUrl = it + } + InstrumentationRegistry.getArguments().getString("test.sslPinning.appName")?.let { + appName = it + } + } @Test fun validateUpdateWithChallenge() { + Assume.assumeTrue(::baseUrl.isInitialized && ::appName.isInitialized) val config = CertStoreConfiguration.Builder(getServiceUrl("/init?appName=$appName"), getPublicKeyFromServer()) .useChallenge(true) .build() val store = CertStore.powerAuthCertStore(config, appContext) - // currently the data are expired, therefore STORE_IS_EMPTY result - updateAndCheck(store, UpdateMode.FORCED, UpdateResult.STORE_IS_EMPTY) + updateAndCheck(store, UpdateMode.FORCED, UpdateResult.OK) } private fun getServiceUrl(relativePath: String): URL { diff --git a/library/src/androidTest/java/com/wultra/android/sslpinning/CommonTest.kt b/library/src/androidTest/java/com/wultra/android/sslpinning/CommonTest.kt index df478f7..76685e0 100644 --- a/library/src/androidTest/java/com/wultra/android/sslpinning/CommonTest.kt +++ b/library/src/androidTest/java/com/wultra/android/sslpinning/CommonTest.kt @@ -30,7 +30,7 @@ abstract class CommonTest { val appContext = InstrumentationRegistry.getInstrumentation().targetContext @Before - fun setUp() { + open fun setUp() { WultraDebug.loggingLevel = WultraDebug.WultraLoggingLevel.DEBUG clearStorage() } From dffce6dad5c22977ffe923d65e81d7c0dbeb0e7e Mon Sep 17 00:00:00 2001 From: Tomas Kypta Date: Wed, 20 Dec 2023 12:59:49 +0100 Subject: [PATCH 5/9] Update build action configuration --- .github/workflows/build.yml | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 88f9a72..95ea85c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,19 +7,17 @@ on: - master - release/* pull_request: - schedule: - - cron: '11 6 3 * *' jobs: buildJob: name: Build - runs-on: macos-latest + runs-on: ubuntu-latest steps: - name: Checkout the repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '11' distribution: 'zulu' @@ -29,14 +27,14 @@ jobs: lintJob: name: Lint - runs-on: macos-latest + runs-on: ubuntu-latest needs: [buildJob] steps: - name: Checkout the repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '11' distribution: 'zulu' @@ -46,7 +44,7 @@ jobs: - name: Upload lint results artifact if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: lint-results-debug path: library/build/reports/lint-results-debug.html @@ -54,14 +52,14 @@ jobs: unitTestJob: name: Unit Test - runs-on: macos-latest + runs-on: ubuntu-latest needs: [buildJob] steps: - name: Checkout the repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '11' distribution: 'zulu' @@ -71,7 +69,7 @@ jobs: - name: Upload unit test results artifact if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: unit-test-results-debug path: library/build/reports/tests/testDebugUnitTest/ @@ -83,10 +81,10 @@ jobs: needs: [buildJob] steps: - name: Checkout the repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '11' distribution: 'zulu' @@ -102,7 +100,7 @@ jobs: - name: Upload instrumentation test results artifact if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: instrumentation-test-results-debug path: library/build/reports/androidTests/connected/ From 69cca1a6e41ca3d9b2a458b0852a538ed24b72ca Mon Sep 17 00:00:00 2001 From: Tomas Kypta Date: Wed, 20 Dec 2023 13:05:12 +0100 Subject: [PATCH 6/9] Add jEnv to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 8fd3302..0b8dc06 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,6 @@ fastlane/Preview.html fastlane/screenshots fastlane/test_output fastlane/readme.md + +# jEnv +.java-version \ No newline at end of file From 136d45f6d6509bef1a4d72583be72a275c250cdd Mon Sep 17 00:00:00 2001 From: Tomas Kypta Date: Wed, 20 Dec 2023 14:18:41 +0100 Subject: [PATCH 7/9] Remove jacoco Gradle plugin --- build.gradle.kts | 6 +----- buildSrc/gradle.properties | 3 +-- buildSrc/src/main/kotlin/Constants.kt | 1 - 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5f5e83c..9c5df9e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,13 +23,9 @@ buildscript { classpath("com.android.tools.build:gradle:${Constants.BuildScript.androidPluginVersion}") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Constants.BuildScript.kotlinVersion}") classpath("org.jetbrains.dokka:dokka-gradle-plugin:${Constants.BuildScript.dokkaVersion}") - classpath("org.jacoco:org.jacoco.core:${Constants.BuildScript.jacocoVersion}") } } tasks.register("clean", Delete::class) { delete(rootProject.buildDir) -} - -// a hack to make buildSrc constant available in applied .gradle scripts -project.extra["jacocoVersion"] = Constants.BuildScript.jacocoVersion \ No newline at end of file +} \ No newline at end of file diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties index 34c578e..f2daf0a 100644 --- a/buildSrc/gradle.properties +++ b/buildSrc/gradle.properties @@ -16,5 +16,4 @@ systemProp.kotlinVersion=1.8.20 systemProp.androidPluginVersion=7.4.2 -systemProp.dokkaVersion=1.8.10 -systemProp.jacocoVersion=0.8.11 \ No newline at end of file +systemProp.dokkaVersion=1.8.10 \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Constants.kt b/buildSrc/src/main/kotlin/Constants.kt index 931628e..90aa7e4 100644 --- a/buildSrc/src/main/kotlin/Constants.kt +++ b/buildSrc/src/main/kotlin/Constants.kt @@ -23,7 +23,6 @@ object Constants { val androidPluginVersion: String by System.getProperties() val kotlinVersion: String by System.getProperties() val dokkaVersion: String by System.getProperties() - val jacocoVersion: String by System.getProperties() } object Java { From 4a58557892e991b32e43c0e96a52641da8dc10cb Mon Sep 17 00:00:00 2001 From: Tomas Kypta Date: Wed, 20 Dec 2023 14:19:18 +0100 Subject: [PATCH 8/9] Improve handling of test arguments --- .../wultra/gradle/sslpinning/WultraSslPinningTestPlugin.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/com/wultra/gradle/sslpinning/WultraSslPinningTestPlugin.kt b/buildSrc/src/main/kotlin/com/wultra/gradle/sslpinning/WultraSslPinningTestPlugin.kt index 7b5857f..3b44ed7 100644 --- a/buildSrc/src/main/kotlin/com/wultra/gradle/sslpinning/WultraSslPinningTestPlugin.kt +++ b/buildSrc/src/main/kotlin/com/wultra/gradle/sslpinning/WultraSslPinningTestPlugin.kt @@ -36,7 +36,9 @@ class WultraSslPinningTestPlugin : Plugin { private fun Project.loadPropertiesFromGradleProps() { for (key in instrumentationArgumentKeys) { - instrumentationArguments[key] = project.properties[key]?.toString() ?: "" + project.properties[key]?.let { + instrumentationArguments[key] = it.toString() + } } } From 75eacefc285d41ddb68d1deec2bb1df9d5c0d7f2 Mon Sep 17 00:00:00 2001 From: Tomas Kypta Date: Thu, 21 Dec 2023 10:23:18 +0100 Subject: [PATCH 9/9] Raise PowerAuth SDK version to 1.8.0 --- buildSrc/src/main/kotlin/Constants.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/Constants.kt b/buildSrc/src/main/kotlin/Constants.kt index 90aa7e4..0b433a5 100644 --- a/buildSrc/src/main/kotlin/Constants.kt +++ b/buildSrc/src/main/kotlin/Constants.kt @@ -38,8 +38,7 @@ object Constants { const val buildToolsVersion = "33.0.2" } - object Dependencies { - const val powerAuthSdkVersion = "1.7.8" + const val powerAuthSdkVersion = "1.8.0" } }