test: remove provider and cache mock leak paths
This commit is contained in:
@@ -2,16 +2,18 @@ import type { ClaudeCodeMcpServer } from "../claude-code-mcp-loader/types"
|
||||
import { McpOAuthProvider } from "../mcp-oauth/provider"
|
||||
import type { OAuthTokenData } from "../mcp-oauth/storage"
|
||||
import { isStepUpRequired, mergeScopes } from "../mcp-oauth/step-up"
|
||||
import type { OAuthProviderFactory, OAuthProviderLike } from "./types"
|
||||
|
||||
export function getOrCreateAuthProvider(
|
||||
authProviders: Map<string, McpOAuthProvider>,
|
||||
authProviders: Map<string, OAuthProviderLike>,
|
||||
serverUrl: string,
|
||||
oauth: NonNullable<ClaudeCodeMcpServer["oauth"]>
|
||||
): McpOAuthProvider {
|
||||
oauth: NonNullable<ClaudeCodeMcpServer["oauth"]>,
|
||||
createOAuthProvider: OAuthProviderFactory = (options) => new McpOAuthProvider(options),
|
||||
): OAuthProviderLike {
|
||||
const existing = authProviders.get(serverUrl)
|
||||
if (existing) return existing
|
||||
|
||||
const provider = new McpOAuthProvider({
|
||||
const provider = createOAuthProvider({
|
||||
serverUrl,
|
||||
clientId: oauth.clientId,
|
||||
scopes: oauth.scopes,
|
||||
@@ -27,7 +29,8 @@ function isTokenExpired(tokenData: OAuthTokenData): boolean {
|
||||
|
||||
export async function buildHttpRequestInit(
|
||||
config: ClaudeCodeMcpServer,
|
||||
authProviders: Map<string, McpOAuthProvider>
|
||||
authProviders: Map<string, OAuthProviderLike>,
|
||||
createOAuthProvider?: OAuthProviderFactory,
|
||||
): Promise<RequestInit | undefined> {
|
||||
const headers: Record<string, string> = {}
|
||||
|
||||
@@ -38,7 +41,7 @@ export async function buildHttpRequestInit(
|
||||
}
|
||||
|
||||
if (config.oauth && config.url) {
|
||||
const provider = getOrCreateAuthProvider(authProviders, config.url, config.oauth)
|
||||
const provider = getOrCreateAuthProvider(authProviders, config.url, config.oauth, createOAuthProvider)
|
||||
let tokenData = provider.tokens()
|
||||
|
||||
if (!tokenData || isTokenExpired(tokenData)) {
|
||||
@@ -60,9 +63,10 @@ export async function buildHttpRequestInit(
|
||||
export async function handleStepUpIfNeeded(params: {
|
||||
error: Error
|
||||
config: ClaudeCodeMcpServer
|
||||
authProviders: Map<string, McpOAuthProvider>
|
||||
authProviders: Map<string, OAuthProviderLike>
|
||||
createOAuthProvider?: OAuthProviderFactory
|
||||
}): Promise<boolean> {
|
||||
const { error, config, authProviders } = params
|
||||
const { error, config, authProviders, createOAuthProvider } = params
|
||||
|
||||
if (!config.oauth || !config.url) {
|
||||
return false
|
||||
@@ -89,7 +93,7 @@ export async function handleStepUpIfNeeded(params: {
|
||||
config.oauth.scopes = mergedScopes
|
||||
|
||||
authProviders.delete(config.url)
|
||||
const provider = getOrCreateAuthProvider(authProviders, config.url, config.oauth)
|
||||
const provider = getOrCreateAuthProvider(authProviders, config.url, config.oauth, createOAuthProvider)
|
||||
|
||||
try {
|
||||
await provider.login()
|
||||
|
||||
Reference in New Issue
Block a user