Fixes #7550 Part of #7406 Part of #7475
This commit is contained in:
parent
e3eb37fe34
commit
de9c06129b
28
sa/model.go
28
sa/model.go
|
|
@ -1324,10 +1324,10 @@ func newPBFromIdentifierModel(id identifierModel) (*sapb.Identifier, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newIdentifierModelsFromPB(pb []*sapb.Identifier) ([]identifierModel, error) {
|
func newIdentifierModelsFromPB(pbs []*sapb.Identifier) ([]identifierModel, error) {
|
||||||
var ids []identifierModel
|
ids := make([]identifierModel, 0, len(pbs))
|
||||||
for _, p := range pb {
|
for _, pb := range pbs {
|
||||||
id, err := newIdentifierModelFromPB(p)
|
id, err := newIdentifierModelFromPB(pb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1337,24 +1337,26 @@ func newIdentifierModelsFromPB(pb []*sapb.Identifier) ([]identifierModel, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPBFromIdentifierModels(ids []identifierModel) (*sapb.Identifiers, error) {
|
func newPBFromIdentifierModels(ids []identifierModel) (*sapb.Identifiers, error) {
|
||||||
var pb []*sapb.Identifier
|
pbs := make([]*sapb.Identifier, 0, len(ids))
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
p, err := newPBFromIdentifierModel(id)
|
pb, err := newPBFromIdentifierModel(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pb = append(pb, p)
|
pbs = append(pbs, pb)
|
||||||
}
|
}
|
||||||
return &sapb.Identifiers{Identifiers: pb}, nil
|
return &sapb.Identifiers{Identifiers: pbs}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// pausedModel represents a row in the paused table. The pausedAt and unpausedAt
|
// pausedModel represents a row in the paused table. It contains the
|
||||||
// fields are pointers because they are NULL-able columns. Valid states are:
|
// registrationID of the paused account, the time the (account, identifier) pair
|
||||||
// - Identifier paused: pausedAt is non-NULL, unpausedAt is NULL
|
// was paused, and the time the pair was unpaused. The UnpausedAt field is
|
||||||
// - Identifier unpaused: pausedAt is non-NULL, unpausedAt is non-NULL
|
// nullable because the pair may not have been unpaused yet. A pair is
|
||||||
|
// considered paused if there is a matching row in the paused table with a NULL
|
||||||
|
// UnpausedAt time.
|
||||||
type pausedModel struct {
|
type pausedModel struct {
|
||||||
identifierModel
|
identifierModel
|
||||||
RegistrationID int64 `db:"registrationID"`
|
RegistrationID int64 `db:"registrationID"`
|
||||||
PausedAt *time.Time `db:"pausedAt"`
|
PausedAt time.Time `db:"pausedAt"`
|
||||||
UnpausedAt *time.Time `db:"unpausedAt"`
|
UnpausedAt *time.Time `db:"unpausedAt"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
7
sa/sa.go
7
sa/sa.go
|
|
@ -1358,10 +1358,9 @@ func (ssa *SQLStorageAuthority) PauseIdentifiers(ctx context.Context, req *sapb.
|
||||||
|
|
||||||
case err != nil && errors.Is(err, sql.ErrNoRows):
|
case err != nil && errors.Is(err, sql.ErrNoRows):
|
||||||
// Not currently or previously paused, insert a new pause record.
|
// Not currently or previously paused, insert a new pause record.
|
||||||
pausedAt := ssa.clk.Now().Truncate(time.Second)
|
|
||||||
err = tx.Insert(ctx, &pausedModel{
|
err = tx.Insert(ctx, &pausedModel{
|
||||||
RegistrationID: req.RegistrationID,
|
RegistrationID: req.RegistrationID,
|
||||||
PausedAt: &pausedAt,
|
PausedAt: ssa.clk.Now().Truncate(time.Second),
|
||||||
identifierModel: identifierModel{
|
identifierModel: identifierModel{
|
||||||
Type: identifier.Type,
|
Type: identifier.Type,
|
||||||
Value: identifier.Value,
|
Value: identifier.Value,
|
||||||
|
|
@ -1379,12 +1378,12 @@ func (ssa *SQLStorageAuthority) PauseIdentifiers(ctx context.Context, req *sapb.
|
||||||
// Identifier is already paused.
|
// Identifier is already paused.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
case entry.UnpausedAt.After(*entry.PausedAt):
|
case entry.UnpausedAt.After(entry.PausedAt):
|
||||||
// Previously paused (and unpaused), repause the identifier.
|
// Previously paused (and unpaused), repause the identifier.
|
||||||
_, err := tx.ExecContext(ctx, `
|
_, err := tx.ExecContext(ctx, `
|
||||||
UPDATE paused
|
UPDATE paused
|
||||||
SET pausedAt = ?,
|
SET pausedAt = ?,
|
||||||
unpausedAt = NULL
|
unpausedAt = NULL
|
||||||
WHERE
|
WHERE
|
||||||
registrationID = ? AND
|
registrationID = ? AND
|
||||||
identifierType = ? AND
|
identifierType = ? AND
|
||||||
|
|
|
||||||
546
sa/sa_test.go
546
sa/sa_test.go
|
|
@ -4316,83 +4316,76 @@ func TestUnpauseAccount(t *testing.T) {
|
||||||
sa, _, cleanUp := initSA(t)
|
sa, _, cleanUp := initSA(t)
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
ptrTime := func(t time.Time) *time.Time {
|
tests := []struct {
|
||||||
return &t
|
name string
|
||||||
}
|
|
||||||
|
|
||||||
type args struct {
|
|
||||||
state []pausedModel
|
state []pausedModel
|
||||||
req *sapb.RegistrationID
|
req *sapb.RegistrationID
|
||||||
}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args args
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "UnpauseAccount with no paused identifiers",
|
name: "UnpauseAccount with no paused identifiers",
|
||||||
args: args{
|
state: nil,
|
||||||
state: nil,
|
req: &sapb.RegistrationID{Id: 1},
|
||||||
req: &sapb.RegistrationID{Id: 1},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "UnpauseAccount with one paused identifier",
|
name: "UnpauseAccount with one paused identifier",
|
||||||
args: args{
|
state: []pausedModel{
|
||||||
state: []pausedModel{
|
{
|
||||||
{
|
RegistrationID: 1,
|
||||||
RegistrationID: 1,
|
identifierModel: identifierModel{
|
||||||
identifierModel: identifierModel{
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
Value: "example.com",
|
||||||
Value: "example.com",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
},
|
},
|
||||||
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
},
|
},
|
||||||
req: &sapb.RegistrationID{Id: 1},
|
|
||||||
},
|
},
|
||||||
|
req: &sapb.RegistrationID{Id: 1},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "UnpauseAccount with multiple paused identifiers",
|
name: "UnpauseAccount with multiple paused identifiers",
|
||||||
args: args{
|
state: []pausedModel{
|
||||||
state: []pausedModel{
|
{
|
||||||
{
|
RegistrationID: 1,
|
||||||
RegistrationID: 1,
|
identifierModel: identifierModel{
|
||||||
identifierModel: identifierModel{
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
Value: "example.com",
|
||||||
Value: "example.com",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.net",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.org",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
},
|
},
|
||||||
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
RegistrationID: 1,
|
||||||
|
identifierModel: identifierModel{
|
||||||
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
|
Value: "example.net",
|
||||||
|
},
|
||||||
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
RegistrationID: 1,
|
||||||
|
identifierModel: identifierModel{
|
||||||
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
|
Value: "example.org",
|
||||||
|
},
|
||||||
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
},
|
},
|
||||||
req: &sapb.RegistrationID{Id: 1},
|
|
||||||
},
|
},
|
||||||
|
req: &sapb.RegistrationID{Id: 1},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
// Drop all rows from the paused table.
|
||||||
|
_, err := sa.dbMap.ExecContext(ctx, "TRUNCATE TABLE paused")
|
||||||
|
test.AssertNotError(t, err, "truncating paused table")
|
||||||
|
}()
|
||||||
|
|
||||||
// Setup table state.
|
// Setup table state.
|
||||||
for _, state := range tt.args.state {
|
for _, state := range tt.state {
|
||||||
err := sa.dbMap.Insert(ctx, &state)
|
err := sa.dbMap.Insert(ctx, &state)
|
||||||
test.AssertNotError(t, err, "inserting test identifier")
|
test.AssertNotError(t, err, "inserting test identifier")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := sa.UnpauseAccount(ctx, tt.args.req)
|
_, err := sa.UnpauseAccount(ctx, tt.req)
|
||||||
test.AssertNotError(t, err, "Unexpected error for UnpauseAccount()")
|
test.AssertNotError(t, err, "Unexpected error for UnpauseAccount()")
|
||||||
|
|
||||||
// Count the number of paused identifiers.
|
// Count the number of paused identifiers.
|
||||||
|
|
@ -4401,14 +4394,10 @@ func TestUnpauseAccount(t *testing.T) {
|
||||||
ctx,
|
ctx,
|
||||||
&count,
|
&count,
|
||||||
"SELECT COUNT(*) FROM paused WHERE registrationID = ? AND unpausedAt IS NULL",
|
"SELECT COUNT(*) FROM paused WHERE registrationID = ? AND unpausedAt IS NULL",
|
||||||
tt.args.req.Id,
|
tt.req.Id,
|
||||||
)
|
)
|
||||||
test.AssertNotError(t, err, "SELECT COUNT(*) failed")
|
test.AssertNotError(t, err, "SELECT COUNT(*) failed")
|
||||||
test.AssertEquals(t, count, 0)
|
test.AssertEquals(t, count, 0)
|
||||||
|
|
||||||
// Drop all rows from the paused table.
|
|
||||||
_, err = sa.dbMap.ExecContext(ctx, "TRUNCATE TABLE paused")
|
|
||||||
test.AssertNotError(t, err, "Truncate table paused failed")
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4424,26 +4413,21 @@ func TestPauseIdentifiers(t *testing.T) {
|
||||||
return &t
|
return &t
|
||||||
}
|
}
|
||||||
|
|
||||||
type args struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
state []pausedModel
|
state []pausedModel
|
||||||
req *sapb.PauseRequest
|
req *sapb.PauseRequest
|
||||||
}
|
want *sapb.PauseIdentifiersResponse
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args args
|
|
||||||
want *sapb.PauseIdentifiersResponse
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "An identifier which is not now or previously paused",
|
name: "An identifier which is not now or previously paused",
|
||||||
args: args{
|
state: nil,
|
||||||
state: nil,
|
req: &sapb.PauseRequest{
|
||||||
req: &sapb.PauseRequest{
|
RegistrationID: 1,
|
||||||
RegistrationID: 1,
|
Identifiers: []*sapb.Identifier{
|
||||||
Identifiers: []*sapb.Identifier{
|
{
|
||||||
{
|
Type: string(identifier.DNS),
|
||||||
Type: string(identifier.DNS),
|
Value: "example.com",
|
||||||
Value: "example.com",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -4454,25 +4438,23 @@ func TestPauseIdentifiers(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "One unpaused entry which was previously paused",
|
name: "One unpaused entry which was previously paused",
|
||||||
args: args{
|
state: []pausedModel{
|
||||||
state: []pausedModel{
|
{
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.com",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
UnpausedAt: ptrTime(sa.clk.Now().Add(-time.Minute)),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
req: &sapb.PauseRequest{
|
|
||||||
RegistrationID: 1,
|
RegistrationID: 1,
|
||||||
Identifiers: []*sapb.Identifier{
|
identifierModel: identifierModel{
|
||||||
{
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Type: string(identifier.DNS),
|
Value: "example.com",
|
||||||
Value: "example.com",
|
},
|
||||||
},
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
|
UnpausedAt: ptrTime(sa.clk.Now().Add(-time.Minute)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
req: &sapb.PauseRequest{
|
||||||
|
RegistrationID: 1,
|
||||||
|
Identifiers: []*sapb.Identifier{
|
||||||
|
{
|
||||||
|
Type: string(identifier.DNS),
|
||||||
|
Value: "example.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -4483,24 +4465,22 @@ func TestPauseIdentifiers(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "An identifier which is currently paused",
|
name: "An identifier which is currently paused",
|
||||||
args: args{
|
state: []pausedModel{
|
||||||
state: []pausedModel{
|
{
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.com",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
req: &sapb.PauseRequest{
|
|
||||||
RegistrationID: 1,
|
RegistrationID: 1,
|
||||||
Identifiers: []*sapb.Identifier{
|
identifierModel: identifierModel{
|
||||||
{
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Type: string(identifier.DNS),
|
Value: "example.com",
|
||||||
Value: "example.com",
|
},
|
||||||
},
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
req: &sapb.PauseRequest{
|
||||||
|
RegistrationID: 1,
|
||||||
|
Identifiers: []*sapb.Identifier{
|
||||||
|
{
|
||||||
|
Type: string(identifier.DNS),
|
||||||
|
Value: "example.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -4511,42 +4491,40 @@ func TestPauseIdentifiers(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Two previously paused entries and one new entry",
|
name: "Two previously paused entries and one new entry",
|
||||||
args: args{
|
state: []pausedModel{
|
||||||
state: []pausedModel{
|
{
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.com",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
UnpausedAt: ptrTime(sa.clk.Now().Add(-time.Minute)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.net",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
UnpausedAt: ptrTime(sa.clk.Now().Add(-time.Minute)),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
req: &sapb.PauseRequest{
|
|
||||||
RegistrationID: 1,
|
RegistrationID: 1,
|
||||||
Identifiers: []*sapb.Identifier{
|
identifierModel: identifierModel{
|
||||||
{
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Type: string(identifier.DNS),
|
Value: "example.com",
|
||||||
Value: "example.com",
|
},
|
||||||
},
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
{
|
UnpausedAt: ptrTime(sa.clk.Now().Add(-time.Minute)),
|
||||||
Type: string(identifier.DNS),
|
},
|
||||||
Value: "example.net",
|
{
|
||||||
},
|
RegistrationID: 1,
|
||||||
{
|
identifierModel: identifierModel{
|
||||||
Type: string(identifier.DNS),
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Value: "example.org",
|
Value: "example.net",
|
||||||
},
|
},
|
||||||
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
|
UnpausedAt: ptrTime(sa.clk.Now().Add(-time.Minute)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
req: &sapb.PauseRequest{
|
||||||
|
RegistrationID: 1,
|
||||||
|
Identifiers: []*sapb.Identifier{
|
||||||
|
{
|
||||||
|
Type: string(identifier.DNS),
|
||||||
|
Value: "example.com",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: string(identifier.DNS),
|
||||||
|
Value: "example.net",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: string(identifier.DNS),
|
||||||
|
Value: "example.org",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -4558,20 +4536,22 @@ func TestPauseIdentifiers(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
// Drop all rows from the paused table.
|
||||||
|
_, err := sa.dbMap.ExecContext(ctx, "TRUNCATE TABLE paused")
|
||||||
|
test.AssertNotError(t, err, "Truncate table paused failed")
|
||||||
|
}()
|
||||||
|
|
||||||
// Setup table state.
|
// Setup table state.
|
||||||
for _, state := range tt.args.state {
|
for _, state := range tt.state {
|
||||||
err := sa.dbMap.Insert(ctx, &state)
|
err := sa.dbMap.Insert(ctx, &state)
|
||||||
test.AssertNotError(t, err, "inserting test identifier")
|
test.AssertNotError(t, err, "inserting test identifier")
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := sa.PauseIdentifiers(ctx, tt.args.req)
|
got, err := sa.PauseIdentifiers(ctx, tt.req)
|
||||||
test.AssertNotError(t, err, "Unexpected error for PauseIdentifiers()")
|
test.AssertNotError(t, err, "Unexpected error for PauseIdentifiers()")
|
||||||
test.AssertEquals(t, got.Paused, tt.want.Paused)
|
test.AssertEquals(t, got.Paused, tt.want.Paused)
|
||||||
test.AssertEquals(t, got.Repaused, tt.want.Repaused)
|
test.AssertEquals(t, got.Repaused, tt.want.Repaused)
|
||||||
|
|
||||||
// Drop all rows from the paused table.
|
|
||||||
_, err = sa.dbMap.ExecContext(ctx, "TRUNCATE TABLE paused")
|
|
||||||
test.AssertNotError(t, err, "Truncate table paused failed")
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4587,53 +4567,46 @@ func TestCheckIdentifiersPaused(t *testing.T) {
|
||||||
return &t
|
return &t
|
||||||
}
|
}
|
||||||
|
|
||||||
type args struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
state []pausedModel
|
state []pausedModel
|
||||||
req *sapb.PauseRequest
|
req *sapb.PauseRequest
|
||||||
}
|
want *sapb.Identifiers
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args args
|
|
||||||
want *sapb.Identifiers
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "No paused identifiers",
|
name: "No paused identifiers",
|
||||||
args: args{
|
state: nil,
|
||||||
state: nil,
|
req: &sapb.PauseRequest{
|
||||||
req: &sapb.PauseRequest{
|
RegistrationID: 1,
|
||||||
RegistrationID: 1,
|
Identifiers: []*sapb.Identifier{
|
||||||
Identifiers: []*sapb.Identifier{
|
{
|
||||||
{
|
Type: string(identifier.DNS),
|
||||||
Type: string(identifier.DNS),
|
Value: "example.com",
|
||||||
Value: "example.com",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: &sapb.Identifiers{
|
want: &sapb.Identifiers{
|
||||||
Identifiers: nil,
|
Identifiers: []*sapb.Identifier{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "One paused identifier",
|
name: "One paused identifier",
|
||||||
args: args{
|
state: []pausedModel{
|
||||||
state: []pausedModel{
|
{
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.com",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
req: &sapb.PauseRequest{
|
|
||||||
RegistrationID: 1,
|
RegistrationID: 1,
|
||||||
Identifiers: []*sapb.Identifier{
|
identifierModel: identifierModel{
|
||||||
{
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Type: string(identifier.DNS),
|
Value: "example.com",
|
||||||
Value: "example.com",
|
},
|
||||||
},
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
req: &sapb.PauseRequest{
|
||||||
|
RegistrationID: 1,
|
||||||
|
Identifiers: []*sapb.Identifier{
|
||||||
|
{
|
||||||
|
Type: string(identifier.DNS),
|
||||||
|
Value: "example.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -4648,49 +4621,47 @@ func TestCheckIdentifiersPaused(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Two paused identifiers, one unpaused",
|
name: "Two paused identifiers, one unpaused",
|
||||||
args: args{
|
state: []pausedModel{
|
||||||
state: []pausedModel{
|
{
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.com",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.net",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.org",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
UnpausedAt: ptrTime(sa.clk.Now().Add(-time.Minute)),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
req: &sapb.PauseRequest{
|
|
||||||
RegistrationID: 1,
|
RegistrationID: 1,
|
||||||
Identifiers: []*sapb.Identifier{
|
identifierModel: identifierModel{
|
||||||
{
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Type: string(identifier.DNS),
|
Value: "example.com",
|
||||||
Value: "example.com",
|
},
|
||||||
},
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
{
|
},
|
||||||
Type: string(identifier.DNS),
|
{
|
||||||
Value: "example.net",
|
RegistrationID: 1,
|
||||||
},
|
identifierModel: identifierModel{
|
||||||
{
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Type: string(identifier.DNS),
|
Value: "example.net",
|
||||||
Value: "example.org",
|
},
|
||||||
},
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
RegistrationID: 1,
|
||||||
|
identifierModel: identifierModel{
|
||||||
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
|
Value: "example.org",
|
||||||
|
},
|
||||||
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
|
UnpausedAt: ptrTime(sa.clk.Now().Add(-time.Minute)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
req: &sapb.PauseRequest{
|
||||||
|
RegistrationID: 1,
|
||||||
|
Identifiers: []*sapb.Identifier{
|
||||||
|
{
|
||||||
|
Type: string(identifier.DNS),
|
||||||
|
Value: "example.com",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: string(identifier.DNS),
|
||||||
|
Value: "example.net",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: string(identifier.DNS),
|
||||||
|
Value: "example.org",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -4710,19 +4681,21 @@ func TestCheckIdentifiersPaused(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
// Drop all rows from the paused table.
|
||||||
|
_, err := sa.dbMap.ExecContext(ctx, "TRUNCATE TABLE paused")
|
||||||
|
test.AssertNotError(t, err, "Truncate table paused failed")
|
||||||
|
}()
|
||||||
|
|
||||||
// Setup table state.
|
// Setup table state.
|
||||||
for _, state := range tt.args.state {
|
for _, state := range tt.state {
|
||||||
err := sa.dbMap.Insert(ctx, &state)
|
err := sa.dbMap.Insert(ctx, &state)
|
||||||
test.AssertNotError(t, err, "inserting test identifier")
|
test.AssertNotError(t, err, "inserting test identifier")
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := sa.CheckIdentifiersPaused(ctx, tt.args.req)
|
got, err := sa.CheckIdentifiersPaused(ctx, tt.req)
|
||||||
test.AssertNotError(t, err, "Unexpected error for PauseIdentifiers()")
|
test.AssertNotError(t, err, "Unexpected error for PauseIdentifiers()")
|
||||||
test.AssertDeepEquals(t, got.Identifiers, tt.want.Identifiers)
|
test.AssertDeepEquals(t, got.Identifiers, tt.want.Identifiers)
|
||||||
|
|
||||||
// Drop all rows from the paused table.
|
|
||||||
_, err = sa.dbMap.ExecContext(ctx, "TRUNCATE TABLE paused")
|
|
||||||
test.AssertNotError(t, err, "Truncate table paused failed")
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4738,40 +4711,33 @@ func TestGetPausedIdentifiers(t *testing.T) {
|
||||||
return &t
|
return &t
|
||||||
}
|
}
|
||||||
|
|
||||||
type args struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
state []pausedModel
|
state []pausedModel
|
||||||
req *sapb.RegistrationID
|
req *sapb.RegistrationID
|
||||||
}
|
want *sapb.Identifiers
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args args
|
|
||||||
want *sapb.Identifiers
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "No paused identifiers",
|
name: "No paused identifiers",
|
||||||
args: args{
|
state: nil,
|
||||||
state: nil,
|
req: &sapb.RegistrationID{Id: 1},
|
||||||
req: &sapb.RegistrationID{Id: 1},
|
|
||||||
},
|
|
||||||
want: &sapb.Identifiers{
|
want: &sapb.Identifiers{
|
||||||
Identifiers: nil,
|
Identifiers: []*sapb.Identifier{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "One paused identifier",
|
name: "One paused identifier",
|
||||||
args: args{
|
state: []pausedModel{
|
||||||
state: []pausedModel{
|
{
|
||||||
{
|
RegistrationID: 1,
|
||||||
RegistrationID: 1,
|
identifierModel: identifierModel{
|
||||||
identifierModel: identifierModel{
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
Value: "example.com",
|
||||||
Value: "example.com",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
},
|
},
|
||||||
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
},
|
},
|
||||||
req: &sapb.RegistrationID{Id: 1},
|
|
||||||
},
|
},
|
||||||
|
req: &sapb.RegistrationID{Id: 1},
|
||||||
want: &sapb.Identifiers{
|
want: &sapb.Identifiers{
|
||||||
Identifiers: []*sapb.Identifier{
|
Identifiers: []*sapb.Identifier{
|
||||||
{
|
{
|
||||||
|
|
@ -4783,36 +4749,34 @@ func TestGetPausedIdentifiers(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Two paused identifiers, one unpaused",
|
name: "Two paused identifiers, one unpaused",
|
||||||
args: args{
|
state: []pausedModel{
|
||||||
state: []pausedModel{
|
{
|
||||||
{
|
RegistrationID: 1,
|
||||||
RegistrationID: 1,
|
identifierModel: identifierModel{
|
||||||
identifierModel: identifierModel{
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
Value: "example.com",
|
||||||
Value: "example.com",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.net",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
RegistrationID: 1,
|
|
||||||
identifierModel: identifierModel{
|
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
|
||||||
Value: "example.org",
|
|
||||||
},
|
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
|
||||||
UnpausedAt: ptrTime(sa.clk.Now().Add(-time.Minute)),
|
|
||||||
},
|
},
|
||||||
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
RegistrationID: 1,
|
||||||
|
identifierModel: identifierModel{
|
||||||
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
|
Value: "example.net",
|
||||||
|
},
|
||||||
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
RegistrationID: 1,
|
||||||
|
identifierModel: identifierModel{
|
||||||
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
|
Value: "example.org",
|
||||||
|
},
|
||||||
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
|
UnpausedAt: ptrTime(sa.clk.Now().Add(-time.Minute)),
|
||||||
},
|
},
|
||||||
req: &sapb.RegistrationID{Id: 1},
|
|
||||||
},
|
},
|
||||||
|
req: &sapb.RegistrationID{Id: 1},
|
||||||
want: &sapb.Identifiers{
|
want: &sapb.Identifiers{
|
||||||
Identifiers: []*sapb.Identifier{
|
Identifiers: []*sapb.Identifier{
|
||||||
{
|
{
|
||||||
|
|
@ -4829,19 +4793,21 @@ func TestGetPausedIdentifiers(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
// Drop all rows from the paused table.
|
||||||
|
_, err := sa.dbMap.ExecContext(ctx, "TRUNCATE TABLE paused")
|
||||||
|
test.AssertNotError(t, err, "Truncate table paused failed")
|
||||||
|
}()
|
||||||
|
|
||||||
// Setup table state.
|
// Setup table state.
|
||||||
for _, state := range tt.args.state {
|
for _, state := range tt.state {
|
||||||
err := sa.dbMap.Insert(ctx, &state)
|
err := sa.dbMap.Insert(ctx, &state)
|
||||||
test.AssertNotError(t, err, "inserting test identifier")
|
test.AssertNotError(t, err, "inserting test identifier")
|
||||||
}
|
}
|
||||||
|
|
||||||
got, err := sa.GetPausedIdentifiers(ctx, tt.args.req)
|
got, err := sa.GetPausedIdentifiers(ctx, tt.req)
|
||||||
test.AssertNotError(t, err, "Unexpected error for PauseIdentifiers()")
|
test.AssertNotError(t, err, "Unexpected error for PauseIdentifiers()")
|
||||||
test.AssertDeepEquals(t, got.Identifiers, tt.want.Identifiers)
|
test.AssertDeepEquals(t, got.Identifiers, tt.want.Identifiers)
|
||||||
|
|
||||||
// Drop all rows from the paused table.
|
|
||||||
_, err = sa.dbMap.ExecContext(ctx, "TRUNCATE TABLE paused")
|
|
||||||
test.AssertNotError(t, err, "Truncate table paused failed")
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4853,10 +4819,6 @@ func TestGetPausedIdentifiersOnlyUnpausesOneAccount(t *testing.T) {
|
||||||
sa, _, cleanUp := initSA(t)
|
sa, _, cleanUp := initSA(t)
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
ptrTime := func(t time.Time) *time.Time {
|
|
||||||
return &t
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert two paused identifiers for two different accounts.
|
// Insert two paused identifiers for two different accounts.
|
||||||
err := sa.dbMap.Insert(ctx, &pausedModel{
|
err := sa.dbMap.Insert(ctx, &pausedModel{
|
||||||
RegistrationID: 1,
|
RegistrationID: 1,
|
||||||
|
|
@ -4864,7 +4826,7 @@ func TestGetPausedIdentifiersOnlyUnpausesOneAccount(t *testing.T) {
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Value: "example.com",
|
Value: "example.com",
|
||||||
},
|
},
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
})
|
})
|
||||||
test.AssertNotError(t, err, "inserting test identifier")
|
test.AssertNotError(t, err, "inserting test identifier")
|
||||||
|
|
||||||
|
|
@ -4874,7 +4836,7 @@ func TestGetPausedIdentifiersOnlyUnpausesOneAccount(t *testing.T) {
|
||||||
Type: identifierTypeToUint[string(identifier.DNS)],
|
Type: identifierTypeToUint[string(identifier.DNS)],
|
||||||
Value: "example.net",
|
Value: "example.net",
|
||||||
},
|
},
|
||||||
PausedAt: ptrTime(sa.clk.Now().Add(-time.Hour)),
|
PausedAt: sa.clk.Now().Add(-time.Hour),
|
||||||
})
|
})
|
||||||
test.AssertNotError(t, err, "inserting test identifier")
|
test.AssertNotError(t, err, "inserting test identifier")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue