n8n-bookstack-agent-tool
Version:
Comprehensive BookStack API integration tool for n8n AI Agent with MCP framework compatibility
187 lines ⢠8.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiFailureSimulator = void 0;
const index_js_1 = require("../index.js");
class ApiFailureSimulator {
constructor() {
this.validConfig = {
baseUrl: 'https://wiki.l7cloud.io',
authType: 'bearer',
token: 'EnRkbVwqzNSyLaVo7olU8Wx8umGznKuE',
tokenSecret: 'TyaJ0JHAenwRIgScmsffrCeSIlon4fZ2',
timeout: 30000,
retryAttempts: 3,
retryDelay: 1000
};
this.tool = new index_js_1.BookStackN8nTool(this.validConfig);
}
async runApiFailureTests() {
console.log('\nšØ API FAILURE SIMULATION TESTS');
console.log('===============================');
await this.testTimeoutScenarios();
await this.testServerErrorScenarios();
await this.testAuthenticationFailures();
await this.testNetworkIssues();
console.log('\nā
API failure simulation tests completed');
}
async testTimeoutScenarios() {
console.log('\nā° Testing timeout scenarios...');
const shortTimeoutConfig = {
...this.validConfig,
timeout: 1000 // Minimum valid timeout to test timeout handling
};
const timeoutTool = new index_js_1.BookStackN8nTool(shortTimeoutConfig);
try {
console.log(' Testing with extremely short timeout (100ms)...');
await timeoutTool.execCommand('listBooks', {});
console.log(' ā ļø Timeout test: Request completed unexpectedly');
}
catch (error) {
const errorMessage = error.message;
if (errorMessage.toLowerCase().includes('timeout') || errorMessage.toLowerCase().includes('aborted')) {
console.log(' ā
Timeout handling: Properly detected and handled');
}
else {
console.log(` ā Timeout handling: Unexpected error - ${errorMessage}`);
}
}
}
async testServerErrorScenarios() {
console.log('\nš„ Testing server error scenarios...');
try {
console.log(' Testing with invalid book ID to trigger 404...');
await this.tool.execCommand('getBook', { id: 999999 });
console.log(' ā ļø 404 test: No error thrown for invalid ID');
}
catch (error) {
const errorMessage = error.message;
if (errorMessage.toLowerCase().includes('not found') || errorMessage.toLowerCase().includes('404')) {
console.log(' ā
404 handling: Properly detected and handled');
}
else {
console.log(` ā 404 handling: Unexpected error - ${errorMessage}`);
}
}
try {
console.log(' Testing with invalid endpoint to trigger server errors...');
await this.tool.execCommand('createBook', {
name: '', // Empty name should trigger validation error
description: 'Test book'
});
console.log(' ā ļø Validation test: No error thrown for invalid data');
}
catch (error) {
const errorMessage = error.message;
if (errorMessage.toLowerCase().includes('validation') ||
errorMessage.toLowerCase().includes('required') ||
errorMessage.toLowerCase().includes('422')) {
console.log(' ā
Validation error handling: Properly detected and handled');
}
else {
console.log(` ā Validation error handling: Unexpected error - ${errorMessage}`);
}
}
}
async testAuthenticationFailures() {
console.log('\nš Testing authentication failures...');
const invalidAuthConfig = {
...this.validConfig,
token: 'invalid_token_12345',
tokenSecret: 'invalid_secret_67890'
};
const invalidAuthTool = new index_js_1.BookStackN8nTool(invalidAuthConfig);
try {
console.log(' Testing with invalid authentication credentials...');
await invalidAuthTool.execCommand('listBooks', {});
console.log(' ā ļø Auth test: Request succeeded with invalid credentials');
}
catch (error) {
const errorMessage = error.message;
if (errorMessage.toLowerCase().includes('unauthorized') ||
errorMessage.toLowerCase().includes('401') ||
errorMessage.toLowerCase().includes('forbidden') ||
errorMessage.toLowerCase().includes('403')) {
console.log(' ā
Authentication error handling: Properly detected and handled');
}
else {
console.log(` ā Authentication error handling: Unexpected error - ${errorMessage}`);
}
}
try {
console.log(' Testing with missing authentication credentials...');
const missingTokenConfig = {
...this.validConfig,
token: '',
tokenSecret: ''
};
const missingTokenTool = new index_js_1.BookStackN8nTool(missingTokenConfig);
await missingTokenTool.execCommand('listBooks', {});
console.log(' ā ļø Missing auth test: Request succeeded without credentials');
}
catch (error) {
const errorMessage = error.message;
if (errorMessage.toLowerCase().includes('token') ||
errorMessage.toLowerCase().includes('auth') ||
errorMessage.toLowerCase().includes('credential') ||
errorMessage.toLowerCase().includes('required')) {
console.log(' ā
Missing credentials handling: Properly detected and handled');
}
else {
console.log(` ā Missing credentials handling: Unexpected error - ${errorMessage}`);
}
}
}
async testNetworkIssues() {
console.log('\nš Testing network issues...');
const invalidUrlConfig = {
...this.validConfig,
baseUrl: 'https://nonexistent-bookstack-server.invalid'
};
const networkTool = new index_js_1.BookStackN8nTool(invalidUrlConfig);
try {
console.log(' Testing with invalid/unreachable URL...');
await networkTool.execCommand('listBooks', {});
console.log(' ā ļø Network test: Request succeeded to invalid URL');
}
catch (error) {
const errorMessage = error.message;
if (errorMessage.toLowerCase().includes('network') ||
errorMessage.toLowerCase().includes('dns') ||
errorMessage.toLowerCase().includes('enotfound') ||
errorMessage.toLowerCase().includes('connection')) {
console.log(' ā
Network error handling: Properly detected and handled');
}
else {
console.log(` ā Network error handling: Unexpected error - ${errorMessage}`);
}
}
try {
console.log(' Testing with malformed URL...');
const malformedUrlConfig = {
...this.validConfig,
baseUrl: 'not-a-valid-url'
};
const malformedTool = new index_js_1.BookStackN8nTool(malformedUrlConfig);
await malformedTool.execCommand('listBooks', {});
console.log(' ā ļø Malformed URL test: Request succeeded with invalid URL format');
}
catch (error) {
const errorMessage = error.message;
if (errorMessage.toLowerCase().includes('url') ||
errorMessage.toLowerCase().includes('protocol') ||
errorMessage.toLowerCase().includes('http') ||
errorMessage.toLowerCase().includes('https')) {
console.log(' ā
Malformed URL handling: Properly detected and handled');
}
else {
console.log(` ā Malformed URL handling: Unexpected error - ${errorMessage}`);
}
}
}
}
exports.ApiFailureSimulator = ApiFailureSimulator;
if (require.main === module) {
const simulator = new ApiFailureSimulator();
simulator.runApiFailureTests().catch(console.error);
}
//# sourceMappingURL=api-failure-simulation.js.map