mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 22:39:39 +00:00
- Create AuthHeaderProvider that integrates with Firebase and API key stores - Add core extension to register auth provider during preInit - Implement automatic auth header injection for all HTTP requests - Add comprehensive unit and integration tests - Include examples showing migration from manual to automatic auth This completes the header registration system by connecting it to the actual authentication mechanisms in ComfyUI. Co-Authored-By: Claude <noreply@anthropic.com>
84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { AuthHeaderProvider } from '@/providers/authHeaderProvider'
|
|
import { headerRegistry } from '@/services/headerRegistry'
|
|
|
|
// Mock the providers module
|
|
vi.mock('@/providers/authHeaderProvider', () => ({
|
|
AuthHeaderProvider: vi.fn()
|
|
}))
|
|
|
|
// Mock headerRegistry
|
|
vi.mock('@/services/headerRegistry', () => ({
|
|
headerRegistry: {
|
|
registerHeaderProvider: vi.fn()
|
|
}
|
|
}))
|
|
|
|
// Mock app
|
|
const mockApp = {
|
|
registerExtension: vi.fn()
|
|
}
|
|
|
|
vi.mock('@/scripts/app', () => ({
|
|
app: mockApp
|
|
}))
|
|
|
|
describe('authHeaders extension', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
// Reset module cache to ensure fresh imports
|
|
vi.resetModules()
|
|
})
|
|
|
|
it('should register extension with correct name', async () => {
|
|
// Import the extension (this will call app.registerExtension)
|
|
await import('@/extensions/core/authHeaders')
|
|
|
|
expect(mockApp.registerExtension).toHaveBeenCalledOnce()
|
|
const extensionConfig = mockApp.registerExtension.mock.calls[0][0]
|
|
expect(extensionConfig.name).toBe('Comfy.AuthHeaders')
|
|
})
|
|
|
|
it('should register auth header provider in preInit hook', async () => {
|
|
// Import the extension
|
|
await import('@/extensions/core/authHeaders')
|
|
|
|
const extensionConfig = mockApp.registerExtension.mock.calls[0][0]
|
|
expect(extensionConfig.preInit).toBeDefined()
|
|
|
|
// Call the preInit hook
|
|
await extensionConfig.preInit({})
|
|
|
|
// Verify AuthHeaderProvider was instantiated
|
|
expect(AuthHeaderProvider).toHaveBeenCalledOnce()
|
|
|
|
// Verify header provider was registered with high priority
|
|
expect(headerRegistry.registerHeaderProvider).toHaveBeenCalledWith(
|
|
expect.any(Object), // The AuthHeaderProvider instance
|
|
{ priority: 1000 }
|
|
)
|
|
})
|
|
|
|
it('should log initialization messages', async () => {
|
|
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
|
|
|
// Import the extension
|
|
await import('@/extensions/core/authHeaders')
|
|
|
|
const extensionConfig = mockApp.registerExtension.mock.calls[0][0]
|
|
|
|
// Call the preInit hook
|
|
await extensionConfig.preInit({})
|
|
|
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
'[AuthHeaders] Registering authentication header provider'
|
|
)
|
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
'[AuthHeaders] Authentication headers will be automatically injected'
|
|
)
|
|
|
|
consoleLogSpy.mockRestore()
|
|
})
|
|
})
|