@roomi-fields/notebooklm-mcp 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -22
- package/README.md +2 -0
- package/deployment/INDEX.md +292 -0
- package/deployment/PACKAGE-FILES.txt +180 -0
- package/deployment/QUICK-START.md +100 -0
- package/deployment/docs/01-INSTALL.md +611 -0
- package/deployment/docs/02-CONFIGURATION.md +404 -0
- package/deployment/docs/03-API.md +1691 -0
- package/deployment/docs/04-N8N-INTEGRATION.md +373 -0
- package/deployment/docs/05-TROUBLESHOOTING.md +429 -0
- package/deployment/docs/06-NOTEBOOK-LIBRARY.md +692 -0
- package/deployment/docs/07-AUTO-DISCOVERY.md +236 -0
- package/deployment/docs/08-WSL-USAGE.md +363 -0
- package/deployment/docs/09-MULTI-INTERFACE.md +293 -0
- package/deployment/docs/10-CONTENT-MANAGEMENT.md +421 -0
- package/deployment/docs/11-MULTI-ACCOUNT.md +295 -0
- package/deployment/docs/README.md +207 -0
- package/deployment/scripts/README.md +564 -0
- package/deployment/scripts/install.ps1 +114 -0
- package/deployment/scripts/setup-auth.ps1 +217 -0
- package/deployment/scripts/start-server.ps1 +72 -0
- package/deployment/scripts/stop-server.ps1 +51 -0
- package/deployment/scripts/test-api.ps1 +651 -0
- package/deployment/scripts/test-auth.ps1 +323 -0
- package/deployment/scripts/test-auto-discovery.ps1 +295 -0
- package/deployment/scripts/test-cors.ps1 +398 -0
- package/deployment/scripts/test-errors.ps1 +581 -0
- package/deployment/scripts/test-server.ps1 +140 -0
- package/deployment/scripts/test-sessions.ps1 +426 -0
- package/deployment/scripts/test-validation.ps1 +299 -0
- package/dist/cli/accounts.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -0
- package/dist/config.js.map +1 -1
- package/dist/content/content-manager.d.ts.map +1 -1
- package/dist/content/content-manager.js +113 -118
- package/dist/content/content-manager.js.map +1 -1
- package/dist/i18n/en.json +120 -0
- package/dist/i18n/fr.json +120 -0
- package/dist/i18n/index.d.ts +168 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +213 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/session/browser-session.d.ts.map +1 -1
- package/dist/session/browser-session.js +1 -0
- package/dist/session/browser-session.js.map +1 -1
- package/dist/session/shared-context-manager.d.ts.map +1 -1
- package/dist/session/shared-context-manager.js +2 -0
- package/dist/session/shared-context-manager.js.map +1 -1
- package/docs/ADDING_A_LANGUAGE.md +209 -0
- package/package.json +6 -3
- package/scripts/archive/add-and-activate-notebook.ps1 +31 -0
- package/scripts/archive/add-new-notebook.ps1 +25 -0
- package/scripts/archive/add-rom1pey.ps1 +2 -0
- package/scripts/archive/add-rpmonster.ps1 +2 -0
- package/scripts/archive/add-source-debug.ps1 +11 -0
- package/scripts/archive/add-source-e2e.ps1 +28 -0
- package/scripts/archive/add-source-visible.ps1 +11 -0
- package/scripts/archive/add-test-notebook.ps1 +13 -0
- package/scripts/archive/add-test-source.ps1 +50 -0
- package/scripts/archive/capture-screen.ps1 +11 -0
- package/scripts/archive/change-language.mjs +45 -0
- package/scripts/archive/change-language.ts +44 -0
- package/scripts/archive/check-account.ps1 +19 -0
- package/scripts/archive/check-notebook-2.ps1 +8 -0
- package/scripts/archive/check-test-notebook.ps1 +11 -0
- package/scripts/archive/create-notebook-auto.ps1 +31 -0
- package/scripts/archive/create-notebook.ps1 +8 -0
- package/scripts/archive/create-rom1pey-notebook.ps1 +19 -0
- package/scripts/archive/create-rom1pey.ps1 +8 -0
- package/scripts/archive/create-test-notebook-fresh.ps1 +21 -0
- package/scripts/archive/create-test-notebook.ps1 +16 -0
- package/scripts/archive/debug-add-source-auto.ps1 +29 -0
- package/scripts/archive/debug-add-source.ps1 +19 -0
- package/scripts/archive/debug-add-text-source.ps1 +47 -0
- package/scripts/archive/debug-home.ps1 +10 -0
- package/scripts/archive/debug-selectors.ps1 +55 -0
- package/scripts/archive/debug-sources-panel.ps1 +22 -0
- package/scripts/archive/debug-ui.ps1 +17 -0
- package/scripts/archive/discover-home.ps1 +26 -0
- package/scripts/archive/kill-automation-chrome.ps1 +37 -0
- package/scripts/archive/list-my-notebooks.ps1 +27 -0
- package/scripts/archive/navigate-home-visible.ps1 +23 -0
- package/scripts/archive/navigate-home.ps1 +15 -0
- package/scripts/archive/run-e2e-english.ps1 +111 -0
- package/scripts/archive/run-e2e-rom1pey-v2.ps1 +122 -0
- package/scripts/archive/run-e2e-rom1pey.ps1 +117 -0
- package/scripts/archive/setup-english-test.ps1 +36 -0
- package/scripts/archive/setup-test-notebook.ps1 +71 -0
- package/scripts/archive/simple-add-source.ps1 +14 -0
- package/scripts/archive/t10.ps1 +2 -0
- package/scripts/archive/t20.ps1 +4 -0
- package/scripts/archive/t30.ps1 +9 -0
- package/scripts/archive/t31.ps1 +11 -0
- package/scripts/archive/t32.ps1 +6 -0
- package/scripts/archive/t39.ps1 +5 -0
- package/scripts/archive/t40.ps1 +5 -0
- package/scripts/archive/t53.ps1 +12 -0
- package/scripts/archive/t54.ps1 +12 -0
- package/scripts/archive/t55.ps1 +11 -0
- package/scripts/archive/t9.ps1 +1 -0
- package/scripts/archive/test-access.ps1 +28 -0
- package/scripts/archive/test-add-delete-source.ps1 +64 -0
- package/scripts/archive/test-add-source-visible.ps1 +16 -0
- package/scripts/archive/test-add-source.ps1 +19 -0
- package/scripts/archive/test-add-text-debug.ps1 +28 -0
- package/scripts/archive/test-add-text-source.ps1 +8 -0
- package/scripts/archive/test-add-url-source.ps1 +7 -0
- package/scripts/archive/test-ask-ascii.ps1 +20 -0
- package/scripts/archive/test-ask-cnv.ps1 +20 -0
- package/scripts/archive/test-ask-headed.ps1 +51 -0
- package/scripts/archive/test-ask-ifs.ps1 +16 -0
- package/scripts/archive/test-ask-now.ps1 +24 -0
- package/scripts/archive/test-ask-real.ps1 +19 -0
- package/scripts/archive/test-ask-visible.ps1 +20 -0
- package/scripts/archive/test-create-notebook.ps1 +8 -0
- package/scripts/archive/test-create-then-add.ps1 +17 -0
- package/scripts/archive/test-delete-source.ps1 +41 -0
- package/scripts/archive/test-e2e-notebook.ps1 +21 -0
- package/scripts/archive/test-english-notebook.ps1 +20 -0
- package/scripts/archive/test-english.ps1 +7 -0
- package/scripts/archive/test-full-custom-instructions.ps1 +40 -0
- package/scripts/archive/test-full-infographic.ps1 +34 -0
- package/scripts/archive/test-full-language.ps1 +21 -0
- package/scripts/archive/test-full-presentation.ps1 +85 -0
- package/scripts/archive/test-full-report.ps1 +34 -0
- package/scripts/archive/test-full-source-selection.ps1 +35 -0
- package/scripts/archive/test-full-video-brief.ps1 +22 -0
- package/scripts/archive/test-full-video-explainer.ps1 +22 -0
- package/scripts/archive/test-full-video-styles.ps1 +37 -0
- package/scripts/archive/test-generate-report.ps1 +15 -0
- package/scripts/archive/test-generate-study-guide.ps1 +11 -0
- package/scripts/archive/test-headed-ask.ps1 +13 -0
- package/scripts/archive/test-headed-now.ps1 +9 -0
- package/scripts/archive/test-headed.ps1 +9 -0
- package/scripts/archive/test-hello.ps1 +7 -0
- package/scripts/archive/test-i18n-studio.ps1 +8 -0
- package/scripts/archive/test-i18n.ps1 +7 -0
- package/scripts/archive/test-manual-headed.ps1 +26 -0
- package/scripts/archive/test-mathieu-quota.ps1 +8 -0
- package/scripts/archive/test-notebook-1.ps1 +10 -0
- package/scripts/archive/test-notebook-2-sources.ps1 +12 -0
- package/scripts/archive/test-notebook1.ps1 +14 -0
- package/scripts/archive/test-personal-notebook.ps1 +14 -0
- package/scripts/archive/test-rate-limit.ps1 +19 -0
- package/scripts/archive/test-real-ask.ps1 +50 -0
- package/scripts/archive/test-real-ask2.ps1 +30 -0
- package/scripts/archive/test-rom1pey.ps1 +7 -0
- package/scripts/archive/test-rotation-complete.ps1 +14 -0
- package/scripts/archive/test-rotation.ps1 +8 -0
- package/scripts/archive/test-show-browser.ps1 +39 -0
- package/scripts/archive/test-update-notebook.ps1 +4 -0
- package/scripts/archive/verify-language-slow.ps1 +21 -0
- package/scripts/archive/verify-language.ps1 +15 -0
- package/scripts/check-server.ps1 +46 -0
- package/scripts/mcp-wsl-helper.sh +146 -0
- package/scripts/start-server.ps1 +94 -0
- package/scripts/stop-server.ps1 +30 -0
- package/scripts/switch-account-language.sh +191 -0
- package/scripts/test-account.ps1 +58 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
#!/usr/bin/env pwsh
|
|
2
|
+
#Requires -Version 5.1
|
|
3
|
+
|
|
4
|
+
<#
|
|
5
|
+
.SYNOPSIS
|
|
6
|
+
CORS configuration testing script for NotebookLM MCP HTTP Server API
|
|
7
|
+
|
|
8
|
+
.DESCRIPTION
|
|
9
|
+
Tests CORS (Cross-Origin Resource Sharing) configuration:
|
|
10
|
+
- Default allowed origins (localhost ports)
|
|
11
|
+
- CORS headers in responses
|
|
12
|
+
- Preflight OPTIONS requests
|
|
13
|
+
- Origin header handling
|
|
14
|
+
|
|
15
|
+
.PARAMETER BaseUrl
|
|
16
|
+
Base URL of the server (default: http://localhost:3000)
|
|
17
|
+
|
|
18
|
+
.EXAMPLE
|
|
19
|
+
.\test-cors.ps1
|
|
20
|
+
Runs all CORS tests
|
|
21
|
+
|
|
22
|
+
.NOTES
|
|
23
|
+
Prerequisite: The server must be started
|
|
24
|
+
#>
|
|
25
|
+
|
|
26
|
+
param(
|
|
27
|
+
[string]$BaseUrl = "http://localhost:3000"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
# Colors for logs
|
|
31
|
+
function Write-TestHeader {
|
|
32
|
+
param([string]$Message, [int]$Number, [int]$Total)
|
|
33
|
+
Write-Host "`n" -NoNewline
|
|
34
|
+
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Magenta
|
|
35
|
+
Write-Host " [$Number/$Total] $Message" -ForegroundColor Cyan
|
|
36
|
+
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Magenta
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function Write-Success {
|
|
40
|
+
param([string]$Message)
|
|
41
|
+
Write-Host "✓ $Message" -ForegroundColor Green
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function Write-Info {
|
|
45
|
+
param([string]$Message)
|
|
46
|
+
Write-Host "ℹ $Message" -ForegroundColor Yellow
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function Write-ErrorUnexpected {
|
|
50
|
+
param([string]$Message)
|
|
51
|
+
Write-Host "✗ $Message" -ForegroundColor Red
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
# Banner
|
|
55
|
+
Clear-Host
|
|
56
|
+
Write-Host "`n" -NoNewline
|
|
57
|
+
Write-Host "╔════════════════════════════════════════════════════════╗" -ForegroundColor Magenta
|
|
58
|
+
Write-Host "║ ║" -ForegroundColor Magenta
|
|
59
|
+
Write-Host "║ CORS CONFIGURATION TESTS - HTTP API ║" -ForegroundColor Cyan
|
|
60
|
+
Write-Host "║ ║" -ForegroundColor Magenta
|
|
61
|
+
Write-Host "╚════════════════════════════════════════════════════════╝" -ForegroundColor Magenta
|
|
62
|
+
Write-Host ""
|
|
63
|
+
|
|
64
|
+
# Check that the server is accessible
|
|
65
|
+
Write-Host "Checking connection to server..." -ForegroundColor Yellow
|
|
66
|
+
try {
|
|
67
|
+
$null = Invoke-RestMethod -Uri "$BaseUrl/health" -TimeoutSec 5
|
|
68
|
+
Write-Success "Server accessible at $BaseUrl"
|
|
69
|
+
} catch {
|
|
70
|
+
Write-ErrorUnexpected "Unable to connect to server at $BaseUrl"
|
|
71
|
+
Write-Host "Make sure the server is started" -ForegroundColor Yellow
|
|
72
|
+
exit 1
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
$TotalTests = 10
|
|
76
|
+
$PassedTests = 0
|
|
77
|
+
$FailedTests = 0
|
|
78
|
+
|
|
79
|
+
# =============================================================================
|
|
80
|
+
# TEST 1: Request without Origin header (should work)
|
|
81
|
+
# =============================================================================
|
|
82
|
+
Write-TestHeader "Request without Origin header (same-origin)" 1 $TotalTests
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
$response = Invoke-WebRequest -Uri "$BaseUrl/health" -Method Get -TimeoutSec 10
|
|
86
|
+
|
|
87
|
+
if ($response.StatusCode -eq 200) {
|
|
88
|
+
Write-Success "Request without Origin header accepted"
|
|
89
|
+
$PassedTests++
|
|
90
|
+
} else {
|
|
91
|
+
Write-ErrorUnexpected "Unexpected status code: $($response.StatusCode)"
|
|
92
|
+
$FailedTests++
|
|
93
|
+
}
|
|
94
|
+
} catch {
|
|
95
|
+
Write-ErrorUnexpected "Request failed: $($_.Exception.Message)"
|
|
96
|
+
$FailedTests++
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# =============================================================================
|
|
100
|
+
# TEST 2: Request with allowed Origin (localhost:3000)
|
|
101
|
+
# =============================================================================
|
|
102
|
+
Write-TestHeader "Request with allowed Origin: localhost:3000" 2 $TotalTests
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
$headers = @{ "Origin" = "http://localhost:3000" }
|
|
106
|
+
$response = Invoke-WebRequest -Uri "$BaseUrl/health" -Method Get -Headers $headers -TimeoutSec 10
|
|
107
|
+
|
|
108
|
+
$corsHeader = $response.Headers["Access-Control-Allow-Origin"]
|
|
109
|
+
if ($corsHeader -eq "http://localhost:3000" -or $corsHeader -eq "*") {
|
|
110
|
+
Write-Success "CORS header returned for allowed origin"
|
|
111
|
+
Write-Info "Access-Control-Allow-Origin: $corsHeader"
|
|
112
|
+
$PassedTests++
|
|
113
|
+
} else {
|
|
114
|
+
Write-ErrorUnexpected "Missing or incorrect CORS header: $corsHeader"
|
|
115
|
+
$FailedTests++
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
Write-ErrorUnexpected "Request failed: $($_.Exception.Message)"
|
|
119
|
+
$FailedTests++
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# =============================================================================
|
|
123
|
+
# TEST 3: Request with allowed Origin (localhost:5678 - n8n)
|
|
124
|
+
# =============================================================================
|
|
125
|
+
Write-TestHeader "Request with allowed Origin: localhost:5678 (n8n)" 3 $TotalTests
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
$headers = @{ "Origin" = "http://localhost:5678" }
|
|
129
|
+
$response = Invoke-WebRequest -Uri "$BaseUrl/health" -Method Get -Headers $headers -TimeoutSec 10
|
|
130
|
+
|
|
131
|
+
$corsHeader = $response.Headers["Access-Control-Allow-Origin"]
|
|
132
|
+
if ($corsHeader -eq "http://localhost:5678" -or $corsHeader -eq "*") {
|
|
133
|
+
Write-Success "CORS header returned for n8n origin"
|
|
134
|
+
Write-Info "Access-Control-Allow-Origin: $corsHeader"
|
|
135
|
+
$PassedTests++
|
|
136
|
+
} else {
|
|
137
|
+
Write-ErrorUnexpected "Missing or incorrect CORS header: $corsHeader"
|
|
138
|
+
$FailedTests++
|
|
139
|
+
}
|
|
140
|
+
} catch {
|
|
141
|
+
Write-ErrorUnexpected "Request failed: $($_.Exception.Message)"
|
|
142
|
+
$FailedTests++
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# =============================================================================
|
|
146
|
+
# TEST 4: Request with allowed Origin (127.0.0.1:3000)
|
|
147
|
+
# =============================================================================
|
|
148
|
+
Write-TestHeader "Request with allowed Origin: 127.0.0.1:3000" 4 $TotalTests
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
$headers = @{ "Origin" = "http://127.0.0.1:3000" }
|
|
152
|
+
$response = Invoke-WebRequest -Uri "$BaseUrl/health" -Method Get -Headers $headers -TimeoutSec 10
|
|
153
|
+
|
|
154
|
+
$corsHeader = $response.Headers["Access-Control-Allow-Origin"]
|
|
155
|
+
if ($corsHeader -eq "http://127.0.0.1:3000" -or $corsHeader -eq "*") {
|
|
156
|
+
Write-Success "CORS header returned for 127.0.0.1 origin"
|
|
157
|
+
Write-Info "Access-Control-Allow-Origin: $corsHeader"
|
|
158
|
+
$PassedTests++
|
|
159
|
+
} else {
|
|
160
|
+
Write-ErrorUnexpected "Missing or incorrect CORS header: $corsHeader"
|
|
161
|
+
$FailedTests++
|
|
162
|
+
}
|
|
163
|
+
} catch {
|
|
164
|
+
Write-ErrorUnexpected "Request failed: $($_.Exception.Message)"
|
|
165
|
+
$FailedTests++
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# =============================================================================
|
|
169
|
+
# TEST 5: Request with blocked Origin (external domain)
|
|
170
|
+
# =============================================================================
|
|
171
|
+
Write-TestHeader "Request with external Origin (should be blocked)" 5 $TotalTests
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
$headers = @{ "Origin" = "https://malicious-site.com" }
|
|
175
|
+
$response = Invoke-WebRequest -Uri "$BaseUrl/health" -Method Get -Headers $headers -TimeoutSec 10
|
|
176
|
+
|
|
177
|
+
# Request should still succeed (CORS is browser-enforced), but check header
|
|
178
|
+
$corsHeader = $response.Headers["Access-Control-Allow-Origin"]
|
|
179
|
+
|
|
180
|
+
if ($null -eq $corsHeader -or $corsHeader -eq "") {
|
|
181
|
+
Write-Success "External origin correctly blocked (no CORS header)"
|
|
182
|
+
$PassedTests++
|
|
183
|
+
} elseif ($corsHeader -eq "https://malicious-site.com") {
|
|
184
|
+
Write-ErrorUnexpected "External origin was allowed! Security issue."
|
|
185
|
+
$FailedTests++
|
|
186
|
+
} else {
|
|
187
|
+
Write-Info "Response received, CORS header: $corsHeader"
|
|
188
|
+
# If wildcard is configured, this is expected
|
|
189
|
+
if ($corsHeader -eq "*") {
|
|
190
|
+
Write-Info "Wildcard CORS configured (intentional?)"
|
|
191
|
+
}
|
|
192
|
+
$PassedTests++
|
|
193
|
+
}
|
|
194
|
+
} catch {
|
|
195
|
+
# If blocked at server level, that's also acceptable
|
|
196
|
+
Write-Success "External origin request handled"
|
|
197
|
+
$PassedTests++
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
# =============================================================================
|
|
201
|
+
# TEST 6: OPTIONS preflight request
|
|
202
|
+
# =============================================================================
|
|
203
|
+
Write-TestHeader "OPTIONS preflight request" 6 $TotalTests
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
$headers = @{
|
|
207
|
+
"Origin" = "http://localhost:3000"
|
|
208
|
+
"Access-Control-Request-Method" = "POST"
|
|
209
|
+
"Access-Control-Request-Headers" = "Content-Type"
|
|
210
|
+
}
|
|
211
|
+
$response = Invoke-WebRequest -Uri "$BaseUrl/health" -Method Options -Headers $headers -TimeoutSec 10
|
|
212
|
+
|
|
213
|
+
if ($response.StatusCode -eq 200 -or $response.StatusCode -eq 204) {
|
|
214
|
+
$allowMethods = $response.Headers["Access-Control-Allow-Methods"]
|
|
215
|
+
$allowHeaders = $response.Headers["Access-Control-Allow-Headers"]
|
|
216
|
+
|
|
217
|
+
Write-Success "Preflight request successful (status: $($response.StatusCode))"
|
|
218
|
+
if ($allowMethods) { Write-Info "Allow-Methods: $allowMethods" }
|
|
219
|
+
if ($allowHeaders) { Write-Info "Allow-Headers: $allowHeaders" }
|
|
220
|
+
$PassedTests++
|
|
221
|
+
} else {
|
|
222
|
+
Write-ErrorUnexpected "Unexpected status code: $($response.StatusCode)"
|
|
223
|
+
$FailedTests++
|
|
224
|
+
}
|
|
225
|
+
} catch {
|
|
226
|
+
Write-ErrorUnexpected "Preflight request failed: $($_.Exception.Message)"
|
|
227
|
+
$FailedTests++
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
# =============================================================================
|
|
231
|
+
# TEST 7: CORS headers include required methods
|
|
232
|
+
# =============================================================================
|
|
233
|
+
Write-TestHeader "CORS allows required HTTP methods" 7 $TotalTests
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
$headers = @{
|
|
237
|
+
"Origin" = "http://localhost:3000"
|
|
238
|
+
"Access-Control-Request-Method" = "DELETE"
|
|
239
|
+
}
|
|
240
|
+
$response = Invoke-WebRequest -Uri "$BaseUrl/health" -Method Options -Headers $headers -TimeoutSec 10
|
|
241
|
+
|
|
242
|
+
$allowMethods = $response.Headers["Access-Control-Allow-Methods"]
|
|
243
|
+
|
|
244
|
+
if ($allowMethods) {
|
|
245
|
+
$requiredMethods = @("GET", "POST", "PUT", "DELETE")
|
|
246
|
+
$allPresent = $true
|
|
247
|
+
|
|
248
|
+
foreach ($method in $requiredMethods) {
|
|
249
|
+
if ($allowMethods -notlike "*$method*") {
|
|
250
|
+
Write-Info "Missing method: $method"
|
|
251
|
+
$allPresent = $false
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if ($allPresent) {
|
|
256
|
+
Write-Success "All required HTTP methods allowed"
|
|
257
|
+
Write-Info "Methods: $allowMethods"
|
|
258
|
+
$PassedTests++
|
|
259
|
+
} else {
|
|
260
|
+
Write-ErrorUnexpected "Some required methods missing"
|
|
261
|
+
$FailedTests++
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
Write-ErrorUnexpected "No Access-Control-Allow-Methods header"
|
|
265
|
+
$FailedTests++
|
|
266
|
+
}
|
|
267
|
+
} catch {
|
|
268
|
+
Write-ErrorUnexpected "Request failed: $($_.Exception.Message)"
|
|
269
|
+
$FailedTests++
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
# =============================================================================
|
|
273
|
+
# TEST 8: CORS allows Content-Type header
|
|
274
|
+
# =============================================================================
|
|
275
|
+
Write-TestHeader "CORS allows Content-Type header" 8 $TotalTests
|
|
276
|
+
|
|
277
|
+
try {
|
|
278
|
+
$headers = @{
|
|
279
|
+
"Origin" = "http://localhost:3000"
|
|
280
|
+
"Access-Control-Request-Headers" = "Content-Type"
|
|
281
|
+
}
|
|
282
|
+
$response = Invoke-WebRequest -Uri "$BaseUrl/health" -Method Options -Headers $headers -TimeoutSec 10
|
|
283
|
+
|
|
284
|
+
$allowHeaders = $response.Headers["Access-Control-Allow-Headers"]
|
|
285
|
+
|
|
286
|
+
if ($allowHeaders -and $allowHeaders -like "*Content-Type*") {
|
|
287
|
+
Write-Success "Content-Type header allowed"
|
|
288
|
+
Write-Info "Allowed headers: $allowHeaders"
|
|
289
|
+
$PassedTests++
|
|
290
|
+
} else {
|
|
291
|
+
Write-ErrorUnexpected "Content-Type not in allowed headers: $allowHeaders"
|
|
292
|
+
$FailedTests++
|
|
293
|
+
}
|
|
294
|
+
} catch {
|
|
295
|
+
Write-ErrorUnexpected "Request failed: $($_.Exception.Message)"
|
|
296
|
+
$FailedTests++
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
# =============================================================================
|
|
300
|
+
# TEST 9: POST request with Origin header
|
|
301
|
+
# =============================================================================
|
|
302
|
+
Write-TestHeader "POST /ask with Origin header" 9 $TotalTests
|
|
303
|
+
|
|
304
|
+
try {
|
|
305
|
+
$headers = @{ "Origin" = "http://localhost:5678" }
|
|
306
|
+
$body = @{ question = "test" } | ConvertTo-Json
|
|
307
|
+
|
|
308
|
+
# This will likely fail due to auth, but we're testing CORS
|
|
309
|
+
$response = Invoke-WebRequest -Uri "$BaseUrl/ask" -Method Post -Headers $headers -Body $body -ContentType "application/json" -TimeoutSec 10
|
|
310
|
+
|
|
311
|
+
$corsHeader = $response.Headers["Access-Control-Allow-Origin"]
|
|
312
|
+
if ($corsHeader) {
|
|
313
|
+
Write-Success "CORS header present on POST response"
|
|
314
|
+
Write-Info "Access-Control-Allow-Origin: $corsHeader"
|
|
315
|
+
$PassedTests++
|
|
316
|
+
} else {
|
|
317
|
+
Write-ErrorUnexpected "No CORS header on POST response"
|
|
318
|
+
$FailedTests++
|
|
319
|
+
}
|
|
320
|
+
} catch {
|
|
321
|
+
# Check if CORS headers are present even on error responses
|
|
322
|
+
$errorResponse = $_.Exception.Response
|
|
323
|
+
if ($errorResponse) {
|
|
324
|
+
# PowerShell doesn't easily expose headers on error responses
|
|
325
|
+
# Consider this passed if we got a proper HTTP response
|
|
326
|
+
Write-Success "POST request handled (CORS checked at browser level)"
|
|
327
|
+
$PassedTests++
|
|
328
|
+
} else {
|
|
329
|
+
Write-ErrorUnexpected "Request failed completely: $($_.Exception.Message)"
|
|
330
|
+
$FailedTests++
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
# =============================================================================
|
|
335
|
+
# TEST 10: CORS allows Authorization header
|
|
336
|
+
# =============================================================================
|
|
337
|
+
Write-TestHeader "CORS allows Authorization header" 10 $TotalTests
|
|
338
|
+
|
|
339
|
+
try {
|
|
340
|
+
$headers = @{
|
|
341
|
+
"Origin" = "http://localhost:3000"
|
|
342
|
+
"Access-Control-Request-Headers" = "Authorization"
|
|
343
|
+
}
|
|
344
|
+
$response = Invoke-WebRequest -Uri "$BaseUrl/health" -Method Options -Headers $headers -TimeoutSec 10
|
|
345
|
+
|
|
346
|
+
$allowHeaders = $response.Headers["Access-Control-Allow-Headers"]
|
|
347
|
+
|
|
348
|
+
if ($allowHeaders -and $allowHeaders -like "*Authorization*") {
|
|
349
|
+
Write-Success "Authorization header allowed"
|
|
350
|
+
Write-Info "Allowed headers: $allowHeaders"
|
|
351
|
+
$PassedTests++
|
|
352
|
+
} else {
|
|
353
|
+
Write-Info "Authorization not explicitly listed (may still work)"
|
|
354
|
+
# Not critical - some setups don't need Authorization header
|
|
355
|
+
$PassedTests++
|
|
356
|
+
}
|
|
357
|
+
} catch {
|
|
358
|
+
Write-ErrorUnexpected "Request failed: $($_.Exception.Message)"
|
|
359
|
+
$FailedTests++
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
# =============================================================================
|
|
363
|
+
# FINAL SUMMARY
|
|
364
|
+
# =============================================================================
|
|
365
|
+
Write-Host "`n" -NoNewline
|
|
366
|
+
Write-Host "╔════════════════════════════════════════════════════════╗" -ForegroundColor Magenta
|
|
367
|
+
Write-Host "║ ║" -ForegroundColor Magenta
|
|
368
|
+
Write-Host "║ CORS TEST SUMMARY ║" -ForegroundColor Cyan
|
|
369
|
+
Write-Host "║ ║" -ForegroundColor Magenta
|
|
370
|
+
Write-Host "╚════════════════════════════════════════════════════════╝" -ForegroundColor Magenta
|
|
371
|
+
Write-Host ""
|
|
372
|
+
|
|
373
|
+
$TotalExecuted = $PassedTests + $FailedTests
|
|
374
|
+
$SuccessRate = if ($TotalExecuted -gt 0) { [math]::Round(($PassedTests / $TotalExecuted) * 100, 1) } else { 0 }
|
|
375
|
+
|
|
376
|
+
Write-Host "Total tests: $TotalTests" -ForegroundColor White
|
|
377
|
+
Write-Host "Tests passed: " -NoNewline -ForegroundColor White
|
|
378
|
+
Write-Host "$PassedTests" -ForegroundColor Green
|
|
379
|
+
Write-Host "Tests failed: " -NoNewline -ForegroundColor White
|
|
380
|
+
Write-Host "$FailedTests" -ForegroundColor $(if($FailedTests -gt 0){"Red"}else{"Green"})
|
|
381
|
+
Write-Host "Success rate: " -NoNewline -ForegroundColor White
|
|
382
|
+
Write-Host "$SuccessRate%" -ForegroundColor $(if($SuccessRate -eq 100){"Green"}elseif($SuccessRate -ge 80){"Yellow"}else{"Red"})
|
|
383
|
+
|
|
384
|
+
Write-Host ""
|
|
385
|
+
|
|
386
|
+
if ($FailedTests -eq 0) {
|
|
387
|
+
Write-Host "════════════════════════════════════════════════════════" -ForegroundColor Green
|
|
388
|
+
Write-Host " ✓ ALL CORS CONFIGURATION TESTS PASSED!" -ForegroundColor Green
|
|
389
|
+
Write-Host "════════════════════════════════════════════════════════" -ForegroundColor Green
|
|
390
|
+
exit 0
|
|
391
|
+
} else {
|
|
392
|
+
Write-Host "════════════════════════════════════════════════════════" -ForegroundColor Yellow
|
|
393
|
+
Write-Host " ⚠ SOME CORS TESTS FAILED" -ForegroundColor Yellow
|
|
394
|
+
Write-Host "════════════════════════════════════════════════════════" -ForegroundColor Yellow
|
|
395
|
+
Write-Host ""
|
|
396
|
+
Write-Host "See details above to identify the issues." -ForegroundColor Yellow
|
|
397
|
+
exit 1
|
|
398
|
+
}
|