41 lines
1.7 KiB
PowerShell
41 lines
1.7 KiB
PowerShell
$ErrorActionPreference = "Stop"
|
|
|
|
. (Join-Path $PSScriptRoot "Initialize-ServerHttpBindIp.ps1")
|
|
|
|
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ("easyai-bind-test-" + [guid]::NewGuid().ToString("N"))
|
|
New-Item -ItemType Directory -Path $tempDir | Out-Null
|
|
$envPath = Join-Path $tempDir ".env"
|
|
|
|
function Assert-BindIp {
|
|
param([string]$PublicApiUrl, [string]$Expected)
|
|
[System.IO.File]::WriteAllText($envPath, "NUXT_PUBLIC_BASE_APIURL=$PublicApiUrl`n", [System.Text.UTF8Encoding]::new($false))
|
|
Initialize-ServerHttpBindIp -Path $envPath
|
|
$content = Get-Content $envPath -Raw -Encoding UTF8
|
|
if ($content -notmatch "(?m)^SERVER_HTTP_BIND_IP=$([regex]::Escape($Expected))$") {
|
|
throw "Expected SERVER_HTTP_BIND_IP=$Expected for $PublicApiUrl"
|
|
}
|
|
}
|
|
|
|
try {
|
|
Assert-BindIp "/api" "127.0.0.1"
|
|
Assert-BindIp "http://10.0.0.8:3001" "0.0.0.0"
|
|
Assert-BindIp "http://127.0.0.1:3001" "127.0.0.1"
|
|
|
|
[System.IO.File]::WriteAllText($envPath, "NUXT_PUBLIC_BASE_APIURL=/api`nSERVER_HTTP_BIND_IP=0.0.0.0`n", [System.Text.UTF8Encoding]::new($false))
|
|
Initialize-ServerHttpBindIp -Path $envPath
|
|
if ((Get-Content $envPath -Raw -Encoding UTF8) -notmatch '(?m)^SERVER_HTTP_BIND_IP=0\.0\.0\.0$') {
|
|
throw "Existing explicit bind value was not preserved"
|
|
}
|
|
|
|
$invalidAccepted = $false
|
|
try {
|
|
Initialize-ServerHttpBindIp -Path $envPath -Override "192.168.1.8"
|
|
$invalidAccepted = $true
|
|
} catch { }
|
|
if ($invalidAccepted) { throw "Invalid SERVER_HTTP_BIND_IP unexpectedly accepted" }
|
|
|
|
Write-Host "Server HTTP bind IP PowerShell tests passed"
|
|
} finally {
|
|
Remove-Item -Recurse -Force $tempDir -ErrorAction SilentlyContinue
|
|
}
|