-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Allain Magyar <allain.magyar@iohk.io>
- Loading branch information
1 parent
d674f31
commit ab8ffcb
Showing
13 changed files
with
259 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tests/integration-tests/src/test/kotlin/models/JwtCredential.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package models | ||
|
||
import com.jayway.jsonpath.DocumentContext | ||
import com.jayway.jsonpath.JsonPath | ||
import java.util.Base64 | ||
|
||
|
||
class JwtCredential(base64: String) { | ||
private val payload: DocumentContext | ||
|
||
init { | ||
val jwt = String(Base64.getDecoder().decode(base64)) | ||
val parts = jwt.split(".") | ||
payload = JsonPath.parse(String(Base64.getUrlDecoder().decode(parts[1]))) | ||
} | ||
|
||
fun statusListId(): String { | ||
val listUrl = payload.read<String>("$.vc.credentialStatus.statusListCredential") | ||
return listUrl.split("/credential-status/")[1] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
tests/integration-tests/src/test/kotlin/steps/credentials/RevokeCredentialSteps.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package steps.credentials | ||
|
||
import interactions.* | ||
import io.cucumber.java.en.Then | ||
import io.cucumber.java.en.When | ||
import io.iohk.atala.automation.serenity.ensure.Ensure | ||
import io.iohk.atala.automation.utils.Wait | ||
import models.JwtCredential | ||
import net.serenitybdd.rest.SerenityRest | ||
import net.serenitybdd.screenplay.Actor | ||
import org.apache.http.HttpStatus | ||
import org.hyperledger.identus.client.models.IssueCredentialRecord | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
class RevokeCredentialSteps { | ||
@When("{actor} revokes the credential issued to {actor}") | ||
fun issuerRevokesCredentialsIssuedToHolder(issuer: Actor, holder: Actor) { | ||
val issuedCredential = issuer.recall<IssueCredentialRecord>("issuedCredential") | ||
val jwtCred = JwtCredential(issuedCredential.credential!!) | ||
val statusListId = jwtCred.statusListId() | ||
issuer.remember("statusListId", statusListId) | ||
|
||
issuer.attemptsTo( | ||
Get.resource("/credential-status/${statusListId}") | ||
) | ||
val encodedList = SerenityRest.lastResponse().jsonPath().get<String>("credentialSubject.encodedList") | ||
issuer.remember("encodedStatusList", encodedList) | ||
|
||
issuer.attemptsTo( | ||
Patch.to("/credential-status/revoke-credential/${issuedCredential.recordId}"), | ||
Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_OK) | ||
) | ||
} | ||
|
||
@When("{actor} tries to revoke credential from {actor}") | ||
fun holderTriesToRevokeCredentialFromIssuer(holder: Actor, issuer: Actor) { | ||
val issuedCredential = issuer.recall<IssueCredentialRecord>("issuedCredential") | ||
val receivedCredential = holder.recall<IssueCredentialRecord>("issuedCredential") | ||
holder.attemptsTo( | ||
Patch.to("/credential-status/revoke-credential/${issuedCredential.recordId}"), | ||
Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_NOT_FOUND) | ||
) | ||
holder.attemptsTo( | ||
Patch.to("/credential-status/revoke-credential/${receivedCredential.recordId}"), | ||
Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_NOT_FOUND) | ||
) | ||
} | ||
|
||
@Then("{actor} should see the credential was revoked") | ||
fun credentialShouldBeRevoked(issuer: Actor) { | ||
Wait.until( | ||
timeout = 30.seconds, | ||
errorMessage = "Encoded Status List didn't change after revoking." | ||
) { | ||
val statusListId = issuer.recall<String>("statusListId") | ||
val encodedList = issuer.recall<String>("statusEncodedList") | ||
issuer.attemptsTo( | ||
Get.resource("/credential-status/$statusListId") | ||
) | ||
val actualEncodedList = SerenityRest.lastResponse().jsonPath().get<String>("credentialSubject.encodedList") | ||
actualEncodedList != encodedList | ||
} | ||
} | ||
|
||
@Then("{actor} should see the credential is not revoked") | ||
fun issuerShouldSeeTheCredentialIsNotRevoked(issuer: Actor) { | ||
val issuedCredential = issuer.recall<IssueCredentialRecord>("issuedCredential") | ||
val jwtCred = JwtCredential(issuedCredential.credential!!) | ||
val statusListId = jwtCred.statusListId() | ||
issuer.remember("statusListId", statusListId) | ||
|
||
issuer.attemptsTo( | ||
Get.resource("/credential-status/${statusListId}") | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.