|
|
@@ -28,6 +28,7 @@ import (
|
|
|
"net/url"
|
|
|
"os"
|
|
|
"sync"
|
|
|
+ "syscall"
|
|
|
"testing"
|
|
|
"time"
|
|
|
|
|
|
@@ -49,6 +50,7 @@ func TestSSH(t *testing.T) {
|
|
|
&runServerConfig{
|
|
|
tunnelProtocol: "SSH",
|
|
|
enableSSHAPIRequests: true,
|
|
|
+ doHotReload: false,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -57,6 +59,7 @@ func TestOSSH(t *testing.T) {
|
|
|
&runServerConfig{
|
|
|
tunnelProtocol: "OSSH",
|
|
|
enableSSHAPIRequests: true,
|
|
|
+ doHotReload: false,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -65,6 +68,7 @@ func TestUnfrontedMeek(t *testing.T) {
|
|
|
&runServerConfig{
|
|
|
tunnelProtocol: "UNFRONTED-MEEK-OSSH",
|
|
|
enableSSHAPIRequests: true,
|
|
|
+ doHotReload: false,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -73,6 +77,7 @@ func TestUnfrontedMeekHTTPS(t *testing.T) {
|
|
|
&runServerConfig{
|
|
|
tunnelProtocol: "UNFRONTED-MEEK-HTTPS-OSSH",
|
|
|
enableSSHAPIRequests: true,
|
|
|
+ doHotReload: false,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -81,12 +86,23 @@ func TestWebTransportAPIRequests(t *testing.T) {
|
|
|
&runServerConfig{
|
|
|
tunnelProtocol: "OSSH",
|
|
|
enableSSHAPIRequests: false,
|
|
|
+ doHotReload: false,
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+func TestHotReload(t *testing.T) {
|
|
|
+ runServer(t,
|
|
|
+ &runServerConfig{
|
|
|
+ tunnelProtocol: "OSSH",
|
|
|
+ enableSSHAPIRequests: true,
|
|
|
+ doHotReload: true,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
type runServerConfig struct {
|
|
|
tunnelProtocol string
|
|
|
enableSSHAPIRequests bool
|
|
|
+ doHotReload bool
|
|
|
}
|
|
|
|
|
|
func runServer(t *testing.T, runConfig *runServerConfig) {
|
|
|
@@ -106,7 +122,9 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
|
|
|
|
|
|
// customize server config
|
|
|
|
|
|
- psinetFilename, sponsorID, expectedHomepageURL := pavePsinetDatabaseFile(t)
|
|
|
+ // Pave psinet with random values to test handshake homepages.
|
|
|
+ psinetFilename := "psinet.json"
|
|
|
+ sponsorID, expectedHomepageURL := pavePsinetDatabaseFile(t, psinetFilename)
|
|
|
|
|
|
var serverConfig interface{}
|
|
|
json.Unmarshal(serverConfigJSON, &serverConfig)
|
|
|
@@ -149,6 +167,26 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
+ // Test: hot reload (of psinet)
|
|
|
+
|
|
|
+ if runConfig.doHotReload {
|
|
|
+ // TODO: monitor logs for more robust wait-until-loaded
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
+
|
|
|
+ // Pave a new psinet with different random values.
|
|
|
+ sponsorID, expectedHomepageURL = pavePsinetDatabaseFile(t, psinetFilename)
|
|
|
+
|
|
|
+ p, _ := os.FindProcess(os.Getpid())
|
|
|
+ p.Signal(syscall.SIGUSR1)
|
|
|
+
|
|
|
+ // TODO: monitor logs for more robust wait-until-reloaded
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
+
|
|
|
+ // After reloading psinet, the new sponsorID/expectedHomepageURL
|
|
|
+ // should be active, as tested in the client "Homepage" notice
|
|
|
+ // handler below.
|
|
|
+ }
|
|
|
+
|
|
|
// connect to server with client
|
|
|
|
|
|
// TODO: currently, TargetServerEntry only works with one tunnel
|
|
|
@@ -289,9 +327,7 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
|
|
|
response.Body.Close()
|
|
|
}
|
|
|
|
|
|
-func pavePsinetDatabaseFile(t *testing.T) (string, string, string) {
|
|
|
-
|
|
|
- psinetFilename := "psinet.json"
|
|
|
+func pavePsinetDatabaseFile(t *testing.T, psinetFilename string) (string, string) {
|
|
|
|
|
|
sponsorID, _ := psiphon.MakeRandomStringHex(8)
|
|
|
|
|
|
@@ -322,5 +358,5 @@ func pavePsinetDatabaseFile(t *testing.T) (string, string, string) {
|
|
|
t.Fatalf("error paving psinet database: %s", err)
|
|
|
}
|
|
|
|
|
|
- return psinetFilename, sponsorID, expectedHomepageURL
|
|
|
+ return sponsorID, expectedHomepageURL
|
|
|
}
|