Local control channel: unprivileged users can trigger --force-update via the running service
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package control
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRoundTrip(t *testing.T) {
|
||||
server, client := net.Pipe()
|
||||
go serveConn(server, func(cmd string) string {
|
||||
if cmd != CmdUpdateNow {
|
||||
return "ERR unknown command: " + cmd
|
||||
}
|
||||
return "OK v0.2.2 is up to date"
|
||||
})
|
||||
reply, err := readReply(client, CmdUpdateNow)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if reply != "OK v0.2.2 is up to date" {
|
||||
t.Fatalf("reply = %q", reply)
|
||||
}
|
||||
|
||||
server2, client2 := net.Pipe()
|
||||
go serveConn(server2, func(cmd string) string { return "ERR unknown command: " + cmd })
|
||||
reply, err = readReply(client2, "bogus")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.HasPrefix(reply, "ERR ") {
|
||||
t.Fatalf("reply = %q, want ERR prefix", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyReplyIsUnavailable(t *testing.T) {
|
||||
server, client := net.Pipe()
|
||||
go serveConn(server, func(cmd string) string {
|
||||
server.Close() // hang up without answering
|
||||
return ""
|
||||
})
|
||||
if _, err := readReply(client, CmdUpdateNow); !errors.Is(err, ErrUnavailable) {
|
||||
t.Fatalf("err = %v, want ErrUnavailable", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user