Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ linters:

exclusions:
rules:
# gosec finds G703 (a path from tainted input) with a taint analysis
# whose result changes from run to run, with the same code and the
# same version (#186). So nolintlint sometimes reports a G703
# directive as unused. Only that report is off, only for a directive
# that names G703 alone; any other unused directive is still
# reported, and gosec still reports a G703 without a directive.
- linters:
- nolintlint
text: '^directive `//nolint:gosec // G703: [^`]+` is unused for linter "gosec"$'
# Code in cmd/ may print. Only the rules about printing and logging
# (their messages start with "library code must not") are off there.
- path: ^cmd/
Expand Down
7 changes: 7 additions & 0 deletions internal/approval/approvaltest/approver.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ func (a *Approver) WaitEnded(n int, timeout time.Duration) ([]Ended, error) {
return a.Ended(), err
}

// WaitAlarms waits until at least n alarms went out, and returns them. It
// fails after timeout.
func (a *Approver) WaitAlarms(n int, timeout time.Duration) ([]approval.Alarm, error) {
err := a.wait(func() bool { return len(a.alarms) >= n }, timeout)
return a.Alarms(), err
}

// WaitRunning waits until Run runs. It fails after timeout.
func (a *Approver) WaitRunning(timeout time.Duration) error {
return a.wait(func() bool { return a.answer != nil }, timeout)
Expand Down
20 changes: 17 additions & 3 deletions internal/broker/standinguse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func TestStandingOldToken(t *testing.T) {
func TestStandingOutsideWindow(t *testing.T) {
e, tok0, id := useEnv(t)
e.clock.Advance(3 * time.Hour) // 15:00
e.waitMissedAlarm()
for range 2 {
res, _ := e.useToken("laptop", tok0)
mustStatus(t, res, http.StatusForbidden)
Expand Down Expand Up @@ -451,22 +452,35 @@ func TestStandingForeignToken(t *testing.T) {
func TestStandingOutsideWindowAlarmFails(t *testing.T) {
e, tok0, id := useEnv(t)
e.clock.Advance(3 * time.Hour) // 15:00
e.waitMissedAlarm()
e.approver.FailAlarm(errors.New("made-up: the alarm cannot be sent"))
res, _ := e.useToken("laptop", tok0)
mustStatus(t, res, http.StatusForbidden)
if n := len(e.approver.Alarms()); n != 0 {
t.Fatalf("%d alarms went out", n)
if n := len(e.approver.Alarms()); n != 1 {
t.Fatalf("%d alarms went out, want only the missed-window alarm", n)
}
e.approver.FailAlarm(nil)
for range 2 {
res, _ = e.useToken("laptop", tok0)
mustStatus(t, res, http.StatusForbidden)
}
if as := e.approver.Alarms(); len(as) != 1 || as[0].Cause != audit.AlarmOutsideWindow || as[0].GrantID != id {
if as := e.approver.Alarms(); len(as) != 2 || as[1].Cause != audit.AlarmOutsideWindow || as[1].GrantID != id {
t.Errorf("the alarms: %+v", as)
}
}

// waitMissedAlarm waits for the alarm of the window of 11:00-13:00 of
// useEnv, after the clock went past 13:00 with no use in it. The core
// sends it from its own goroutine, at a time that the test does not
// control; a test that counts alarms waits for it first (#186).
func (e *env) waitMissedAlarm() {
e.t.Helper()
as, err := e.approver.WaitAlarms(1, waitLimit)
if err != nil || len(as) != 1 || as[0].Cause != audit.AlarmMissedWindow {
e.t.Fatalf("the missed-window alarm: %+v, %v", as, err)
}
}

// TestStandingBeforeStart: a valid token before the start of the grant is
// denied, with an outside_window alarm, and the grant stays.
func TestStandingBeforeStart(t *testing.T) {
Expand Down
Loading