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
10 changes: 10 additions & 0 deletions internal/gql/rechallenge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func TestRechallengePreflightAttachesCachedToken(t *testing.T) {

func TestRechallengeFullFlowOnElevatedError(t *testing.T) {
mutationHits := int32(0)
var openedURLs []string
var headerAfterRetry string

parker := http.NewServeMux()
Expand Down Expand Up @@ -125,6 +126,7 @@ func TestRechallengeFullFlowOnElevatedError(t *testing.T) {
runner := &rechallenge.Runner{
Client: &rechallenge.Client{APIHost: parkerSrv.URL, HTTP: parkerSrv.Client()},
TokenCache: cache,
OpenURL: func(url string) { openedURLs = append(openedURLs, url) },
Sleep: func(_ context.Context, _ time.Duration) error { return nil },
}
c := NewClient(Config{
Expand Down Expand Up @@ -154,6 +156,9 @@ func TestRechallengeFullFlowOnElevatedError(t *testing.T) {
if headerAfterRetry != "elev" {
t.Errorf("retry header = %q, want elev", headerAfterRetry)
}
if len(openedURLs) != 1 || openedURLs[0] != "https://example/v" {
t.Errorf("opened URLs = %q, want one verification URL", openedURLs)
}
}

func TestRechallengeSurfacesOriginalErrorOnFlowFailure(t *testing.T) {
Expand All @@ -172,6 +177,7 @@ func TestRechallengeSurfacesOriginalErrorOnFlowFailure(t *testing.T) {
runner := &rechallenge.Runner{
Client: &rechallenge.Client{APIHost: parker.URL, HTTP: parker.Client()},
TokenCache: cache,
OpenURL: func(string) { t.Error("failed session creation must not open a browser") },
Sleep: func(_ context.Context, _ time.Duration) error { return nil },
}
c := NewClient(Config{
Expand Down Expand Up @@ -228,6 +234,7 @@ func TestRechallengeUsesConfigInteractivityProvider(t *testing.T) {
runner := &rechallenge.Runner{
Client: &rechallenge.Client{APIHost: parkerSrv.URL, HTTP: parkerSrv.Client()},
TokenCache: cache,
OpenURL: func(string) {},
Sleep: func(_ context.Context, _ time.Duration) error { return nil },
}

Expand Down Expand Up @@ -302,6 +309,7 @@ func TestRechallengeSurfacesStepUpFailureReason(t *testing.T) {
Runner: &rechallenge.Runner{
Client: &rechallenge.Client{APIHost: parker.URL, HTTP: parker.Client()},
TokenCache: cache,
OpenURL: func(string) { t.Error("failed session creation must not open a browser") },
Sleep: func(context.Context, time.Duration) error { return nil },
},
Interactive: func() bool { return true },
Expand Down Expand Up @@ -356,6 +364,7 @@ func TestRechallengeFailureReasonCannotLeakToken(t *testing.T) {
APIHost: parker.URL, HTTP: parker.Client(), BearerToken: bearer,
},
TokenCache: cache,
OpenURL: func(string) { t.Error("failed session creation must not open a browser") },
Sleep: func(context.Context, time.Duration) error { return nil },
},
Interactive: func() bool { return true },
Expand Down Expand Up @@ -404,6 +413,7 @@ func TestRechallengeNonInteractiveReturnsPromptly(t *testing.T) {
Runner: &rechallenge.Runner{
Client: &rechallenge.Client{APIHost: parker.URL, HTTP: parker.Client()},
TokenCache: cache,
OpenURL: func(string) { t.Error("non-interactive flow must not open a browser") },
Sleep: func(ctx context.Context, _ time.Duration) error {
select {
case <-ctx.Done():
Expand Down
4 changes: 4 additions & 0 deletions internal/rechallenge/flow_noninteractive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func TestFlowNonInteractiveFailsFastInsteadOfPolling(t *testing.T) {
Tracker: tr,
TokenCache: newTestCache(),
Stdout: io.Discard,
OpenURL: func(string) { t.Error("non-interactive flow must not open a browser") },
Sleep: func(ctx context.Context, _ time.Duration) error {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -147,6 +148,7 @@ func TestFlowNonInteractiveWaitOptInStillPolls(t *testing.T) {
Tracker: &fakeTracker{},
TokenCache: newTestCache(),
Stdout: &out,
OpenURL: func(string) { t.Error("non-interactive wait must not open a browser") },
Sleep: func(context.Context, time.Duration) error { return nil },
}
tok, err := r.Run(context.Background(), RunInput{
Expand Down Expand Up @@ -190,6 +192,7 @@ func TestFlowRejectsUnusableDeadline(t *testing.T) {
Tracker: &fakeTracker{},
TokenCache: newTestCache(),
Stdout: io.Discard,
OpenURL: func(string) {},
Sleep: func(ctx context.Context, _ time.Duration) error {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -256,6 +259,7 @@ func TestFlowFloorsServerPollInterval(t *testing.T) {
Tracker: &fakeTracker{},
TokenCache: newTestCache(),
Stdout: io.Discard,
OpenURL: func(string) {},
Sleep: func(_ context.Context, d time.Duration) error {
mu.Lock()
slept = append(slept, d)
Expand Down
13 changes: 10 additions & 3 deletions internal/rechallenge/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (f *fakeTracker) Track(name string, _ map[string]any) {
func TestFlowUnsupportedVersion(t *testing.T) {
cache := newTestCache()
tr := &fakeTracker{}
r := &Runner{Tracker: tr, TokenCache: cache}
r := &Runner{Tracker: tr, TokenCache: cache, OpenURL: func(string) { t.Error("unsupported version must not open a browser") }}
_, err := r.Run(context.Background(), RunInput{
RequestedOperation: "doThing",
Extension: Extension{
Expand Down Expand Up @@ -75,8 +75,13 @@ func TestFlowHappyPathVerified(t *testing.T) {
Tracker: tr,
TokenCache: cache,
Stdout: &out,
OpenURL: func(string) { atomic.AddInt32(&openCalled, 1) },
Sleep: func(_ context.Context, _ time.Duration) error { return nil },
OpenURL: func(url string) {
atomic.AddInt32(&openCalled, 1)
if url != "https://example/v/c1" {
t.Errorf("OpenURL = %q, want verification URL", url)
}
},
Sleep: func(_ context.Context, _ time.Duration) error { return nil },
}

var diagnostics bytes.Buffer
Expand Down Expand Up @@ -146,6 +151,7 @@ func TestFlowTerminalCancelled(t *testing.T) {
Client: &Client{APIHost: srv.URL, HTTP: srv.Client()},
Tracker: &fakeTracker{},
TokenCache: newTestCache(),
OpenURL: func(string) {},
Sleep: func(_ context.Context, _ time.Duration) error { return nil },
}
_, err := r.Run(context.Background(), RunInput{
Expand Down Expand Up @@ -184,6 +190,7 @@ func TestFlowAbortedByContext(t *testing.T) {
Client: &Client{APIHost: srv.URL, HTTP: srv.Client()},
Tracker: &fakeTracker{},
TokenCache: newTestCache(),
OpenURL: func(string) {},
Sleep: func(ctx context.Context, _ time.Duration) error {
<-ctx.Done()
return ctx.Err()
Expand Down
1 change: 1 addition & 0 deletions internal/rechallenge/redact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func TestFlowRedactsStatusReason(t *testing.T) {
Tracker: &fakeTracker{},
TokenCache: newTestCache(),
Stdout: new(strings.Builder),
OpenURL: func(string) {},
Sleep: func(context.Context, time.Duration) error { return nil },
}
_, err := r.Run(context.Background(), RunInput{
Expand Down
Loading