aboutsummaryrefslogtreecommitdiff
path: root/setup
diff options
context:
space:
mode:
Diffstat (limited to 'setup')
-rw-r--r--setup/base/base_test.go2
-rw-r--r--setup/config/config_address.go9
-rw-r--r--setup/config/config_address_test.go20
3 files changed, 27 insertions, 4 deletions
diff --git a/setup/base/base_test.go b/setup/base/base_test.go
index 658dc5b0..aa406db2 100644
--- a/setup/base/base_test.go
+++ b/setup/base/base_test.go
@@ -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)
diff --git a/setup/config/config_address.go b/setup/config/config_address.go
index 0e4f0296..a35cc3f9 100644
--- a/setup/config/config_address.go
+++ b/setup/config/config_address.go
@@ -3,6 +3,7 @@ package config
import (
"io/fs"
"net/url"
+ "strconv"
)
const (
@@ -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) {
diff --git a/setup/config/config_address_test.go b/setup/config/config_address_test.go
index 1be484fd..38c96ab7 100644
--- a/setup/config/config_address_test.go
+++ b/setup/config/config_address_test.go
@@ -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)
+}