-
Notifications
You must be signed in to change notification settings - Fork 15
/
PresentProofSteps.kt
156 lines (147 loc) · 5.92 KB
/
PresentProofSteps.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package features.present_proof
import api_models.Connection
import api_models.Credential
import api_models.PresentationProof
import common.Utils.lastResponseList
import common.Utils.lastResponseObject
import common.Utils.wait
import io.cucumber.java.en.Then
import io.cucumber.java.en.When
import net.serenitybdd.screenplay.Actor
import net.serenitybdd.screenplay.rest.interactions.Get
import net.serenitybdd.screenplay.rest.interactions.Patch
import net.serenitybdd.screenplay.rest.interactions.Post
import net.serenitybdd.screenplay.rest.questions.ResponseConsequence
import org.apache.http.HttpStatus.SC_CREATED
import org.apache.http.HttpStatus.SC_OK
class PresentProofSteps {
@When("{actor} sends a request for proof presentation to {actor}")
fun faberSendsARequestForProofPresentationToBob(faber: Actor, bob: Actor) {
faber.attemptsTo(
Post.to("/present-proof/presentations")
.with {
it.body(
"""
{
"description":"Request presentation of credential",
"connectionId": "${faber.recall<Connection>("connection-with-${bob.name}").connectionId}",
"options":{
"challenge": "11c91493-01b3-4c4d-ac36-b336bab5bddf",
"domain": "https://example-verifier.com"
},
"proofs":[
{
"schemaId": "https://schema.org/Person",
"trustIssuers": [
"did:web:atalaprism.io/users/testUser"
]
}
]
}
""".trimIndent(),
)
},
)
faber.should(
ResponseConsequence.seeThatResponse {
it.statusCode(SC_CREATED)
},
)
faber.remember("presentationId", lastResponseObject("", PresentationProof::class).presentationId)
}
@When("{actor} receives the request")
fun bobReceivesTheRequest(bob: Actor) {
wait(
{
bob.attemptsTo(
Get.resource("/present-proof/presentations"),
)
bob.should(
ResponseConsequence.seeThatResponse("Get presentations") {
it.statusCode(SC_OK)
},
)
lastResponseList("contents", PresentationProof::class).findLast {
it.status == "RequestReceived"
} != null
},
"ERROR: Bob did not achieve any presentation request!",
)
val presentationId = lastResponseList("contents", PresentationProof::class).findLast {
it.status == "RequestReceived"
}!!.presentationId
bob.remember("presentationId", presentationId)
}
@When("{actor} makes the presentation of the proof to {actor}")
fun bobMakesThePresentationOfTheProof(bob: Actor, faber: Actor) {
bob.attemptsTo(
Patch.to("/present-proof/presentations/${bob.recall<String>("presentationId")}").with {
it.body(
"""
{ "action": "request-accept", "proofId": ["${bob.recall<Credential>("issuedCredential").recordId}"] }
""".trimIndent(),
)
},
)
}
@When("{actor} rejects the proof")
fun bobRejectsProof(bob: Actor) {
bob.attemptsTo(
Patch.to("/present-proof/presentations/${bob.recall<String>("presentationId")}").with {
it.body("""{ "action": "request-reject" }""")
},
)
}
@Then("{actor} sees the proof is rejected")
fun bobSeesProofIsRejected(actor: Actor) {
wait(
{
actor.attemptsTo(
Get.resource("/present-proof/presentations/${actor.recall<String>("presentationId")}"),
)
actor.should(
ResponseConsequence.seeThatResponse {
it.statusCode(SC_OK)
},
)
lastResponseObject("", PresentationProof::class).status == "RequestRejected"
},
"ERROR: Faber did not receive presentation from Bob!",
)
}
@When("{actor} acknowledges the proof")
fun faberAcknowledgesTheProof(faber: Actor) {
wait(
{
faber.attemptsTo(
Get.resource("/present-proof/presentations/${faber.recall<String>("presentationId")}"),
)
faber.should(
ResponseConsequence.seeThatResponse {
it.statusCode(SC_OK)
},
)
lastResponseObject("", PresentationProof::class).status == "PresentationReceived" ||
lastResponseObject("", PresentationProof::class).status == "PresentationVerified"
},
"ERROR: Faber did not receive presentation from Bob!",
)
}
@Then("{actor} has the proof verified")
fun faberHasTheProofVerified(faber: Actor) {
wait(
{
faber.attemptsTo(
Get.resource("/present-proof/presentations/${faber.recall<String>("presentationId")}"),
)
faber.should(
ResponseConsequence.seeThatResponse {
it.statusCode(SC_OK)
},
)
lastResponseObject("", PresentationProof::class).status == "PresentationVerified"
},
"ERROR: presentation did not achieve PresentationVerified state!",
)
}
}