-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathtest-credentials-all-methods-direct.js
More file actions
174 lines (155 loc) · 4.75 KB
/
test-credentials-all-methods-direct.js
File metadata and controls
174 lines (155 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env node
/**
* Direct API test for ALL Credentials endpoints
* Tests POST, PUT, DELETE methods to confirm entire API is restricted
*/
const axios = require('axios');
const fs = require('fs');
// Load configuration
let config;
if (fs.existsSync('.config.json')) {
const rawConfig = JSON.parse(fs.readFileSync('.config.json', 'utf8'));
const defaultEnv = rawConfig.defaultEnv || Object.keys(rawConfig.environments)[0];
const envConfig = rawConfig.environments[defaultEnv];
config = {
n8nHost: envConfig.n8n_host,
n8nApiKey: envConfig.n8n_api_key
};
} else {
require('dotenv').config();
config = {
n8nHost: process.env.N8N_HOST,
n8nApiKey: process.env.N8N_API_KEY
};
}
const testId = '1';
async function testEndpoint(method, endpoint, data = null) {
try {
const options = {
method: method,
url: `${config.n8nHost}/api/v1${endpoint}`,
headers: {
'X-N8N-API-KEY': config.n8nApiKey,
'Accept': 'application/json',
'Content-Type': 'application/json'
}
};
if (data) {
options.data = data;
}
const response = await axios(options);
return { success: true, status: response.status, data: response.data };
} catch (error) {
if (error.response) {
return {
success: false,
status: error.response.status,
message: error.response.data
};
}
return { success: false, error: error.message };
}
}
async function main() {
console.log('\n=== Comprehensive Credentials API Test ===\n');
console.log(`Testing against: ${config.n8nHost}\n`);
const tests = [
{
name: 'GET /credentials',
method: 'GET',
endpoint: '/credentials',
story: '2.6.1'
},
{
name: 'GET /credentials/{id}',
method: 'GET',
endpoint: `/credentials/${testId}`,
story: '2.6.2'
},
{
name: 'POST /credentials',
method: 'POST',
endpoint: '/credentials',
data: {
name: 'Test Credential',
type: 'httpBasicAuth',
data: {
user: 'test',
password: 'test'
}
},
story: '2.6.3'
},
{
name: 'PUT /credentials/{id}',
method: 'PUT',
endpoint: `/credentials/${testId}`,
data: {
name: 'Updated Credential',
type: 'httpBasicAuth',
data: {
user: 'test',
password: 'test'
}
},
story: '2.6.4'
},
{
name: 'DELETE /credentials/{id}',
method: 'DELETE',
endpoint: `/credentials/${testId}`,
story: '2.6.5'
},
{
name: 'GET /credentials/schema/{typeName}',
method: 'GET',
endpoint: '/credentials/schema/httpBasicAuth',
story: '2.6.6'
}
];
const results = [];
for (const test of tests) {
console.log(`Testing: ${test.name} (Story ${test.story})`);
const result = await testEndpoint(test.method, test.endpoint, test.data);
results.push({
...test,
result
});
if (result.success) {
console.log(` ✅ Status ${result.status} - SUPPORTED`);
} else if (result.status === 405) {
console.log(` ❌ Status 405 - NOT SUPPORTED (Method Not Allowed)`);
} else if (result.status === 404) {
console.log(` ⚠️ Status 404 - Might be supported but resource not found`);
} else if (result.status === 401) {
console.log(` ❌ Status 401 - Authentication error`);
} else if (result.status === 403) {
console.log(` ❌ Status 403 - Permission denied`);
} else if (result.status) {
console.log(` ⚠️ Status ${result.status} - ${JSON.stringify(result.message)}`);
} else {
console.log(` ❌ Error: ${result.error}`);
}
}
// Summary
console.log('\n=== Summary ===\n');
const supported = results.filter(r => r.result.success);
const notAllowed = results.filter(r => r.result.status === 405);
const other = results.filter(r => !r.result.success && r.result.status !== 405);
console.log(`Total endpoints tested: ${results.length}`);
console.log(`✅ Supported: ${supported.length}`);
console.log(`❌ Not Allowed (405): ${notAllowed.length}`);
console.log(`⚠️ Other errors: ${other.length}`);
if (notAllowed.length === results.length) {
console.log('\n🔒 CONCLUSION: Entire Credentials API is RESTRICTED (all 405)');
console.log(' This is a security-based design decision by n8n');
console.log(' Stories 2.6.1 - 2.6.6 should return informative messages');
} else if (notAllowed.length > 0) {
console.log(`\n⚠️ CONCLUSION: ${notAllowed.length}/${results.length} endpoints restricted`);
console.log(' Partial API availability - investigate further');
} else {
console.log('\n✅ CONCLUSION: Credentials API appears to be available');
}
console.log('\n');
}
main();