refactor: remove CORS settings, make auth mandatory in types

- Remove enableCORS and allowedOrigins from MCPServerSettings
- Make apiKey required (string, not optional)
- Set enableAuth to true by default
- Add comprehensive test coverage for settings types
This commit is contained in:
2025-10-25 21:07:53 -04:00
parent a9c6093ada
commit 5ce7488597
2 changed files with 51 additions and 8 deletions

View File

@@ -1,10 +1,8 @@
// Settings Types
export interface MCPServerSettings {
port: number;
enableCORS: boolean;
allowedOrigins: string[];
apiKey?: string;
enableAuth: boolean;
apiKey: string; // Now required, not optional
enableAuth: boolean; // Will be removed in future, kept for migration
}
export interface NotificationSettings {
@@ -20,10 +18,8 @@ export interface MCPPluginSettings extends MCPServerSettings, NotificationSettin
export const DEFAULT_SETTINGS: MCPPluginSettings = {
port: 3000,
enableCORS: true,
allowedOrigins: ['*'],
apiKey: '',
enableAuth: false,
apiKey: '', // Will be auto-generated on first load
enableAuth: true, // Always true now
autoStart: false,
// Notification defaults
notificationsEnabled: false,

View File

@@ -0,0 +1,47 @@
import { DEFAULT_SETTINGS, MCPPluginSettings } from '../src/types/settings-types';
describe('Settings Types', () => {
describe('DEFAULT_SETTINGS', () => {
it('should have authentication enabled by default', () => {
expect(DEFAULT_SETTINGS.enableAuth).toBe(true);
});
it('should not have enableCORS field', () => {
expect((DEFAULT_SETTINGS as any).enableCORS).toBeUndefined();
});
it('should not have allowedOrigins field', () => {
expect((DEFAULT_SETTINGS as any).allowedOrigins).toBeUndefined();
});
it('should have empty apiKey by default', () => {
expect(DEFAULT_SETTINGS.apiKey).toBe('');
});
it('should have autoStart disabled by default', () => {
expect(DEFAULT_SETTINGS.autoStart).toBe(false);
});
it('should have valid port number', () => {
expect(DEFAULT_SETTINGS.port).toBe(3000);
expect(DEFAULT_SETTINGS.port).toBeGreaterThan(0);
expect(DEFAULT_SETTINGS.port).toBeLessThan(65536);
});
});
describe('MCPPluginSettings interface', () => {
it('should require apiKey field', () => {
const settings: MCPPluginSettings = {
...DEFAULT_SETTINGS,
apiKey: 'test-key'
};
expect(settings.apiKey).toBe('test-key');
});
it('should not allow enableCORS field', () => {
// This is a compile-time check, but we verify runtime
const settings: MCPPluginSettings = DEFAULT_SETTINGS;
expect((settings as any).enableCORS).toBeUndefined();
});
});
});