From 9f5899d161eca3fde4e1e5533d09f1a94efabb41 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 2 Dec 2026 22:09:14 +0100 Subject: [PATCH] Treat the enterprise provider registration timeout as unavailable CredentialStore.getSession already continues without a session when the github-enterprise provider is not registered, but a host that contributes the provider and registers it only once an enterprise URI is set makes getSession time out instead. Treat that message the same way so GitHub.com sign-in and the Pull Requests view still start. --- src/github/credentials.ts | 9 ++++++- src/test/github/credentials.test.ts | 39 ++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/github/credentials.ts b/src/github/credentials.ts index 8d41071f82..83eef702c9 100644 --- a/src/github/credentials.ts +++ b/src/github/credentials.ts @@ -129,6 +129,13 @@ export interface CredentialStoreSessionsChangeEvent extends vscode.Authenticatio serverChanged: boolean; } +// Thrown by `vscode.authentication.getSession` when the enterprise provider is not registered. Some hosts +// contribute the provider but only register it once an enterprise URI is configured, which surfaces as the timeout. +const ENTERPRISE_PROVIDER_UNAVAILABLE_MESSAGES = [ + `No authentication provider '${AuthProvider.githubEnterprise}' is currently registered.`, + `Timed out waiting for authentication provider '${AuthProvider.githubEnterprise}' to register.`, +]; + export class CredentialStore extends Disposable { private static readonly ID = 'Authentication'; private _githubAPI: GitHub | undefined; @@ -693,7 +700,7 @@ export class CredentialStore extends Disposable { return { session, isNew: !!session, scopes: requireScopes ? scopes : SCOPES_OLD }; } catch (error) { if (authProviderId === AuthProvider.githubEnterprise && error instanceof Error - && error.message === `No authentication provider '${AuthProvider.githubEnterprise}' is currently registered.`) { + && ENTERPRISE_PROVIDER_UNAVAILABLE_MESSAGES.includes(error.message)) { Logger.appendLine('GitHub Enterprise authentication is unavailable. Set up GitHub Enterprise to sign in.', CredentialStore.ID); return { session: undefined, isNew: false, scopes }; } diff --git a/src/test/github/credentials.test.ts b/src/test/github/credentials.test.ts index 0b6592a714..a41b3aad44 100644 --- a/src/test/github/credentials.test.ts +++ b/src/test/github/credentials.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { strictEqual, deepStrictEqual } from 'assert'; +import { strictEqual, deepStrictEqual, rejects } from 'assert'; import { Octokit } from '@octokit/rest'; import { ApolloClient, ApolloLink, InMemoryCache } from 'apollo-boost'; import { createSandbox, match, SinonSandbox, SinonStub } from 'sinon'; @@ -403,6 +403,43 @@ describe('CredentialStore', function () { }); } + describe('GitHub Enterprise provider that is not registered', function () { + let credentialStore: CredentialStore; + let getSession: SinonStub; + + beforeEach(function () { + sinon.stub(process, 'env').value({ ...process.env, GITHUB_OAUTH_TOKEN: undefined }); + credentialStore = new CredentialStore(new MockTelemetry(), new MockExtensionContext()); + getSession = sinon.stub(vscode.authentication, 'getSession'); + getSession.withArgs(AuthProvider.github).resolves(createSession('dotcom-session', 'account', defaultScopes)); + }); + + afterEach(function () { + credentialStore.dispose(); + }); + + for (const message of [ + `No authentication provider '${AuthProvider.githubEnterprise}' is currently registered.`, + `Timed out waiting for authentication provider '${AuthProvider.githubEnterprise}' to register.`, + ]) { + it(`still signs in to GitHub.com when the enterprise lookup fails with "${message}"`, async function () { + getSession.withArgs(AuthProvider.githubEnterprise).rejects(new Error(message)); + + deepStrictEqual(await credentialStore.create(), { canceled: false, unavailable: false }); + strictEqual(credentialStore.isAuthenticated(AuthProvider.github), true); + strictEqual(credentialStore.isAuthenticated(AuthProvider.githubEnterprise), false); + }); + } + + it('does not hide enterprise errors with other messages', async function () { + getSession.withArgs(AuthProvider.githubEnterprise).rejects(new Error('Timed out waiting for authentication provider \'github\' to register.')); + await rejects(credentialStore.create(), /Timed out waiting for authentication provider 'github' to register/); + + getSession.withArgs(AuthProvider.githubEnterprise).rejects(new Error('Network down')); + await rejects(credentialStore.create(), /Network down/); + }); + }); + it('retries the current user request after a failure', async function () { const telemetry = new MockTelemetry(); const credentialStore = new CredentialStore(telemetry, new MockExtensionContext());