(t *testing.T)
| 184 | } |
| 185 | |
| 186 | func TestHTTPSSetupCanPatchRunningServer(t *testing.T) { |
| 187 | configPath := writeHTTPSSetupTempConfig(t, sampleHTTPSConfig) |
| 188 | curlDir := t.TempDir() |
| 189 | curlLog := filepath.Join(curlDir, "curl.log") |
| 190 | curlStub := filepath.Join(curlDir, "curl-stub.sh") |
| 191 | curlScript := "#!/usr/bin/env sh\nprintf '%s\\n' \"$@\" >\"" + curlLog + "\"\nprintf '200'\n" |
| 192 | if err := os.WriteFile(curlStub, []byte(curlScript), 0o755); err != nil { |
| 193 | t.Fatalf("os.WriteFile() error = %v", err) |
| 194 | } |
| 195 | |
| 196 | input := strings.Join([]string{ |
| 197 | "1", |
| 198 | "", |
| 199 | "", |
| 200 | "", |
| 201 | "", |
| 202 | "", |
| 203 | "1", |
| 204 | "http://localhost/", |
| 205 | "admin", |
| 206 | "password", |
| 207 | "", |
| 208 | }, "\n") |
| 209 | |
| 210 | output := runHTTPSSetup(t, configPath, input, map[string]string{ |
| 211 | "CURL_BIN": curlStub, |
| 212 | }) |
| 213 | if !strings.Contains(output, "HTTPS setup applied through the admin API.") { |
| 214 | t.Fatalf("https-setup output did not confirm API patch:\n%s", output) |
| 215 | } |
| 216 | if !strings.Contains(output, "Restart GoMud so it rebinds the updated HTTP/HTTPS listeners.") { |
| 217 | t.Fatalf("https-setup output did not require restart after API patch:\n%s", output) |
| 218 | } |
| 219 | |
| 220 | logBytes, err := os.ReadFile(curlLog) |
| 221 | if err != nil { |
| 222 | t.Fatalf("os.ReadFile() error = %v", err) |
| 223 | } |
| 224 | curlArgs := string(logBytes) |
| 225 | if !strings.Contains(curlArgs, "http://localhost/admin/api/v1/config") { |
| 226 | t.Fatalf("curl stub did not receive config endpoint:\n%s", curlArgs) |
| 227 | } |
| 228 | if !strings.Contains(curlArgs, "FilePaths.HttpsCertFile") { |
| 229 | t.Fatalf("curl stub did not receive config payload:\n%s", curlArgs) |
| 230 | } |
| 231 | |
| 232 | updated := readHTTPSSetupConfig(t, configPath) |
| 233 | if updated != sampleHTTPSConfig { |
| 234 | t.Fatalf("https-setup changed bundled config unexpectedly:\n%s", updated) |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | func TestHTTPSSetupAutoModeAPIApplyRequiresRestart(t *testing.T) { |
| 239 | configPath := writeHTTPSSetupTempConfig(t, sampleHTTPSConfig) |
nothing calls this directly
no test coverage detected