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
@@ -66,12 +66,12 @@ func (fixture consentGrantsFixture) grantInput(t *testing.T, subject uuid.UUID,
|
||||
|
||||
// registerC1 records the registration C1 of an existing account in its own
|
||||
// transaction.
|
||||
func (fixture consentGrantsFixture) registerC1(t *testing.T, subject uuid.UUID) domain.ConsentRecord {
|
||||
func (fixture consentGrantsFixture) registerC1(t *testing.T, user domain.User) domain.ConsentRecord {
|
||||
t.Helper()
|
||||
var result consent.GrantResult
|
||||
err := fixture.transactor.WithinTransaction(fixture.ctx, func(ctx context.Context, unit outbound.UnitOfWork) error {
|
||||
var err error
|
||||
result, err = fixture.service.GrantAtRegistration(ctx, unit, subject, fixture.currentVersion(t, domain.ConsentPurposePersonalData))
|
||||
result, err = fixture.service.GrantAtRegistration(ctx, unit, user.ID, user.RegistrationVersion, fixture.currentVersion(t, domain.ConsentPurposePersonalData))
|
||||
return err
|
||||
})
|
||||
if err != nil || !result.Created {
|
||||
@@ -170,7 +170,7 @@ func TestConsentGrants(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
registered, err = fixture.service.GrantAtRegistration(ctx, unit, user.ID, c1)
|
||||
registered, err = fixture.service.GrantAtRegistration(ctx, unit, user.ID, user.RegistrationVersion, c1)
|
||||
return err
|
||||
})
|
||||
if err != nil || !registered.Created {
|
||||
@@ -180,6 +180,7 @@ func TestConsentGrants(t *testing.T) {
|
||||
assertRowCount(ctx, t, pool, sessionsTable, 0)
|
||||
assertRowCount(ctx, t, pool, consentRecordsTable, 1)
|
||||
if record := registered.Record; record.SubjectID() != user.ID || record.Source() != domain.ConsentSourceRegistration ||
|
||||
record.RegistrationVersion() != user.RegistrationVersion ||
|
||||
record.TextVersion() != consentSecondC1Version || !record.GrantedAt().Equal(start) {
|
||||
t.Fatalf("registration C1 = %s %s %v, want the current text at the application time", record.Source(), record.TextVersion(), record.GrantedAt())
|
||||
}
|
||||
@@ -228,7 +229,7 @@ func TestConsentGrants(t *testing.T) {
|
||||
if err := unit.Users().Create(ctx, user); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fixture.service.GrantAtRegistration(ctx, unit, user.ID, c1); err != nil {
|
||||
if _, err := fixture.service.GrantAtRegistration(ctx, unit, user.ID, user.RegistrationVersion, c1); err != nil {
|
||||
return err
|
||||
}
|
||||
return errForcedRollback
|
||||
@@ -242,7 +243,7 @@ func TestConsentGrants(t *testing.T) {
|
||||
// A grant for a subject that has no account is refused by the ledger
|
||||
// and stores nothing.
|
||||
err = transactor.WithinTransaction(ctx, func(ctx context.Context, unit outbound.UnitOfWork) error {
|
||||
_, err := fixture.service.GrantAtRegistration(ctx, unit, uuid.New(), c1)
|
||||
_, err := fixture.service.GrantAtRegistration(ctx, unit, uuid.New(), 1, c1)
|
||||
return err
|
||||
})
|
||||
if !errors.Is(err, outbound.ErrUserNotFound) {
|
||||
@@ -379,30 +380,31 @@ func TestConsentGrants(t *testing.T) {
|
||||
reregister := func(t *testing.T, rawEmail string, grantFirst bool) (granted consent.GrantResult, earlier domain.ConsentRecord) {
|
||||
t.Helper()
|
||||
first := fixture.identity.createUser(t, rawEmail, domain.ScenarioCandidate, start.Add(-72*time.Hour))
|
||||
earlier = fixture.registerC1(t, first.ID)
|
||||
earlier = fixture.registerC1(t, first)
|
||||
changed, err := first.ReRegister(fixture.identity.registration(t, rawEmail, domain.ScenarioEmployer, start))
|
||||
if err != nil {
|
||||
t.Fatalf("ReRegister() error = %v", err)
|
||||
}
|
||||
version := fixture.currentVersion(t, domain.ConsentPurposePersonalData)
|
||||
err = transactor.WithinTransaction(ctx, func(ctx context.Context, unit outbound.UnitOfWork) error {
|
||||
grant := func() error {
|
||||
grant := func(registrationVersion int64) error {
|
||||
var err error
|
||||
granted, err = fixture.service.GrantAtRegistration(ctx, unit, first.ID, version)
|
||||
granted, err = fixture.service.GrantAtRegistration(ctx, unit, first.ID, registrationVersion, version)
|
||||
return err
|
||||
}
|
||||
if grantFirst {
|
||||
if err := grant(); err != nil {
|
||||
if err := grant(first.RegistrationVersion); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := unit.Users().UpdateRegistration(ctx, changed); err != nil {
|
||||
registered, err := unit.Users().UpdateRegistration(ctx, changed)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if grantFirst {
|
||||
return nil
|
||||
}
|
||||
return grant()
|
||||
return grant(registered.RegistrationVersion)
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("re-registration transaction error = %v", err)
|
||||
@@ -498,7 +500,7 @@ func TestConsentGrants(t *testing.T) {
|
||||
reset(t)
|
||||
user := fixture.identity.createUser(t, "restart@example.com", domain.ScenarioCandidate, start.Add(-72*time.Hour))
|
||||
grantedAt := map[uuid.UUID]time.Time{}
|
||||
c1 := fixture.registerC1(t, user.ID)
|
||||
c1 := fixture.registerC1(t, user)
|
||||
grantedAt[c1.ID()] = fixture.now()
|
||||
fixture.advance(time.Minute)
|
||||
c2 := fixture.grant(t, fixture.grantInput(t, user.ID, domain.ConsentPurposePublication))
|
||||
|
||||
Reference in new issue
Block a user