feat(identity): confirm registration email atomically

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 09:12:15 +03:00
1 parent 8e7ce8d71c
commit fade4e76e4
75 files changed
+4188 -403

No files matched your search

@@ -71,17 +71,18 @@ func TestGrantAtRegistrationRecordsC1WithTheRegistrationSource(t *testing.T) {
harness := newHarness(t)
subject := uuid.New()
result, err := harness.service.GrantAtRegistration(t.Context(), harness.repositories, subject, harness.version(domain.ConsentPurposePersonalData))
result, err := harness.service.GrantAtRegistration(t.Context(), harness.repositories, subject, 1, harness.version(domain.ConsentPurposePersonalData))
if err != nil || !result.Created {
t.Fatalf("GrantAtRegistration() = %v, %v, want a new record", result.Created, err)
}
record := result.Record
if record.Purpose() != domain.ConsentPurposePersonalData || record.Source() != domain.ConsentSourceRegistration ||
record.RegistrationVersion() != 1 ||
record.SubjectID() != subject || !record.GrantedAt().Equal(clockStart) {
t.Fatalf("GrantAtRegistration() record = %s %s, want the registration C1 at the application clock", record.Purpose(), record.Source())
}
_, err = harness.service.GrantAtRegistration(t.Context(), harness.repositories, subject, "c1-1999-01-01")
_, err = harness.service.GrantAtRegistration(t.Context(), harness.repositories, subject, 1, "c1-1999-01-01")
if !errors.Is(err, consent.ErrStaleConsentText) {
t.Fatalf("GrantAtRegistration(outdated) error = %v, want ErrStaleConsentText", err)
}
@@ -315,7 +316,7 @@ func TestPurposesAreIndependent(t *testing.T) {
var result consent.GrantResult
var err error
if purpose == domain.ConsentPurposePersonalData {
result, err = harness.service.GrantAtRegistration(t.Context(), harness.repositories, subject, harness.version(purpose))
result, err = harness.service.GrantAtRegistration(t.Context(), harness.repositories, subject, 1, harness.version(purpose))
} else {
result, err = harness.service.GrantInSettings(t.Context(), harness.repositories, consent.SettingsGrantInput{
SubjectID: subject, Purpose: purpose, TextVersion: harness.version(purpose),
@@ -621,7 +622,8 @@ func (ledger *fakeLedger) Grant(_ context.Context, grant domain.ConsentGrant) (d
hash := grant.TextHash()
record, err := domain.RestoreConsentRecord(domain.StoredConsentRecord{
ID: grant.ID(), SubjectID: grant.SubjectID(), Purpose: string(grant.Purpose()), TextVersion: string(grant.TextVersion()),
TextHash: hash[:], Source: string(grant.Source()), State: string(domain.ConsentStateActive), GrantedAt: grant.GrantedAt(),
TextHash: hash[:], Source: string(grant.Source()), RegistrationVersion: grant.RegistrationVersion(),
State: string(domain.ConsentStateActive), GrantedAt: grant.GrantedAt(),
})
if err != nil {
return domain.ConsentRecord{}, false, err
@@ -674,6 +676,17 @@ func (ledger *fakeLedger) Current(_ context.Context, subjectID uuid.UUID, purpos
return domain.ConsentRecord{}, outbound.ErrConsentNotFound
}
func (ledger *fakeLedger) LockRegistration(_ context.Context, subjectID uuid.UUID, registrationVersion int64) (domain.ConsentRecord, error) {
for index := len(ledger.records) - 1; index >= 0; index-- {
if record := ledger.records[index]; record.SubjectID() == subjectID &&
record.Purpose() == domain.ConsentPurposePersonalData && record.Source() == domain.ConsentSourceRegistration &&
record.RegistrationVersion() == registrationVersion && record.State() == domain.ConsentStateActive {
return record, nil
}
}
return domain.ConsentRecord{}, outbound.ErrConsentNotFound
}
func (ledger *fakeLedger) CurrentContact(context.Context, uuid.UUID, uuid.UUID) ([]domain.ConsentRecord, error) {
panic("the consent usecase does not read C4")
}