-
Notifications
You must be signed in to change notification settings - Fork 94
feat(lightspeed): add MCP servers settings panel #2582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
44855b5
e8092da
34f60c5
c685a1b
3627613
46116e5
bed98ca
8154707
89b0bbf
05b4026
df80fe5
98a7a23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Copyright Red Hat, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { McpServerValidator } from './mcp-server-validator'; | ||
|
|
||
| describe('McpServerValidator auth header behavior', () => { | ||
| const url = 'https://mcp.example.com'; | ||
| const childMock = jest.fn(); | ||
| const logger: ConstructorParameters<typeof McpServerValidator>[0] = { | ||
| debug: jest.fn(), | ||
| info: jest.fn(), | ||
| warn: jest.fn(), | ||
| error: jest.fn(), | ||
| child: childMock, | ||
| }; | ||
| childMock.mockImplementation(() => logger); | ||
|
|
||
| const originalFetch = global.fetch; | ||
|
Check warning on line 31 in workspaces/lightspeed/plugins/lightspeed-backend/src/service/mcp-server-validator.test.ts
|
||
|
|
||
| afterEach(() => { | ||
| global.fetch = originalFetch; | ||
|
Check warning on line 34 in workspaces/lightspeed/plugins/lightspeed-backend/src/service/mcp-server-validator.test.ts
|
||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('tries raw token first, then Bearer on 401/403', async () => { | ||
| const fetchMock = jest | ||
| .fn() | ||
| .mockResolvedValue(new Response(null, { status: 401 })); | ||
| global.fetch = fetchMock; | ||
|
Check warning on line 42 in workspaces/lightspeed/plugins/lightspeed-backend/src/service/mcp-server-validator.test.ts
|
||
|
|
||
| const validator = new McpServerValidator(logger); | ||
| const result = await validator.validate(url, 'raw-token'); | ||
|
|
||
| expect(result).toMatchObject({ | ||
| valid: false, | ||
| toolCount: 0, | ||
| tools: [], | ||
| error: 'Invalid credentials — server returned 401/403', | ||
| }); | ||
| expect(fetchMock).toHaveBeenCalledTimes(2); | ||
| expect(fetchMock.mock.calls[0][1]?.headers).toMatchObject({ | ||
| Authorization: 'raw-token', | ||
| }); | ||
| expect(fetchMock.mock.calls[1][1]?.headers).toMatchObject({ | ||
| Authorization: 'Bearer raw-token', | ||
| }); | ||
| }); | ||
|
|
||
| it('uses token as-is when it already has an auth scheme', async () => { | ||
| const fetchMock = jest | ||
| .fn() | ||
| .mockResolvedValue(new Response(null, { status: 401 })); | ||
| global.fetch = fetchMock; | ||
|
Check warning on line 66 in workspaces/lightspeed/plugins/lightspeed-backend/src/service/mcp-server-validator.test.ts
|
||
|
|
||
| const validator = new McpServerValidator(logger); | ||
| const result = await validator.validate(url, 'Basic abc123'); | ||
|
|
||
| expect(result.valid).toBe(false); | ||
| expect(fetchMock).toHaveBeenCalledTimes(1); | ||
| expect(fetchMock.mock.calls[0][1]?.headers).toMatchObject({ | ||
| Authorization: 'Basic abc123', | ||
| }); | ||
| }); | ||
| }); | ||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.