protondrive: stop a call rejected during disconnect retrying without credentials
A call in flight when the remote was disconnected, and then rejected as unauthorised, was sent again with empty credentials. It now fails with the "not signed in" error instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
59f0f31b34
commit
db97ef7c8d
2 files changed
+22
No files matched your search
@@ -224,6 +224,10 @@ func (s *session) call(ctx context.Context, opts *rest.Opts, request, response a
|
||||
}
|
||||
}
|
||||
creds = s.current()
|
||||
if creds.UID == "" {
|
||||
// Signed out while the call was made.
|
||||
return resp, s.signInNeeded(errNotSignedIn)
|
||||
}
|
||||
return s.do(ctx, opts, request, response, &creds)
|
||||
}
|
||||
|
||||
|
||||
@@ -526,3 +526,21 @@ func TestLogout(t *testing.T) {
|
||||
old.adoptWait = 0
|
||||
assert.ErrorIs(t, authCall(context.Background(), old), errSessionExpired)
|
||||
}
|
||||
|
||||
func TestCallDuringLogout(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
srv := protontest.New(t)
|
||||
s, _, _ := newTestSession(t, srv)
|
||||
// The call is rejected only after the session has signed out.
|
||||
srv.Inject(protontest.Fault{Method: "GET", Pattern: "/tests/auth", Times: 1, Status: http.StatusUnauthorized, Delay: 500 * time.Millisecond})
|
||||
errc := make(chan error, 1)
|
||||
go func() { errc <- authCall(ctx, s) }()
|
||||
require.Eventually(t, func() bool { return srv.Requests()["GET /tests/auth"] == 1 }, 5*time.Second, 5*time.Millisecond)
|
||||
require.NoError(t, s.logout(ctx))
|
||||
|
||||
err := <-errc
|
||||
assert.ErrorIs(t, err, errNotSignedIn)
|
||||
assert.Equal(t, 1, srv.Requests()["GET /tests/auth"], "retried without credentials")
|
||||
assert.Zero(t, srv.Requests()[refreshRoute])
|
||||
}
|
||||
Reference in new issue
Block a user