Skip to content
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

Added statusReason to UserOperation #148

Merged
merged 2 commits into from
Jun 5, 2024
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
8 changes: 8 additions & 0 deletions docs/Using-Operations-Service.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ class UserOperation: IOperation {

/** Proximity Check Data to be passed when OTP is handed to the app */
var proximityCheck: ProximityCheck? = null


/**
* Enum-like reason why the status has changed.
*
* Max 32 characters are expected. Possible values depend on the backend implementation and configuration.
*/
val statusReason: String?
}
```

Expand Down
26 changes: 26 additions & 0 deletions library/src/androidTest/java/IntegrationTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,30 @@ class IntegrationTests {
}
Assert.assertNull(authorizedFuture2.get(20, TimeUnit.SECONDS))
}

@Test
fun testOperationCanceledWithReason() {
// create regular operation
val op = IntegrationUtils.createOperation(IntegrationUtils.Companion.Factors.F_2FA)
val cancelReason = "PREARRANGED_REASON"
// cancel the operation
IntegrationUtils.cancelOperation(op.operationId, cancelReason)

val future = CompletableFuture<List<OperationHistoryEntry>?>()
val auth = PowerAuthAuthentication.possessionWithPassword(pin)
ops.getHistory(auth) { result ->
result.onSuccess { future.complete(it) }
.onFailure { future.completeExceptionally(it) }
}

val operations = future.get(20, TimeUnit.SECONDS)
Assert.assertNotNull("Operations not retrieved", operations)
if (operations == null) {
return
}

val opRecord = operations.firstOrNull { it.operation.id == op.operationId }
Assert.assertNotNull(opRecord)
Assert.assertTrue("${opRecord?.operation?.statusReason} should be PREARRANGED_REASON", opRecord?.operation?.statusReason == "PREARRANGED_REASON")
}
}
5 changes: 5 additions & 0 deletions library/src/androidTest/java/IntegrationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ class IntegrationUtils {
return makeCall(opBody, "$cloudServerUrl/v2/operations")
}

@Throws
fun cancelOperation(operationId: String, reason: String): StatusResponse {
return makeCall("", "$cloudServerUrl/v2/operations/$operationId?statusReason=$reason", "DELETE")
}

@Throws
fun createNonPersonalizedPACOperation(factors: Factors): NonPersonalisedTOTPOperationObject {
val opBody = when (factors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ open class UserOperation(
* Proximity Check Data to be passed when OTP is handed to the app
*/
@SerializedName("proximityCheck")
override var proximityCheck: ProximityCheck? = null
override var proximityCheck: ProximityCheck? = null,

/**
* Enum-like reason why the status has changed.
*
* Max 32 characters are expected. Possible values depend on the backend implementation and configuration.
*/
@SerializedName("statusReason")
val statusReason: String?
) : IOperation, ExpirableOperation

/**
Expand Down
Loading