@reventlessdev/reventless-registration 1.0.0-alpha.5 → 1.0.0-alpha.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -2
- package/conformance/Registration/InboundTranslation/CompleteRegistration_Conformance_GWT.res +65 -0
- package/conformance/Registration/InboundTranslation/CompleteRegistration_Conformance_GWT.res.mjs +123 -0
- package/conformance/Registration/InboundTranslation/SignUp_Conformance_GWT.res +136 -0
- package/conformance/Registration/InboundTranslation/SignUp_Conformance_GWT.res.mjs +212 -0
- package/conformance/Registration/OutboundTranslation/CreateRegisteredPrincipal_Conformance_GWT.res +102 -0
- package/conformance/Registration/OutboundTranslation/CreateRegisteredPrincipal_Conformance_GWT.res.mjs +179 -0
- package/conformance/Registration/OutboundTranslation/SendRegistrationChallenge_Conformance_GWT.res +312 -0
- package/conformance/Registration/OutboundTranslation/SendRegistrationChallenge_Conformance_GWT.res.mjs +360 -0
- package/conformance/Registration/Registration_Conformance_Examples.res +58 -0
- package/conformance/Registration/Registration_Conformance_Examples.res.mjs +106 -0
- package/conformance/Registration/StateChange/RegistrationPolicy_Conformance_GWT.res +108 -0
- package/conformance/Registration/StateChange/RegistrationPolicy_Conformance_GWT.res.mjs +161 -0
- package/conformance/Registration/StateChange/RegistrationsByInvitation_Conformance_GWT.res +155 -0
- package/conformance/Registration/StateChange/RegistrationsByInvitation_Conformance_GWT.res.mjs +216 -0
- package/conformance/Registration/StateChange/Registrations_Conformance_GWT.res +469 -0
- package/conformance/Registration/StateChange/Registrations_Conformance_GWT.res.mjs +512 -0
- package/conformance/Registration/StateViewStream/RegistrationWindows_Conformance_GWT.res +33 -0
- package/conformance/Registration/StateViewStream/RegistrationWindows_Conformance_GWT.res.mjs +87 -0
- package/i18n/en.json +8 -0
- package/package.json +10 -6
- package/rescript.json +6 -1
- package/src/Registration/InboundTranslation/CompleteRegistration.res +2 -2
- package/src/Registration/InboundTranslation/CompleteRegistration.res.mjs +3 -3
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +1 -1
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +1 -1
- package/src/Registration/InboundTranslation/SignUp.res +19 -9
- package/src/Registration/InboundTranslation/SignUp.res.mjs +14 -7
- package/src/Registration/InboundTranslation/SignUp_Translation.res +32 -7
- package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +41 -8
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +5 -5
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +6 -5
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +10 -8
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +18 -10
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +24 -13
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +26 -16
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +115 -44
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +204 -66
- package/src/Registration/StateChange/RegistrationPolicy.res +3 -0
- package/src/Registration/StateChange/RegistrationPolicy.res.mjs +3 -0
- package/src/Registration/StateChange/RegistrationPolicy_Decision.res +6 -5
- package/src/Registration/StateChange/RegistrationPolicy_Decision.res.mjs +22 -15
- package/src/Registration/StateChange/Registrations.res +67 -41
- package/src/Registration/StateChange/Registrations.res.mjs +84 -51
- package/src/Registration/StateChange/Registrations_Decision.res +82 -39
- package/src/Registration/StateChange/Registrations_Decision.res.mjs +116 -58
- package/src/Registration/StateViewStream/RegistrationWindows.res +4 -0
- package/src/Registration/StateViewStream/RegistrationWindows.res.mjs +3 -3
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
// The ledger's rules that hold for any admission table. An app runs them against its own:
|
|
2
|
+
// `module Ledger = Registrations_Conformance_GWT.Make(Admission)`.
|
|
3
|
+
//
|
|
4
|
+
// What it must never do is answer an anonymous caller differently for a closed policy, a taken
|
|
5
|
+
// address and a fresh one — every arm here is an event or nothing, never an error — and what it
|
|
6
|
+
// must never record is a secret: only its hash.
|
|
7
|
+
|
|
8
|
+
module Make = (App: Reventless.Admission.Declaration) => {
|
|
9
|
+
module Ledger = Registrations
|
|
10
|
+
module AppLedger = Registrations_Decision.Make(App)
|
|
11
|
+
open Ledger
|
|
12
|
+
include ReventlessGwt.Decision_GWT.Make(Ledger, AppLedger)
|
|
13
|
+
open Registration_Conformance_Examples
|
|
14
|
+
|
|
15
|
+
let needing = needs =>
|
|
16
|
+
(name, body) =>
|
|
17
|
+
switch unmet(needs) {
|
|
18
|
+
| None => test(name, body)
|
|
19
|
+
| Some(why) => todo(`${name} (${why})`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let selfServiceRoles = selfService(App.table)
|
|
23
|
+
let otherRoles = notSelfService(App.table)
|
|
24
|
+
let aSelfServiceRole = has(selfServiceRoles, ~kind="self-service")
|
|
25
|
+
let anOtherRole = has(otherRoles, ~kind="non-self-service")
|
|
26
|
+
|
|
27
|
+
let emailId = alice
|
|
28
|
+
let email = aliceMail
|
|
29
|
+
let role = first(selfServiceRoles)
|
|
30
|
+
let roleName = nameOf(role)
|
|
31
|
+
let other = first(otherRoles)
|
|
32
|
+
let roles = [roleName]
|
|
33
|
+
let requestedAt = "2026-10-24T09:00:00.000Z"
|
|
34
|
+
let issuedAt = "2026-10-24T09:00:05.000Z"
|
|
35
|
+
let soonAfter = "2026-10-24T09:10:00.000Z"
|
|
36
|
+
let halfAMinuteOn = "2026-10-24T09:00:35.000Z"
|
|
37
|
+
let nextDay = "2026-10-25T09:00:06.000Z"
|
|
38
|
+
let nextDayLater = "2026-10-25T09:30:00.000Z"
|
|
39
|
+
let twoHoursOn = "2026-10-25T11:00:07.000Z"
|
|
40
|
+
let windowEnd = "2026-10-24T08:00:00.000Z"
|
|
41
|
+
|
|
42
|
+
// Nothing recorded about a self-service role is open, so the ledger's history starts at the
|
|
43
|
+
// request; `opened` is the explicit form, for the window tests.
|
|
44
|
+
let opened: array<consumedEvent> = [RegistrationOpened({role: role})]
|
|
45
|
+
let requested: array<consumedEvent> = [
|
|
46
|
+
RegistrationRequested({emailId, email: personal, roles, requestedAt}),
|
|
47
|
+
]
|
|
48
|
+
let challenged: array<consumedEvent> =
|
|
49
|
+
requested->Array.concat([
|
|
50
|
+
RegistrationChallengeIssued({emailId, proofHash: secretHash, issuedAt}),
|
|
51
|
+
])
|
|
52
|
+
let verified: array<consumedEvent> =
|
|
53
|
+
challenged->Array.concat([
|
|
54
|
+
RegistrationProofAccepted({emailId, email: personal, roles, proofHash: secretHash}),
|
|
55
|
+
])
|
|
56
|
+
let completed: array<consumedEvent> =
|
|
57
|
+
verified->Array.concat([RegistrationCompleted({emailId: emailId})])
|
|
58
|
+
let wrong: consumedEvent = RegistrationProofRefused({emailId, reason: "ProofMismatch"})
|
|
59
|
+
let reissued: array<consumedEvent> =
|
|
60
|
+
challenged->Array.concat([
|
|
61
|
+
RegistrationChallengeReissued({emailId, email: personal, reissuedAt: soonAfter}),
|
|
62
|
+
])
|
|
63
|
+
|
|
64
|
+
let register = (~role=role, ~at=requestedAt, ~initially=?) => Register({
|
|
65
|
+
emailId,
|
|
66
|
+
email,
|
|
67
|
+
role,
|
|
68
|
+
requestedAt: at,
|
|
69
|
+
?initially,
|
|
70
|
+
})
|
|
71
|
+
let submit = (~hash=secretHash, ~at=soonAfter) => SubmitRegistrationProof({
|
|
72
|
+
emailId,
|
|
73
|
+
proofHash: hash,
|
|
74
|
+
presentedAt: at,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe("Registrations StateChangeSlice", () => {
|
|
78
|
+
let test = needing([aSelfServiceRole])
|
|
79
|
+
|
|
80
|
+
// 🚨 The policy is read in the same decision as the address, as its own clause, so a
|
|
81
|
+
// policy closed while a registration is being decided fails the append rather than
|
|
82
|
+
// slipping past it.
|
|
83
|
+
// scenario-id: 49225316-1861-49eb-a48c-474b197b557c
|
|
84
|
+
test("a registration is conditioned on the policy as well as the address", () =>
|
|
85
|
+
givenEvents([])
|
|
86
|
+
->whenCmd(register())
|
|
87
|
+
->thenAppendsConditionedOn([
|
|
88
|
+
{
|
|
89
|
+
// The address's own history. The policy's two types ride along because a
|
|
90
|
+
// single-slice view cannot prove they never carry the address; they match nothing
|
|
91
|
+
// here.
|
|
92
|
+
eventTypes: [
|
|
93
|
+
"RegistrationOpened",
|
|
94
|
+
"RegistrationClosed",
|
|
95
|
+
"RegistrationRequested",
|
|
96
|
+
"RegistrationExpired",
|
|
97
|
+
"RegistrationInvited",
|
|
98
|
+
"RegistrationChallengeReissued",
|
|
99
|
+
"RegistrationWithdrawn",
|
|
100
|
+
"RegistrationAttemptedOnTakenAddress",
|
|
101
|
+
"RegistrationChallengeIssued",
|
|
102
|
+
"RegistrationProofAccepted",
|
|
103
|
+
"RegistrationProofRefused",
|
|
104
|
+
"RegistrationCompleted",
|
|
105
|
+
"RegistrationReleased",
|
|
106
|
+
],
|
|
107
|
+
tags: [{key: "contactAddress", value: emailId->ContactAddressId.toString}],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
eventTypes: ["RegistrationOpened", "RegistrationClosed"],
|
|
111
|
+
tags: [{key: "role", value: roleName}],
|
|
112
|
+
},
|
|
113
|
+
])
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
// scenario-id: 2b7f9c1d-4e6a-4b8c-9d0e-1f2a3b4c5d6e
|
|
117
|
+
test("a role nobody knows records nothing", () =>
|
|
118
|
+
givenEvents([])->whenCmd(register(~role=unknownRole(App.table)))->thenNoEvent
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
// scenario-id: 358a6a64-4227-4c3c-b2e9-72e666c27184
|
|
122
|
+
test("a self-service role claims the address before anything is recorded", () =>
|
|
123
|
+
givenEvents([])
|
|
124
|
+
->whenCmd(register())
|
|
125
|
+
->thenEvent(RegistrationRequested({emailId, email: personal, roles, requestedAt}))
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
// scenario-id: 6c1e8a2b-9d3f-4a5e-8b7c-0d1e2f3a4b5c
|
|
129
|
+
test("a closed self-service role records nothing", () =>
|
|
130
|
+
givenEvents([RegistrationClosed({role: role})])->whenCmd(register())->thenNoEvent
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
// A window someone forgot to close ends by itself, with no event to close it: the role is
|
|
134
|
+
// then what the deployment starts as.
|
|
135
|
+
// scenario-id: ee7d41c0-5f7d-4ae2-a9e2-5af69a071833
|
|
136
|
+
test("past an open window's end, a deployment that starts closed refuses", () =>
|
|
137
|
+
givenEvents([RegistrationOpened({role, until: windowEnd})])
|
|
138
|
+
->whenCmd(register(~initially=Reventless.Admission.InitiallyClosed))
|
|
139
|
+
->thenNoEvent
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
// scenario-id: f41365c2-218a-4992-89d5-fb999cad6e40
|
|
143
|
+
test("past an open window's end, a deployment that starts open claims the address", () =>
|
|
144
|
+
givenEvents([RegistrationOpened({role, until: windowEnd})])
|
|
145
|
+
->whenCmd(register(~initially=Reventless.Admission.InitiallyOpen))
|
|
146
|
+
->thenEvent(RegistrationRequested({emailId, email: personal, roles, requestedAt}))
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
// Nothing recorded is the starting state: a public deployment takes no stranger until an
|
|
150
|
+
// administrator opens the role.
|
|
151
|
+
// scenario-id: a2cc958f-c011-45f9-94fa-ae41129c9536
|
|
152
|
+
test("with nothing recorded, a deployment that starts closed refuses", () =>
|
|
153
|
+
givenEvents([])
|
|
154
|
+
->whenCmd(register(~initially=Reventless.Admission.InitiallyClosed))
|
|
155
|
+
->thenNoEvent
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
// A request stamped with no starting state was made when every role started open.
|
|
159
|
+
// scenario-id: f9d5918e-e77a-4b1a-9da6-21f2ac15de46
|
|
160
|
+
test("with nothing recorded, a request with no starting state claims the address", () =>
|
|
161
|
+
givenEvents([])
|
|
162
|
+
->whenCmd(register())
|
|
163
|
+
->thenEvent(RegistrationRequested({emailId, email: personal, roles, requestedAt}))
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
// scenario-id: 8206c898-8733-4858-996c-2e253f63ea3a
|
|
167
|
+
test("within an open window's end, it claims the address", () =>
|
|
168
|
+
givenEvents([RegistrationOpened({role, until: nextDay})])
|
|
169
|
+
->whenCmd(register())
|
|
170
|
+
->thenEvent(RegistrationRequested({emailId, email: personal, roles, requestedAt}))
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
// scenario-id: dd3c4e5d-f19a-48b9-8011-b9cd63849b75
|
|
174
|
+
test("closing the policy stops registrations it had admitted", () =>
|
|
175
|
+
givenEvents(opened->Array.concat([RegistrationClosed({role: role})]))
|
|
176
|
+
->whenCmd(register())
|
|
177
|
+
->thenNoEvent
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
// scenario-id: 7c2c6eea-6ae0-4de0-930f-cea318e1e553
|
|
181
|
+
test("a second request while one is pending records nothing", () =>
|
|
182
|
+
givenEvents(challenged)->whenCmd(register(~at=soonAfter))->thenNoEvent
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
// 🚨 The security test: the caller is answered as for a fresh address, and the address is
|
|
186
|
+
// told someone tried.
|
|
187
|
+
// scenario-id: 27985e0e-cd57-42f8-9781-760d0ebc2a3a
|
|
188
|
+
test("a registered address records the attempt, not a registration", () =>
|
|
189
|
+
givenEvents(completed)
|
|
190
|
+
->whenCmd(register(~at=nextDay))
|
|
191
|
+
->thenEvent(
|
|
192
|
+
RegistrationAttemptedOnTakenAddress({emailId, email: personal, attemptedAt: nextDay}),
|
|
193
|
+
)
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
// The notice is the one thing the door makes the deployment send to someone who did not
|
|
197
|
+
// ask; a second attempt within the hour sends nothing more.
|
|
198
|
+
// scenario-id: 8ac35a9c-5d8b-441a-95bc-64768139ef97
|
|
199
|
+
test("a second attempt on a registered address within the hour sends no second notice", () =>
|
|
200
|
+
givenEvents(
|
|
201
|
+
completed->Array.concat([
|
|
202
|
+
RegistrationAttemptedOnTakenAddress({emailId, email: personal, attemptedAt: nextDay}),
|
|
203
|
+
]),
|
|
204
|
+
)
|
|
205
|
+
->whenCmd(register(~at=nextDayLater))
|
|
206
|
+
->thenNoEvent
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
// scenario-id: b0425f3e-52a6-40e5-89a4-8b70f8de2fb2
|
|
210
|
+
test("after the hour, a registered address is told again", () =>
|
|
211
|
+
givenEvents(
|
|
212
|
+
completed->Array.concat([
|
|
213
|
+
RegistrationAttemptedOnTakenAddress({emailId, email: personal, attemptedAt: nextDay}),
|
|
214
|
+
]),
|
|
215
|
+
)
|
|
216
|
+
->whenCmd(register(~at=twoHoursOn))
|
|
217
|
+
->thenEvent(
|
|
218
|
+
RegistrationAttemptedOnTakenAddress({emailId, email: personal, attemptedAt: twoHoursOn}),
|
|
219
|
+
)
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
// scenario-id: 5c409dc3-76f6-4311-9943-d655fc11f38e
|
|
223
|
+
test("an abandoned registration releases the address", () =>
|
|
224
|
+
givenEvents(challenged)
|
|
225
|
+
->whenCmd(register(~at=nextDay))
|
|
226
|
+
->thenEvents([
|
|
227
|
+
RegistrationExpired({emailId: emailId}),
|
|
228
|
+
RegistrationRequested({emailId, email: personal, roles, requestedAt: nextDay}),
|
|
229
|
+
])
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
// scenario-id: 77738b1e-b5a2-41ab-888f-7cc6b0d44cdd
|
|
233
|
+
test("a pending registration opens a challenge against a hash", () =>
|
|
234
|
+
givenEvents(requested)
|
|
235
|
+
->whenCmd(IssueRegistrationChallenge({emailId, proofHash: secretHash, issuedAt}))
|
|
236
|
+
->thenEvent(RegistrationChallengeIssued({emailId, proofHash: secretHash, issuedAt}))
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
// The language a visitor asked in is kept with the claim, so every code it is sent is
|
|
240
|
+
// written in it; and what is recorded of the code's mail is its key and language.
|
|
241
|
+
test("a registration keeps the language it was asked in", () =>
|
|
242
|
+
givenEvents([])
|
|
243
|
+
->whenCmd(Register({emailId, email, role, requestedAt, language: "de"}))
|
|
244
|
+
->thenEvent(
|
|
245
|
+
RegistrationRequested({emailId, email: personal, roles, requestedAt, language: "de"}),
|
|
246
|
+
)
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
test("a challenge records the language and key of the mail that carried it", () =>
|
|
250
|
+
givenEvents(requested)
|
|
251
|
+
->whenCmd(
|
|
252
|
+
IssueRegistrationChallenge({
|
|
253
|
+
emailId,
|
|
254
|
+
proofHash: secretHash,
|
|
255
|
+
issuedAt,
|
|
256
|
+
language: "de",
|
|
257
|
+
messageKey: "registration.challenge.body",
|
|
258
|
+
}),
|
|
259
|
+
)
|
|
260
|
+
->thenEvent(
|
|
261
|
+
RegistrationChallengeIssued({
|
|
262
|
+
emailId,
|
|
263
|
+
proofHash: secretHash,
|
|
264
|
+
issuedAt,
|
|
265
|
+
language: "de",
|
|
266
|
+
messageKey: "registration.challenge.body",
|
|
267
|
+
}),
|
|
268
|
+
)
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
test("a reissued code is asked for in the claim's language", () =>
|
|
272
|
+
givenEvents([
|
|
273
|
+
RegistrationRequested({emailId, email: personal, roles, requestedAt, language: "de"}),
|
|
274
|
+
RegistrationChallengeIssued({emailId, proofHash: secretHash, issuedAt}),
|
|
275
|
+
])
|
|
276
|
+
->whenCmd(ReissueRegistrationChallenge({emailId, requestedAt: soonAfter}))
|
|
277
|
+
->thenEvent(
|
|
278
|
+
RegistrationChallengeReissued({
|
|
279
|
+
emailId,
|
|
280
|
+
email: personal,
|
|
281
|
+
reissuedAt: soonAfter,
|
|
282
|
+
language: "de",
|
|
283
|
+
}),
|
|
284
|
+
)
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
// scenario-id: 85ae672c-cfa3-4b26-817f-adc83b7437bd
|
|
288
|
+
test("a redelivered challenge request opens nothing", () =>
|
|
289
|
+
givenEvents(challenged)
|
|
290
|
+
->whenCmd(IssueRegistrationChallenge({emailId, proofHash: "another", issuedAt: soonAfter}))
|
|
291
|
+
->thenNoEvent
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
// scenario-id: 311f471f-6f65-4d6a-9e8b-690f3918cc0c
|
|
295
|
+
test("the right proof settles the registration", () =>
|
|
296
|
+
givenEvents(challenged)
|
|
297
|
+
->whenCmd(submit())
|
|
298
|
+
->thenEvent(
|
|
299
|
+
RegistrationProofAccepted({emailId, email: personal, roles, proofHash: secretHash}),
|
|
300
|
+
)
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
// scenario-id: 055e3684-db0f-40f0-9e4a-fdba6cddb70c
|
|
304
|
+
test("a wrong proof is counted, not settled", () =>
|
|
305
|
+
givenEvents(challenged)
|
|
306
|
+
->whenCmd(submit(~hash="hash-of-a-guess"))
|
|
307
|
+
->thenEvent(RegistrationProofRefused({emailId, reason: "ProofMismatch"}))
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
// scenario-id: 01c83ed2-4ac7-4561-b3a6-33007e75b4f3
|
|
311
|
+
test("a proof after the challenge lapsed is refused", () =>
|
|
312
|
+
givenEvents(challenged)
|
|
313
|
+
->whenCmd(submit(~at=nextDay))
|
|
314
|
+
->thenEvent(RegistrationProofRefused({emailId, reason: "ChallengeExpired"}))
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
// scenario-id: fb9e68aa-2b1f-4e26-914a-6e691214b863
|
|
318
|
+
test("the right proof after the attempts are spent is refused", () =>
|
|
319
|
+
givenEvents(challenged->Array.concat([wrong, wrong, wrong, wrong, wrong]))
|
|
320
|
+
->whenCmd(submit())
|
|
321
|
+
->thenEvent(RegistrationProofRefused({emailId, reason: "AttemptsExhausted"}))
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
// scenario-id: b551a64a-847e-4ec1-aac5-6c4db2c4c904
|
|
325
|
+
test("a settled proof settles once", () =>
|
|
326
|
+
givenEvents(completed)->whenCmd(submit())->thenNoEvent
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
// Nothing to count it against, and nothing to tell the caller.
|
|
330
|
+
// scenario-id: 1c30ca00-a65b-48be-a93f-0bed5996894c
|
|
331
|
+
test("a proof with no challenge outstanding records nothing", () =>
|
|
332
|
+
givenEvents([])->whenCmd(submit())->thenNoEvent
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
// scenario-id: 0ace1364-f882-406d-adce-e0be15803354
|
|
336
|
+
test("an account made for a settled proof completes the registration", () =>
|
|
337
|
+
givenEvents(verified)
|
|
338
|
+
->whenCmd(RecordRegistrationCompleted({emailId: emailId}))
|
|
339
|
+
->thenEvent(RegistrationCompleted({emailId: emailId}))
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
// scenario-id: 5e8b1e7b-98e0-4e85-b7bb-c7e76a12f3b6
|
|
343
|
+
test("completion without a settled proof records nothing", () =>
|
|
344
|
+
givenEvents(challenged)
|
|
345
|
+
->whenCmd(RecordRegistrationCompleted({emailId: emailId}))
|
|
346
|
+
->thenNoEvent
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
// A code lost, or its attempts spent: the claim keeps the address and waits for a fresh
|
|
350
|
+
// code.
|
|
351
|
+
// scenario-id: 91ec32ef-5065-4dec-8854-7aa7a3a7948e
|
|
352
|
+
test("a code that went out is reissued", () =>
|
|
353
|
+
givenEvents(challenged)
|
|
354
|
+
->whenCmd(ReissueRegistrationChallenge({emailId, requestedAt: soonAfter}))
|
|
355
|
+
->thenEvent(RegistrationChallengeReissued({emailId, email: personal, reissuedAt: soonAfter}))
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
// scenario-id: 4cd5e9f7-0e91-484b-8aff-69327eb7bf24
|
|
359
|
+
test("a code is not reissued within the resend cooldown", () =>
|
|
360
|
+
givenEvents(challenged)
|
|
361
|
+
->whenCmd(ReissueRegistrationChallenge({emailId, requestedAt: halfAMinuteOn}))
|
|
362
|
+
->thenNoEvent
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
// A second code while the first is still on its way would leave the ledger holding
|
|
366
|
+
// whichever arrived first.
|
|
367
|
+
// scenario-id: 4ba66cf6-d624-4edf-b2f1-9541d41daca6
|
|
368
|
+
test("a code still on its way is not reissued", () =>
|
|
369
|
+
givenEvents(requested)
|
|
370
|
+
->whenCmd(ReissueRegistrationChallenge({emailId, requestedAt: soonAfter}))
|
|
371
|
+
->thenNoEvent
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
// scenario-id: 282891a5-c29f-44ff-a9d6-6aaeeaeee26e
|
|
375
|
+
test("a reissued code settles where the spent one could not", () =>
|
|
376
|
+
givenEvents(
|
|
377
|
+
challenged
|
|
378
|
+
->Array.concat([wrong, wrong, wrong, wrong, wrong])
|
|
379
|
+
->Array.concat([
|
|
380
|
+
RegistrationChallengeReissued({emailId, email: personal, reissuedAt: soonAfter}),
|
|
381
|
+
RegistrationChallengeIssued({
|
|
382
|
+
emailId,
|
|
383
|
+
proofHash: "hash-of-the-new-secret",
|
|
384
|
+
issuedAt: soonAfter,
|
|
385
|
+
}),
|
|
386
|
+
]),
|
|
387
|
+
)
|
|
388
|
+
->whenCmd(submit(~hash="hash-of-the-new-secret"))
|
|
389
|
+
->thenEvent(
|
|
390
|
+
RegistrationProofAccepted({
|
|
391
|
+
emailId,
|
|
392
|
+
email: personal,
|
|
393
|
+
roles,
|
|
394
|
+
proofHash: "hash-of-the-new-secret",
|
|
395
|
+
}),
|
|
396
|
+
)
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
// scenario-id: e0bca4c5-edce-4d95-8ce1-2b500fd0317e
|
|
400
|
+
test("the voided code no longer settles anything", () =>
|
|
401
|
+
givenEvents(reissued)->whenCmd(submit(~at=soonAfter))->thenNoEvent
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
// scenario-id: be2adab7-c940-46e8-b957-02f55bcb7916
|
|
405
|
+
test("withdrawing a pending registration releases the address", () =>
|
|
406
|
+
givenEvents(challenged)
|
|
407
|
+
->whenCmd(WithdrawRegistration({emailId, withdrawnAt: soonAfter}))
|
|
408
|
+
->thenEvent(RegistrationWithdrawn({emailId, withdrawnAt: soonAfter}))
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
// Once a proof settled, an account is on its way; withdrawing would not stop it.
|
|
412
|
+
// scenario-id: a06fb615-ee9a-493c-afde-adab251a847e
|
|
413
|
+
test("a settled registration is not withdrawn", () =>
|
|
414
|
+
givenEvents(verified)
|
|
415
|
+
->whenCmd(WithdrawRegistration({emailId, withdrawnAt: soonAfter}))
|
|
416
|
+
->thenNoEvent
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
// 🚨 An erased account gives its address back, or its person could never register again.
|
|
420
|
+
// scenario-id: de1ea12d-dcc4-4539-a6c8-ce90ff8adaa2
|
|
421
|
+
test("releasing an erased account frees the address", () =>
|
|
422
|
+
givenEvents(completed)
|
|
423
|
+
->whenCmd(ReleaseRegistration({emailId, releasedAt: nextDay}))
|
|
424
|
+
->thenEvent(RegistrationReleased({emailId, releasedAt: nextDay}))
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
// scenario-id: f74642f6-039b-4f1a-95e3-fa207a2ff5a6
|
|
428
|
+
test("a released address registers again", () =>
|
|
429
|
+
givenEvents(completed->Array.concat([RegistrationReleased({emailId, releasedAt: nextDay})]))
|
|
430
|
+
->whenCmd(register(~at=nextDayLater))
|
|
431
|
+
->thenEvent(
|
|
432
|
+
RegistrationRequested({emailId, email: personal, roles, requestedAt: nextDayLater}),
|
|
433
|
+
)
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
// A claim nobody proved is withdrawn, not released.
|
|
437
|
+
// scenario-id: f1b6c0a2-d964-4da3-8255-6a767198530e
|
|
438
|
+
test("a pending registration is not released", () =>
|
|
439
|
+
givenEvents(challenged)
|
|
440
|
+
->whenCmd(ReleaseRegistration({emailId, releasedAt: soonAfter}))
|
|
441
|
+
->thenNoEvent
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
// A self-service role is signed up for, never invited to, whatever else the table says.
|
|
445
|
+
// scenario-id: 56e1d5a8-23a2-446f-b3bc-29da9af6ac77
|
|
446
|
+
test("a role the app does not declare by invitation is refused to an inviter", () =>
|
|
447
|
+
givenEvents([])
|
|
448
|
+
->whenCmd(Invite({emailId, email, roles: [role], invitedBy: "u_admin", requestedAt}))
|
|
449
|
+
->thenError(NotByInvitation({role: roleName}))
|
|
450
|
+
)
|
|
451
|
+
|
|
452
|
+
let test = needing([anOtherRole])
|
|
453
|
+
|
|
454
|
+
// 🚨 A role not declared self-service is closed, whatever anyone records, and it sends
|
|
455
|
+
// nothing — not even a notice.
|
|
456
|
+
// scenario-id: a093e1a8-62f1-4f28-b7e0-28920fda60bb
|
|
457
|
+
test("a role no visitor may have records nothing", () =>
|
|
458
|
+
givenEvents([])->whenCmd(register(~role=other))->thenNoEvent
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
// The starting state opens only roles the app declares self-service.
|
|
462
|
+
// scenario-id: 37aef343-e58c-49c9-be31-42ae7e5155c1
|
|
463
|
+
test("a role that is not self-service is refused on a deployment that starts open", () =>
|
|
464
|
+
givenEvents([])
|
|
465
|
+
->whenCmd(register(~role=other, ~initially=Reventless.Admission.InitiallyOpen))
|
|
466
|
+
->thenNoEvent
|
|
467
|
+
)
|
|
468
|
+
})
|
|
469
|
+
}
|