|
|
@@ -39,7 +39,7 @@ func serve(t *testing.T, reg *commands.Registry) (*Server, string) {
|
|
|
|
|
|
path := testSocket(t)
|
|
|
s := NewServer(test.NewLogger(), reg)
|
|
|
- require.NoError(t, s.Rebind(context.Background(), path))
|
|
|
+ require.NoError(t, s.Rebind(context.Background(), path, ownerOnly()))
|
|
|
t.Cleanup(s.Stop)
|
|
|
|
|
|
return s, path
|
|
|
@@ -50,7 +50,7 @@ func serveAt(t *testing.T, path string) (*Server, func()) {
|
|
|
t.Helper()
|
|
|
|
|
|
s := NewServer(test.NewLogger(), basicRegistry())
|
|
|
- require.NoError(t, s.Rebind(context.Background(), path))
|
|
|
+ require.NoError(t, s.Rebind(context.Background(), path, ownerOnly()))
|
|
|
return s, s.Stop
|
|
|
}
|
|
|
|
|
|
@@ -183,7 +183,7 @@ func TestStaleSocketIsReplaced(t *testing.T) {
|
|
|
require.NoError(t, err, "test setup should leave a stale socket behind")
|
|
|
|
|
|
s := NewServer(test.NewLogger(), basicRegistry())
|
|
|
- require.NoError(t, s.Rebind(context.Background(), path), "a stale socket must not block startup")
|
|
|
+ require.NoError(t, s.Rebind(context.Background(), path, ownerOnly()), "a stale socket must not block startup")
|
|
|
defer s.Stop()
|
|
|
|
|
|
out, _ := run(t, path, "echo", "ok")
|
|
|
@@ -195,7 +195,7 @@ func TestLiveSocketIsNotStolen(t *testing.T) {
|
|
|
require.NotNil(t, first)
|
|
|
|
|
|
second := NewServer(test.NewLogger(), basicRegistry())
|
|
|
- err := second.Rebind(context.Background(), path)
|
|
|
+ err := second.Rebind(context.Background(), path, ownerOnly())
|
|
|
assert.ErrorContains(t, err, "already in use", "a live endpoint must not be unlinked by a second instance")
|
|
|
}
|
|
|
|
|
|
@@ -209,7 +209,7 @@ func TestLiveSocketIsNotStolenBeforeItsChmod(t *testing.T) {
|
|
|
require.NoError(t, os.Chmod(path, 0666))
|
|
|
|
|
|
second := NewServer(test.NewLogger(), basicRegistry())
|
|
|
- err := second.Rebind(context.Background(), path)
|
|
|
+ err := second.Rebind(context.Background(), path, ownerOnly())
|
|
|
require.ErrorContains(t, err, "already in use", "a live socket at any mode is not thereby dead")
|
|
|
|
|
|
_, err = os.Stat(path)
|
|
|
@@ -223,7 +223,7 @@ func TestRebindMovesTheSocket(t *testing.T) {
|
|
|
s, path := serve(t, basicRegistry())
|
|
|
next := filepath.Join(filepath.Dir(path), "n.sock")
|
|
|
|
|
|
- require.NoError(t, s.Rebind(context.Background(), next))
|
|
|
+ require.NoError(t, s.Rebind(context.Background(), next, ownerOnly()))
|
|
|
assert.Equal(t, next, s.Path())
|
|
|
|
|
|
out, _ := run(t, next, "echo", "moved")
|
|
|
@@ -236,7 +236,7 @@ func TestRebindMovesTheSocket(t *testing.T) {
|
|
|
func TestRebindFailureKeepsTheOldSocket(t *testing.T) {
|
|
|
s, path := serve(t, basicRegistry())
|
|
|
|
|
|
- err := s.Rebind(context.Background(), "/nonexistent-dir-for-tests/x.sock")
|
|
|
+ err := s.Rebind(context.Background(), "/nonexistent-dir-for-tests/x.sock", ownerOnly())
|
|
|
require.Error(t, err)
|
|
|
assert.Equal(t, path, s.Path(), "a bad path must leave the working endpoint alone")
|
|
|
|
|
|
@@ -252,16 +252,16 @@ func TestSemaphoreSurvivesRestart(t *testing.T) {
|
|
|
s := NewServer(test.NewLogger(), basicRegistry())
|
|
|
path := testSocket(t)
|
|
|
|
|
|
- require.NoError(t, s.Rebind(context.Background(), path))
|
|
|
+ require.NoError(t, s.Rebind(context.Background(), path, ownerOnly()))
|
|
|
first := s.sem
|
|
|
require.NotNil(t, first)
|
|
|
s.Stop()
|
|
|
|
|
|
- require.NoError(t, s.Rebind(context.Background(), path))
|
|
|
+ require.NoError(t, s.Rebind(context.Background(), path, ownerOnly()))
|
|
|
defer s.Stop()
|
|
|
assert.Equal(t, first, s.sem, "Rebind after Stop must keep the same semaphore")
|
|
|
|
|
|
- require.NoError(t, s.Rebind(context.Background(), testSocket(t)))
|
|
|
+ require.NoError(t, s.Rebind(context.Background(), testSocket(t), ownerOnly()))
|
|
|
assert.Equal(t, first, s.sem, "Rebind must keep the same semaphore")
|
|
|
}
|
|
|
|
|
|
@@ -274,12 +274,12 @@ func TestRestartIsWatchedOnItsOwnContext(t *testing.T) {
|
|
|
path := testSocket(t)
|
|
|
|
|
|
ctxA, cancelA := context.WithCancel(context.Background())
|
|
|
- require.NoError(t, s.Rebind(ctxA, path))
|
|
|
+ require.NoError(t, s.Rebind(ctxA, path, ownerOnly()))
|
|
|
cancelA()
|
|
|
require.Eventually(t, func() bool { return s.Path() == "" }, time.Second, 10*time.Millisecond, "the first context must stop the server")
|
|
|
|
|
|
ctxB, cancelB := context.WithCancel(context.Background())
|
|
|
- require.NoError(t, s.Rebind(ctxB, path))
|
|
|
+ require.NoError(t, s.Rebind(ctxB, path, ownerOnly()))
|
|
|
defer s.Stop()
|
|
|
assert.Equal(t, path, s.Path())
|
|
|
|
|
|
@@ -298,12 +298,12 @@ func TestStopDetachesTheWatcher(t *testing.T) {
|
|
|
|
|
|
ctxA, cancelA := context.WithCancel(context.Background())
|
|
|
t.Cleanup(cancelA)
|
|
|
- require.NoError(t, s.Rebind(ctxA, path))
|
|
|
+ require.NoError(t, s.Rebind(ctxA, path, ownerOnly()))
|
|
|
s.Stop()
|
|
|
|
|
|
ctxB, cancelB := context.WithCancel(context.Background())
|
|
|
t.Cleanup(cancelB)
|
|
|
- require.NoError(t, s.Rebind(ctxB, path))
|
|
|
+ require.NoError(t, s.Rebind(ctxB, path, ownerOnly()))
|
|
|
t.Cleanup(s.Stop)
|
|
|
|
|
|
cancelA()
|
|
|
@@ -364,7 +364,7 @@ func TestConcurrentClientsAreBounded(t *testing.T) {
|
|
|
s := NewServer(test.NewLogger(), reg)
|
|
|
s.maxConns = 2
|
|
|
path := testSocket(t)
|
|
|
- require.NoError(t, s.Rebind(context.Background(), path))
|
|
|
+ require.NoError(t, s.Rebind(context.Background(), path, ownerOnly()))
|
|
|
defer s.Stop()
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
@@ -408,7 +408,7 @@ func TestSlowCommandIsNamedInTheLog(t *testing.T) {
|
|
|
s.maxConns = 1
|
|
|
s.slowAfter = 20 * time.Millisecond
|
|
|
path := testSocket(t)
|
|
|
- require.NoError(t, s.Rebind(context.Background(), path))
|
|
|
+ require.NoError(t, s.Rebind(context.Background(), path, ownerOnly()))
|
|
|
defer s.Stop()
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
@@ -450,7 +450,7 @@ func TestPanickedCommandIsNotReportedAsStillRunning(t *testing.T) {
|
|
|
s := NewServer(test.NewLoggerWithOutput(&logs), reg)
|
|
|
s.slowAfter = 20 * time.Millisecond
|
|
|
path := testSocket(t)
|
|
|
- require.NoError(t, s.Rebind(context.Background(), path))
|
|
|
+ require.NoError(t, s.Rebind(context.Background(), path, ownerOnly()))
|
|
|
defer s.Stop()
|
|
|
|
|
|
res, err := (&Client{Path: path}).Invoke("boom", nil, nil, "")
|
|
|
@@ -502,7 +502,7 @@ func (f *flakyListener) Accept() (net.Conn, error) {
|
|
|
func TestAcceptSurvivesTransientErrors(t *testing.T) {
|
|
|
path := testSocket(t)
|
|
|
require.NoError(t, os.Mkdir(filepath.Dir(path), 0700))
|
|
|
- ln, err := listen(path)
|
|
|
+ ln, err := listen(path, ownerOnly())
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
s := NewServer(test.NewLogger(), basicRegistry())
|
|
|
@@ -537,7 +537,7 @@ func TestContextCancellationStops(t *testing.T) {
|
|
|
path := testSocket(t)
|
|
|
|
|
|
s := NewServer(test.NewLogger(), basicRegistry())
|
|
|
- require.NoError(t, s.Rebind(ctx, path))
|
|
|
+ require.NoError(t, s.Rebind(ctx, path, ownerOnly()))
|
|
|
|
|
|
cancel()
|
|
|
assert.Eventually(t, func() bool {
|
|
|
@@ -797,10 +797,10 @@ func TestRebindAfterFailedBindStillStopsOnCancel(t *testing.T) {
|
|
|
// listen creates one level only, so a socket directory under a parent that is not
|
|
|
// there yet fails to bind, the shape of a runtime directory that does not exist.
|
|
|
s := NewServer(test.NewLogger(), basicRegistry())
|
|
|
- require.Error(t, s.Rebind(ctx, filepath.Join(base, "missing", "n", "s.sock")))
|
|
|
+ require.Error(t, s.Rebind(ctx, filepath.Join(base, "missing", "n", "s.sock"), ownerOnly()))
|
|
|
|
|
|
good := filepath.Join(base, "n", "s.sock")
|
|
|
- require.NoError(t, s.Rebind(ctx, good))
|
|
|
+ require.NoError(t, s.Rebind(ctx, good, ownerOnly()))
|
|
|
t.Cleanup(s.Stop)
|
|
|
_, err := (&Client{Path: good}).Describe()
|
|
|
require.NoError(t, err)
|
|
|
@@ -891,14 +891,14 @@ func TestRebindRefusesDuringShutdown(t *testing.T) {
|
|
|
// Built by hand rather than through serve: the context watcher is installed once,
|
|
|
// by the first bind, and this test needs it on a context it can cancel.
|
|
|
s := NewServer(test.NewLogger(), basicRegistry())
|
|
|
- require.NoError(t, s.Rebind(ctx, testSocket(t)))
|
|
|
+ require.NoError(t, s.Rebind(ctx, testSocket(t), ownerOnly()))
|
|
|
t.Cleanup(s.Stop)
|
|
|
|
|
|
cancel()
|
|
|
assert.Eventually(t, func() bool { return s.Path() == "" }, 2*time.Second, 20*time.Millisecond, "the watcher stops the server")
|
|
|
|
|
|
next := testSocket(t)
|
|
|
- err := s.Rebind(ctx, next)
|
|
|
+ err := s.Rebind(ctx, next, ownerOnly())
|
|
|
require.Error(t, err)
|
|
|
require.ErrorContains(t, err, "shutting down")
|
|
|
assert.Empty(t, s.Path(), "the server stays stopped")
|
|
|
@@ -916,13 +916,13 @@ func TestRebindAndStopSerialize(t *testing.T) {
|
|
|
|
|
|
for i := 0; i < 50; i++ {
|
|
|
s := NewServer(test.NewLogger(), basicRegistry())
|
|
|
- require.NoError(t, s.Rebind(context.Background(), a))
|
|
|
+ require.NoError(t, s.Rebind(context.Background(), a, ownerOnly()))
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
wg.Add(2)
|
|
|
go func() {
|
|
|
defer wg.Done()
|
|
|
- _ = s.Rebind(context.Background(), b)
|
|
|
+ _ = s.Rebind(context.Background(), b, ownerOnly())
|
|
|
}()
|
|
|
go func() {
|
|
|
defer wg.Done()
|