mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-24 02:39:19 -05:00
chore: refine oauth token tests and warnings
Co-authored-by: samanhappy <2755122+samanhappy@users.noreply.github.com>
This commit is contained in:
@@ -295,7 +295,7 @@ export class MCPHubOAuthProvider implements OAuthClientProvider {
|
||||
/**
|
||||
* Get stored OAuth tokens
|
||||
*/
|
||||
async tokens(): Promise<OAuthTokens | undefined> {
|
||||
tokens(): OAuthTokens | undefined | Promise<OAuthTokens | undefined> {
|
||||
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)`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user