Skip to content

Commit

Permalink
Push tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kober32 committed Nov 19, 2024
1 parent adafc7b commit c084f9a
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/ProjectConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
1 change: 1 addition & 0 deletions configs/integration-tests.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=
6 changes: 3 additions & 3 deletions library/src/androidTest/java/InboxTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
48 changes: 46 additions & 2 deletions library/src/androidTest/java/IntegrationTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,15 +42,17 @@ 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"

@Before
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")
}
Expand Down Expand Up @@ -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<Any?>()
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<Any?>()
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<Any?>()
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<Any?>()
push.register(PushData.hms("testToken")) { result ->
result.onSuccess { future.complete(null) }
.onFailure { future.completeExceptionally(it) }
}
Assert.assertNull(future.get(10, TimeUnit.SECONDS))
}
}
4 changes: 2 additions & 2 deletions library/src/androidTest/java/IntegrationTestsDeprecated.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
12 changes: 9 additions & 3 deletions library/src/androidTest/java/IntegrationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,6 +70,8 @@ class TimestampAdapter: TypeAdapter<Date>() {

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()
Expand All @@ -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<PowerAuthSDK, IOperationsService, IInboxService> {
fun prepareActivation(pin: String, userId: String? = null): ActivationResult {

// Be sure that each activation has its own user
activationName = userId ?: UUID.randomUUID().toString()
Expand Down Expand Up @@ -150,10 +155,11 @@ class IntegrationUtils {
.trimIndent()
makeCall<CommitObject>(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())
)
}

Expand Down

0 comments on commit c084f9a

Please sign in to comment.