feat(server,client): remote install mode, install survives missing systemd
This commit is contained in:
1 parent
c2e9284a63
commit
e89cf7864a
6 files changed
+83
-18
No files matched your search
@@ -9,8 +9,10 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -204,3 +206,36 @@ func TestMachinesShowWhoIsOnline(t *testing.T) {
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstallScriptModes(t *testing.T) {
|
||||
url := newServer(t)
|
||||
var code protocol.CodeResponse
|
||||
call(t, http.MethodPost, url+"/api/codes", adminToken, nil, &code)
|
||||
if code.RemoteCommand != "curl -fsSL "+url+"/i/"+code.Code+"/remote | sh" {
|
||||
t.Fatalf("remote command = %q", code.RemoteCommand)
|
||||
}
|
||||
for path, mode := range map[string]string{"/i/" + code.Code: "login", "/i/" + code.Code + "/remote": "remote"} {
|
||||
res, err := http.Get(url + path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
script, _ := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK || !strings.Contains(string(script), `mode="`+mode+`"`) || !strings.Contains(string(script), `code="`+code.Code+`"`) {
|
||||
t.Fatalf("%s: %d\n%s", path, res.StatusCode, script)
|
||||
}
|
||||
check := exec.Command("sh", "-n")
|
||||
check.Stdin = bytes.NewReader(script)
|
||||
if out, err := check.CombinedOutput(); err != nil {
|
||||
t.Fatalf("%s is not valid sh: %v %s", path, err, out)
|
||||
}
|
||||
}
|
||||
res, err := http.Get(url + "/i/abcdef/remote")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res.Body.Close()
|
||||
if res.StatusCode != http.StatusNotFound {
|
||||
t.Fatalf("unknown code: %d", res.StatusCode)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user