feat(identity): confirm registration email atomically
This commit is contained in:
1 parent
8e7ce8d71c
commit
fade4e76e4
75 files changed
+4188
-403
No files matched your search
@@ -373,7 +373,8 @@ func TestConsentLedger(t *testing.T) {
|
||||
{"C4 with a repeated field", insert("c4", "c4-2026-10-01", publicationHash[:], "invitation_acceptance", &organization, []string{"email", "email"}, nil), consentCheckViolation, "consent_records_c4_scope"},
|
||||
{"C4 with an unknown field", insert("c4", "c4-2026-10-01", publicationHash[:], "invitation_acceptance", &organization, []string{"address"}, nil), consentCheckViolation, "consent_records_c4_scope"},
|
||||
{"C2 with a scope", insert("c2", "c2-2026-10-01", publicationHash[:], "consent_settings", &organization, []string{"email"}, nil), consentCheckViolation, "consent_records_c4_scope"},
|
||||
{"C2 from the registration", insert("c2", "c2-2026-10-01", publicationHash[:], "registration", nil, nil, nil), consentCheckViolation, "consent_records_source_of_purpose"},
|
||||
{"C2 from the registration", insert("c2", "c2-2026-10-01", publicationHash[:], "registration", nil, nil, nil), consentCheckViolation, "consent_records_registration_version"},
|
||||
{"C2 from an invitation", insert("c2", "c2-2026-10-01", publicationHash[:], "invitation_acceptance", nil, nil, nil), consentCheckViolation, "consent_records_source_of_purpose"},
|
||||
{"revocation without a source", insert("c2", "c2-2026-10-01", publicationHash[:], "consent_settings", nil, nil, &empty), consentCheckViolation, "consent_records_revocation_stamp"},
|
||||
{"hash of another text", insert("c3", "c3-2026-10-01", publicationHash[:], "consent_settings", nil, nil, nil), consentForeignKeyViolation, "consent_records_published_text_fkey"},
|
||||
} {
|
||||
@@ -658,11 +659,14 @@ func TestConsentLedger(t *testing.T) {
|
||||
t.Fatalf("ReRegister() error = %v", err)
|
||||
}
|
||||
var replacement domain.ConsentRecord
|
||||
var registered domain.User
|
||||
err = fixture.transactor.WithinTransaction(ctx, func(ctx context.Context, unit outbound.UnitOfWork) error {
|
||||
if _, err := unit.Users().UpdateRegistration(ctx, changed); err != nil {
|
||||
var err error
|
||||
registered, err = unit.Users().UpdateRegistration(ctx, changed)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
grant := fixture.newGrant(t, first.ID, domain.ConsentPurposePersonalData, "c1-2026-10-01", domain.ConsentSourceRegistration, now)
|
||||
grant := fixture.newGrant(t, first.ID, domain.ConsentPurposePersonalData, "c1-2026-10-01", domain.ConsentSourceRegistration, now, registered.RegistrationVersion)
|
||||
var created bool
|
||||
replacement, created, err = unit.ConsentLedger().Grant(ctx, grant)
|
||||
if err == nil && !created {
|
||||
@@ -678,6 +682,9 @@ func TestConsentLedger(t *testing.T) {
|
||||
if replacement.ID() == earlier.ID() {
|
||||
t.Fatal("the earlier registrant's C1 survived the re-registration")
|
||||
}
|
||||
if replacement.RegistrationVersion() != registered.RegistrationVersion {
|
||||
t.Fatalf("replacement C1 registration version = %d, want %d", replacement.RegistrationVersion(), registered.RegistrationVersion)
|
||||
}
|
||||
|
||||
// A stale re-registration changes nothing and deletes nothing.
|
||||
if _, err := fixture.identity.store.Users().UpdateRegistration(ctx, changed); !errors.Is(err, outbound.ErrUserVersionConflict) {
|
||||
@@ -836,14 +843,26 @@ func (fixture consentFixture) newGrant(
|
||||
version domain.ConsentTextVersion,
|
||||
source domain.ConsentSource,
|
||||
at time.Time,
|
||||
registrationVersions ...int64,
|
||||
) domain.ConsentGrant {
|
||||
t.Helper()
|
||||
registrationVersion := int64(0)
|
||||
if source == domain.ConsentSourceRegistration {
|
||||
registrationVersion = 1
|
||||
}
|
||||
if len(registrationVersions) > 1 {
|
||||
t.Fatal("newGrant received more than one registration version")
|
||||
}
|
||||
if len(registrationVersions) == 1 {
|
||||
registrationVersion = registrationVersions[0]
|
||||
}
|
||||
text, err := fixture.store.ConsentTexts().Get(fixture.ctx, purpose, version)
|
||||
if err != nil {
|
||||
t.Fatalf("ConsentTexts().Get(%s, %s) error = %v", purpose, version, err)
|
||||
}
|
||||
grant, err := domain.NewConsentGrant(domain.ConsentGrantInput{
|
||||
SubjectID: subject, Purpose: purpose, TextVersion: text.Version(), TextHash: text.Hash(), Source: source, GrantedAt: at,
|
||||
SubjectID: subject, Purpose: purpose, TextVersion: text.Version(), TextHash: text.Hash(),
|
||||
Source: source, RegistrationVersion: registrationVersion, GrantedAt: at,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("NewConsentGrant() error = %v", err)
|
||||
|
||||
Reference in new issue
Block a user