mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
Chore/refractor (#4454)
* markdown files and env examples cleanup * components update * update jsonlines description * server refractor * update telemetry * add execute custom node * add ui refractor * add username and password authenticate * correctly retrieve past images in agentflowv2 * disable e2e temporarily * add existing username and password authenticate * update migration to default workspace * update todo * blob storage migrating * throw error on agent tool call error * add missing execution import * add referral * chore: add error message when importData is undefined * migrate api keys to db * fix: data too long for column executionData * migrate api keys from json to db at init * add info on account setup * update docstore missing fields --------- Co-authored-by: chungyau97 <chungyau97@gmail.com>
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { generateAPIKey } from '../../src/utils/apiKey'
|
||||
|
||||
export function apiKeyTest() {
|
||||
describe('Api Key', () => {
|
||||
it('should be able to generate a new api key', () => {
|
||||
const apiKey = generateAPIKey()
|
||||
expect(typeof apiKey === 'string').toEqual(true)
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
import { Request } from 'express'
|
||||
import { ChatFlow } from '../../src/database/entities/ChatFlow'
|
||||
import { validateChatflowAPIKey } from '../../src/utils/validateKey'
|
||||
import { compareKeys, getAPIKeys } from '../../src/utils/apiKey'
|
||||
|
||||
jest.mock('../../src/utils/apiKey')
|
||||
|
||||
describe('validateChatflowAPIKey', () => {
|
||||
let req: Partial<Request>
|
||||
let chatflow: ChatFlow
|
||||
|
||||
beforeEach(() => {
|
||||
req = {
|
||||
headers: {}
|
||||
}
|
||||
chatflow = {
|
||||
apikeyid: null
|
||||
} as ChatFlow
|
||||
})
|
||||
|
||||
it('should return true if chatflow.apikeyid is not set', async () => {
|
||||
const result = await validateChatflowAPIKey(req as Request, chatflow)
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it('should return false if chatflow.apikeyid is set but authorization header is missing', async () => {
|
||||
chatflow.apikeyid = 'some-api-key-id'
|
||||
const result = await validateChatflowAPIKey(req as Request, chatflow)
|
||||
expect(result).toBe(false)
|
||||
})
|
||||
|
||||
it('should return false if supplied key does not match the expected key', async () => {
|
||||
chatflow.apikeyid = 'some-api-key-id'
|
||||
req.headers['authorization'] = 'Bearer invalid-key'
|
||||
;(getAPIKeys as jest.Mock).mockResolvedValue([{ id: 'some-api-key-id', apiSecret: 'expected-secret-key' }])
|
||||
;(compareKeys as jest.Mock).mockImplementation((expected, supplied) => expected === supplied)
|
||||
|
||||
const result = await validateChatflowAPIKey(req as Request, chatflow)
|
||||
expect(result).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user