# My Proxy Remote Test Guide

This guide is for testing the Windows service deployment package on a remote Windows server.

## Package Contents

```text
my-goproxy-win64.exe
WinSW.NET461.exe
WinSW.NET4.exe
Install-MyProxy.ps1
Update-MyProxy.ps1
Manager-MyProxy.ps1
Uninstall-MyProxy.ps1
README.md
TEST_DEPLOY_GUIDE.md
docs\API.md
docs\CURL_API.md
```

## 1. Copy Package To Server

Copy `my-proxy-windows-service.zip` to the remote server and extract it, for example:

```text
C:\temp\my-proxy-package
```

## 2. Install Services

Open PowerShell as Administrator:

```powershell
cd C:\temp\my-proxy-package
Set-ExecutionPolicy -Scope Process Bypass -Force
.\Install-MyProxy.ps1 -EnableManagerFirewallRule
```

The installer creates:

```text
C:\app\my-proxy
```

It installs and starts two Windows services:

```text
my-proxy
my-proxy-manager
```

The installer also downloads and extracts the default certificate archive:

```text
https://download.hitoor.com/goproxy/test/proxy-ssl.tar.gz
```

Expected cert files:

```text
C:\app\my-proxy\hitoor.crt
C:\app\my-proxy\hitoor.key
```

The package includes `WinSW.NET4.exe` and `WinSW.NET461.exe`, so the server does not need to download the service wrapper from GitHub. `WinSW.NET4.exe` is used first for Windows Server 2012 compatibility.

On Windows Server 2012, the installer also falls back to a PowerShell `.tar.gz` extractor when `tar.exe` is not available.

If a previous test failed with `my-proxy-service.exe is not a valid application`, use the new package and rerun:

```powershell
.\Install-MyProxy.ps1 -EnableManagerFirewallRule
```

The new installer will overwrite the bad service wrapper.

## 3. Check Service Status

```powershell
Get-Service my-proxy,my-proxy-manager
```

Check local manager health:

```powershell
Invoke-RestMethod http://127.0.0.1:18080/health
```

Check proxy version:

```powershell
$token = "td3oisW/OhYLweb1+Zb05WpO4/Gmc+BqYbaTs3I05No="

Invoke-RestMethod `
  -Uri "http://127.0.0.1:18080/version" `
  -Headers @{ Authorization = "Bearer $token" }
```

## 4. Proxy Ports

The proxy service starts with these listening ports:

```text
8001  Magic HTTP
8002  Magic HTTPS
9001  SOCKS
9002  HTTP
9003  HTTPS
```

The installer currently opens the manager API port `18080` when `-EnableManagerFirewallRule` is used.

For remote proxy testing, open proxy ports if Windows Firewall blocks them:

```powershell
New-NetFirewallRule `
  -DisplayName "MyProxy Proxy Ports" `
  -Direction Inbound `
  -Action Allow `
  -Protocol TCP `
  -LocalPort 8001,8002,9001,9002,9003
```

## 5. API Update Test

On your control machine, use a new proxy executable file. The local file name does not matter.

Example:

```powershell
$server = "REMOTE_SERVER_IP"
$token = "td3oisW/OhYLweb1+Zb05WpO4/Gmc+BqYbaTs3I05No="
$package = ".\my-goproxy-win64.exe"
$sha256 = (Get-FileHash $package -Algorithm SHA256).Hash

Invoke-RestMethod `
  -Uri "http://${server}:18080/update" `
  -Method Post `
  -Headers @{
    Authorization = "Bearer $token"
    "X-Proxy-Sha256" = $sha256
  } `
  -InFile $package `
  -ContentType "application/octet-stream"
```

The remote server will:

```text
save uploaded exe
verify SHA256
stop my-proxy
backup old C:\app\my-proxy\my-goproxy-win64.exe
replace it with the uploaded exe
start my-proxy
return update result
```

The uploaded file is always installed as:

```text
C:\app\my-proxy\my-goproxy-win64.exe
```

## 6. Rollback Test

```powershell
$server = "REMOTE_SERVER_IP"
$token = "td3oisW/OhYLweb1+Zb05WpO4/Gmc+BqYbaTs3I05No="

Invoke-RestMethod `
  -Uri "http://${server}:18080/rollback" `
  -Method Post `
  -Headers @{ Authorization = "Bearer $token" }
```

## 7. Uninstall

On the remote server, open PowerShell as Administrator:

```powershell
C:\app\my-proxy\Uninstall-MyProxy.ps1
```

Remove installed files too:

```powershell
C:\app\my-proxy\Uninstall-MyProxy.ps1 -RemoveFiles
```
