From c084f9aca71ade6410f02ba9a1b5e9ef074af326 Mon Sep 17 00:00:00 2001 From: Jan Kobersky Date: Tue, 19 Nov 2024 14:13:36 +0100 Subject: [PATCH] Push tests --- .github/workflows/tests.yml | 3 +- .../src/main/kotlin/ProjectConfiguration.kt | 1 + configs/integration-tests.properties | 1 + library/src/androidTest/java/InboxTests.kt | 6 +-- .../src/androidTest/java/IntegrationTests.kt | 48 ++++++++++++++++++- .../java/IntegrationTestsDeprecated.kt | 4 +- .../src/androidTest/java/IntegrationUtils.kt | 12 +++-- 7 files changed, 64 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7a8b20c..0180a2f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,7 +32,8 @@ jobs: ER_URL: ${{ secrets.TESTS_ER_URL }} OP_URL: ${{ secrets.TESTS_OP_URL }} IN_URL: ${{ secrets.TESTS_IN_URL }} - run: echo -e tests.sdk.cloudServerUrl="$CL_URL"\\ntests.sdk.cloudServerLogin="$CL_LGN"\\ntests.sdk.cloudServerPassword="$CL_PWD"\\ntests.sdk.cloudApplicationId="$CL_AID"\\ntests.sdk.enrollmentServerUrl="$ER_URL"\\ntests.sdk.operationsServerUrl="$OP_URL"\\ntests.sdk.inboxServerUrl="$IN_URL"\\ntests.sdk.sdkConfig="$SDK_CONFIG" > configs/integration-tests.properties + PU_URL: ${{ secrets.TESTS_PU_URL }} + run: echo -e tests.sdk.cloudServerUrl="$CL_URL"\\ntests.sdk.cloudServerLogin="$CL_LGN"\\ntests.sdk.cloudServerPassword="$CL_PWD"\\ntests.sdk.cloudApplicationId="$CL_AID"\\ntests.sdk.enrollmentServerUrl="$ER_URL"\\ntests.sdk.operationsServerUrl="$OP_URL"\\ntests.sdk.inboxServerUrl="$IN_URL"\\ntests.sdk.pushServerUrl="$PU_URL"\\ntests.sdk.sdkConfig="$SDK_CONFIG" > configs/integration-tests.properties - name: Enable KVM run: | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules diff --git a/buildSrc/src/main/kotlin/ProjectConfiguration.kt b/buildSrc/src/main/kotlin/ProjectConfiguration.kt index e7b0e4b..8ef09cb 100644 --- a/buildSrc/src/main/kotlin/ProjectConfiguration.kt +++ b/buildSrc/src/main/kotlin/ProjectConfiguration.kt @@ -46,6 +46,7 @@ fun loadInstrumentationTestConfigProperties(project: Project, defaultConfig: Def "tests.sdk.enrollmentServerUrl", "tests.sdk.operationsServerUrl", "tests.sdk.inboxServerUrl", + "tests.sdk.pushServerUrl", "tests.sdk.sdkConfig" ) diff --git a/configs/integration-tests.properties b/configs/integration-tests.properties index 23953bb..d968887 100644 --- a/configs/integration-tests.properties +++ b/configs/integration-tests.properties @@ -11,6 +11,7 @@ tests.sdk.cloudApplicationId=dev tests.sdk.enrollmentServerUrl=http://localhost/enrollment-server tests.sdk.operationsServerUrl=http://localhost/enrollment-server tests.sdk.inboxServerUrl=http://localhost/enrollment-server +tests.sdk.pushServerUrl=http://localhost/enrollment-server # Configuration of the PowerAuth server tests.sdk.sdkConfig= \ No newline at end of file diff --git a/library/src/androidTest/java/InboxTests.kt b/library/src/androidTest/java/InboxTests.kt index c3e88db..c488441 100644 --- a/library/src/androidTest/java/InboxTests.kt +++ b/library/src/androidTest/java/InboxTests.kt @@ -19,9 +19,9 @@ class InboxTests { fun setup() { try { val result = IntegrationUtils.prepareActivation(pin) - pa = result.first - ops = result.second - inbox = result.third + pa = result.pa + ops = result.ops + inbox = result.inbox } catch (e: Throwable) { fail("Activation preparation failed: $e") } diff --git a/library/src/androidTest/java/IntegrationTests.kt b/library/src/androidTest/java/IntegrationTests.kt index a3515c8..23bd695 100644 --- a/library/src/androidTest/java/IntegrationTests.kt +++ b/library/src/androidTest/java/IntegrationTests.kt @@ -24,6 +24,8 @@ import com.wultra.android.mtokensdk.api.operation.model.UserOperation import com.wultra.android.mtokensdk.api.operation.model.UserOperationStatus import com.wultra.android.mtokensdk.operation.* import com.wultra.android.mtokensdk.operation.RejectionData +import com.wultra.android.mtokensdk.push.IPushService +import com.wultra.android.mtokensdk.push.PushData import com.wultra.android.powerauth.networking.error.ApiError import io.getlime.security.powerauth.sdk.PowerAuthAuthentication import io.getlime.security.powerauth.sdk.PowerAuthSDK @@ -40,6 +42,7 @@ import java.util.concurrent.TimeUnit class IntegrationTests { private lateinit var ops: IOperationsService + private lateinit var push: IPushService private lateinit var pa: PowerAuthSDK private val pin = "1234" @@ -47,8 +50,9 @@ class IntegrationTests { fun setup() { try { val result = IntegrationUtils.prepareActivation(pin) - pa = result.first - ops = result.second + pa = result.pa + ops = result.ops + push = result.push } catch (e: Throwable) { Assert.fail("Activation preparation failed: $e") } @@ -324,4 +328,44 @@ class IntegrationTests { Assert.assertNotNull(opRecord) Assert.assertTrue("${opRecord?.statusReason} should be PREARRANGED_REASON", opRecord?.statusReason == "PREARRANGED_REASON") } + + @Test + fun testRegisterPushLegacyAndroid() { + val future = CompletableFuture() + push.register("testToken") { result -> + result.onSuccess { future.complete(null) } + .onFailure { future.completeExceptionally(it) } + } + Assert.assertNull(future.get(10, TimeUnit.SECONDS)) + } + + @Test + fun testRegisterPushLegacyHuawei() { + val future = CompletableFuture() + push.registerHuawei("testToken") { result -> + result.onSuccess { future.complete(null) } + .onFailure { future.completeExceptionally(it) } + } + Assert.assertNull(future.get(10, TimeUnit.SECONDS)) + } + + @Test + fun testRegisterPushFCM() { + val future = CompletableFuture() + push.register(PushData.fcm("testToken")) { result -> + result.onSuccess { future.complete(null) } + .onFailure { future.completeExceptionally(it) } + } + Assert.assertNull(future.get(10, TimeUnit.SECONDS)) + } + + @Test + fun testRegisterPushHMS() { + val future = CompletableFuture() + push.register(PushData.hms("testToken")) { result -> + result.onSuccess { future.complete(null) } + .onFailure { future.completeExceptionally(it) } + } + Assert.assertNull(future.get(10, TimeUnit.SECONDS)) + } } diff --git a/library/src/androidTest/java/IntegrationTestsDeprecated.kt b/library/src/androidTest/java/IntegrationTestsDeprecated.kt index 37dded2..f3be8e9 100644 --- a/library/src/androidTest/java/IntegrationTestsDeprecated.kt +++ b/library/src/androidTest/java/IntegrationTestsDeprecated.kt @@ -38,8 +38,8 @@ class IntegrationTestsDeprecated { fun setup() { try { val result = IntegrationUtils.prepareActivation(pin) - pa = result.first - ops = result.second + pa = result.pa + ops = result.ops } catch (e: Throwable) { Assert.fail("Activation preparation failed: $e") } diff --git a/library/src/androidTest/java/IntegrationUtils.kt b/library/src/androidTest/java/IntegrationUtils.kt index 75997f5..d4b0cc0 100644 --- a/library/src/androidTest/java/IntegrationUtils.kt +++ b/library/src/androidTest/java/IntegrationUtils.kt @@ -31,6 +31,8 @@ import com.wultra.android.mtokensdk.inbox.IInboxService import com.wultra.android.mtokensdk.inbox.createInboxService import com.wultra.android.mtokensdk.operation.IOperationsService import com.wultra.android.mtokensdk.operation.createOperationsService +import com.wultra.android.mtokensdk.push.IPushService +import com.wultra.android.mtokensdk.push.createPushService import com.wultra.android.powerauth.networking.ssl.SSLValidationStrategy import io.getlime.security.powerauth.core.ActivationCodeUtil import io.getlime.security.powerauth.networking.response.CreateActivationResult @@ -68,6 +70,8 @@ class TimestampAdapter: TypeAdapter() { class IntegrationUtils { + data class ActivationResult(val pa: PowerAuthSDK, val ops: IOperationsService, val inbox: IInboxService, val push: IPushService) + companion object { val context: Context = ApplicationProvider.getApplicationContext() private val client = OkHttpClient.Builder().build() @@ -81,12 +85,13 @@ class IntegrationUtils { private val enrollmentUrl = getInstrumentationParameter("enrollmentServerUrl") private val operationsUrl = getInstrumentationParameter("operationsServerUrl") private val inboxUrl = getInstrumentationParameter("inboxServerUrl") + private val pushUrl = getInstrumentationParameter("pushServerUrl") private val sdkConfig = getInstrumentationParameter("sdkConfig") private var activationName = "" // will be filled when activation is created private var registrationId = "" // will be filled when activation is created @Throws - fun prepareActivation(pin: String, userId: String? = null): Triple { + fun prepareActivation(pin: String, userId: String? = null): ActivationResult { // Be sure that each activation has its own user activationName = userId ?: UUID.randomUUID().toString() @@ -150,10 +155,11 @@ class IntegrationUtils { .trimIndent() makeCall(bodyCommit, "$cloudServerUrl/v2/registrations/${resp.registrationId}/commit") - return Triple( + return ActivationResult( pa, pa.createOperationsService(context, operationsUrl, SSLValidationStrategy.system()), - pa.createInboxService(context, inboxUrl, SSLValidationStrategy.system()) + pa.createInboxService(context, inboxUrl, SSLValidationStrategy.system()), + pa.createPushService(context, pushUrl, SSLValidationStrategy.system()) ) }