Make server unix socket file permission configurable via flag UnixSocketPerm (#2763)
* feat(any): Add flag unixsocketperm with default 0017 - #2625 Signed-off-by: johannesengl <hello@johannesengl.com> * feat(server): Update unix socket file perm based on config - #2625 Signed-off-by: johannesengl <hello@johannesengl.com> * Fix default value of socket. * Refactor unix socket file creation. * Remove misplaced comment --------- Signed-off-by: johannesengl <hello@johannesengl.com> Co-authored-by: Caio Cotts <caio@cotts.com.br> Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
@@ -58,3 +61,49 @@ var _ = Describe("AbsoluteURL", func() {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
var _ = Describe("createUnixSocketFile", func() {
|
||||
var socketPath string
|
||||
|
||||
BeforeEach(func() {
|
||||
tempDir, _ := os.MkdirTemp("", "create_unix_socket_file_test")
|
||||
socketPath = filepath.Join(tempDir, "test.sock")
|
||||
DeferCleanup(func() {
|
||||
_ = os.RemoveAll(tempDir)
|
||||
})
|
||||
})
|
||||
|
||||
When("unixSocketPerm is valid", func() {
|
||||
It("updates the permission of the unix socket file and returns nil", func() {
|
||||
_, err := createUnixSocketFile(socketPath, "0777")
|
||||
fileInfo, _ := os.Stat(socketPath)
|
||||
actualPermission := fileInfo.Mode().Perm()
|
||||
|
||||
Expect(actualPermission).To(Equal(os.FileMode(0777)))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
When("unixSocketPerm is invalid", func() {
|
||||
It("returns an error", func() {
|
||||
_, err := createUnixSocketFile(socketPath, "invalid")
|
||||
Expect(err).To(HaveOccurred())
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
When("file already exists", func() {
|
||||
It("recreates the file as a socket with the right permissions", func() {
|
||||
_, err := os.Create(socketPath)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(os.Chmod(socketPath, os.FileMode(0777))).To(Succeed())
|
||||
|
||||
_, err = createUnixSocketFile(socketPath, "0600")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
fileInfo, _ := os.Stat(socketPath)
|
||||
Expect(fileInfo.Mode().Perm()).To(Equal(os.FileMode(0600)))
|
||||
Expect(fileInfo.Mode().Type()).To(Equal(fs.ModeSocket))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user