Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cmd/dendrite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main

import (
"flag"
"io/fs"

"github.com/sirupsen/logrus"

Expand All @@ -34,8 +33,8 @@ var (
unixSocket = flag.String("unix-socket", "",
"EXPERIMENTAL(unstable): The HTTP listening unix socket for the server (disables http[s]-bind-address feature)",
)
unixSocketPermission = flag.Int("unix-socket-permission", 0755,
"EXPERIMENTAL(unstable): The HTTP listening unix socket permission for the server",
unixSocketPermission = flag.String("unix-socket-permission", "755",
"EXPERIMENTAL(unstable): The HTTP listening unix socket permission for the server (in chmod format like 755)",
)
httpBindAddr = flag.String("http-bind-address", ":8008", "The HTTP listening port for the server")
httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server")
Expand All @@ -59,7 +58,11 @@ func main() {
}
httpsAddr = https
} else {
httpAddr = config.UnixSocketAddress(*unixSocket, fs.FileMode(*unixSocketPermission))
socket, err := config.UnixSocketAddress(*unixSocket, *unixSocketPermission)
if err != nil {
logrus.WithError(err).Fatalf("Failed to parse unix socket")
}
httpAddr = socket
}

options := []basepkg.BaseDendriteOptions{}
Expand Down
2 changes: 1 addition & 1 deletion setup/base/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestLandingPage_UnixSocket(t *testing.T) {
tempDir := t.TempDir()
socket := path.Join(tempDir, "socket")
// start base with the listener and wait for it to be started
address := config.UnixSocketAddress(socket, 0755)
address, err := config.UnixSocketAddress(socket, "755")
assert.NoError(t, err)
go b.SetupAndServeHTTP(address, nil, nil)
time.Sleep(time.Millisecond * 100)
Expand Down
9 changes: 7 additions & 2 deletions setup/config/config_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"io/fs"
"net/url"
"strconv"
)

const (
Expand Down Expand Up @@ -32,8 +33,12 @@ func (s ServerAddress) Network() string {
}
}

func UnixSocketAddress(path string, perm fs.FileMode) ServerAddress {
return ServerAddress{Address: path, Scheme: NetworkUnix, UnixSocketPermission: perm}
func UnixSocketAddress(path string, perm string) (ServerAddress, error) {
permission, err := strconv.ParseInt(perm, 8, 32)
if err != nil {
return ServerAddress{}, err
}
return ServerAddress{Address: path, Scheme: NetworkUnix, UnixSocketPermission: fs.FileMode(permission)}, nil
}

func HTTPAddress(urlAddress string) (ServerAddress, error) {
Expand Down
20 changes: 19 additions & 1 deletion setup/config/config_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ func TestHttpAddress_ParseBad(t *testing.T) {
}

func TestUnixSocketAddress_Network(t *testing.T) {
address := UnixSocketAddress("/tmp", fs.FileMode(0755))
address, err := UnixSocketAddress("/tmp", "0755")
assert.NoError(t, err)
assert.Equal(t, "unix", address.Network())
}

func TestUnixSocketAddress_Permission_LeadingZero_Ok(t *testing.T) {
address, err := UnixSocketAddress("/tmp", "0755")
assert.NoError(t, err)
assert.Equal(t, fs.FileMode(0755), address.UnixSocketPermission)
}

func TestUnixSocketAddress_Permission_NoLeadingZero_Ok(t *testing.T) {
address, err := UnixSocketAddress("/tmp", "755")
assert.NoError(t, err)
assert.Equal(t, fs.FileMode(0755), address.UnixSocketPermission)
}

func TestUnixSocketAddress_Permission_NonOctal_Bad(t *testing.T) {
_, err := UnixSocketAddress("/tmp", "855")
assert.Error(t, err)
}