From 375be863b8fc08f47ab4e58921f2b141038a38db Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:45:20 +0000 Subject: [PATCH] chore: refine oauth token tests and warnings Co-authored-by: samanhappy <2755122+samanhappy@users.noreply.github.com> --- src/services/mcpOAuthProvider.ts | 8 ++------ tests/services/mcpOAuthProvider.test.ts | 13 +++++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/services/mcpOAuthProvider.ts b/src/services/mcpOAuthProvider.ts index a69d5e6..9870e52 100644 --- a/src/services/mcpOAuthProvider.ts +++ b/src/services/mcpOAuthProvider.ts @@ -295,7 +295,7 @@ export class MCPHubOAuthProvider implements OAuthClientProvider { /** * Get stored OAuth tokens */ - async tokens(): Promise { + tokens(): OAuthTokens | undefined | Promise { return this.getValidTokens(); } @@ -374,10 +374,6 @@ export class MCPHubOAuthProvider implements OAuthClientProvider { const { accessTokenExpiresAt } = oauth; if (!accessTokenExpiresAt) return undefined; if (typeof accessTokenExpiresAt === 'number') return accessTokenExpiresAt; - if (typeof accessTokenExpiresAt === 'string') { - const parsed = Date.parse(accessTokenExpiresAt); - return Number.isNaN(parsed) ? undefined : parsed; - } return undefined; } @@ -410,7 +406,7 @@ export class MCPHubOAuthProvider implements OAuthClientProvider { const nextRefreshToken = tokens.refreshToken ?? refreshToken; if (tokens.refreshToken === undefined) { console.warn( - `Refresh response missing refresh_token for ${this.serverName}, reusing existing refresh token`, + `Refresh response missing refresh_token for ${this.serverName}; reusing existing refresh token (some providers omit refresh_token on refresh)`, ); } diff --git a/tests/services/mcpOAuthProvider.test.ts b/tests/services/mcpOAuthProvider.test.ts index e9618f6..059a5d7 100644 --- a/tests/services/mcpOAuthProvider.test.ts +++ b/tests/services/mcpOAuthProvider.test.ts @@ -24,6 +24,7 @@ jest.mock('../../src/dao/index.js', () => ({ import { MCPHubOAuthProvider } from '../../src/services/mcpOAuthProvider.js'; import * as oauthRegistration from '../../src/services/oauthClientRegistration.js'; import * as oauthSettingsStore from '../../src/services/oauthSettingsStore.js'; +import type { ServerConfig } from '../../src/types/index.js'; describe('MCPHubOAuthProvider token refresh', () => { const NOW = 1_700_000_000_000; @@ -38,7 +39,7 @@ describe('MCPHubOAuthProvider token refresh', () => { nowSpy.mockRestore(); }); - const baseConfig = { + const baseConfig: ServerConfig = { url: 'https://example.com/v1/sse', oauth: { clientId: 'client-id', @@ -48,7 +49,7 @@ describe('MCPHubOAuthProvider token refresh', () => { }; it('refreshes access token when expired', async () => { - const expiredConfig = { + const expiredConfig: ServerConfig = { ...baseConfig, oauth: { ...baseConfig.oauth, @@ -56,7 +57,7 @@ describe('MCPHubOAuthProvider token refresh', () => { }, }; - const refreshedConfig = { + const refreshedConfig: ServerConfig = { ...expiredConfig, oauth: { ...expiredConfig.oauth, @@ -76,7 +77,7 @@ describe('MCPHubOAuthProvider token refresh', () => { }); (oauthSettingsStore.loadServerConfig as jest.Mock).mockResolvedValue(refreshedConfig); - const provider = new MCPHubOAuthProvider('atlassian-work', expiredConfig as any); + const provider = new MCPHubOAuthProvider('atlassian-work', expiredConfig); const tokens = await provider.tokens(); @@ -87,7 +88,7 @@ describe('MCPHubOAuthProvider token refresh', () => { }); it('returns cached token when not expired', async () => { - const freshConfig = { + const freshConfig: ServerConfig = { ...baseConfig, oauth: { ...baseConfig.oauth, @@ -95,7 +96,7 @@ describe('MCPHubOAuthProvider token refresh', () => { }, }; - const provider = new MCPHubOAuthProvider('atlassian-work', freshConfig as any); + const provider = new MCPHubOAuthProvider('atlassian-work', freshConfig); const tokens = await provider.tokens(); expect(tokens?.access_token).toBe('old-access');