mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 14:20:55 +03:00
config: fix bindings backward compatibility
This commit is contained in:
@@ -480,7 +480,7 @@ func checkCommonParamsCompatibility() {
|
||||
}
|
||||
|
||||
func checkSFTPDBindingsCompatibility() {
|
||||
if len(globalConf.SFTPD.Bindings) > 0 {
|
||||
if globalConf.SFTPD.BindPort == 0 { //nolint:staticcheck
|
||||
return
|
||||
}
|
||||
|
||||
@@ -495,11 +495,11 @@ func checkSFTPDBindingsCompatibility() {
|
||||
binding.Address = globalConf.SFTPD.BindAddress //nolint:staticcheck
|
||||
}
|
||||
|
||||
globalConf.SFTPD.Bindings = append(globalConf.SFTPD.Bindings, binding)
|
||||
globalConf.SFTPD.Bindings = []sftpd.Binding{binding}
|
||||
}
|
||||
|
||||
func checkFTPDBindingCompatibility() {
|
||||
if len(globalConf.FTPD.Bindings) > 0 {
|
||||
if globalConf.FTPD.BindPort == 0 { //nolint:staticcheck
|
||||
return
|
||||
}
|
||||
|
||||
@@ -520,11 +520,11 @@ func checkFTPDBindingCompatibility() {
|
||||
binding.ForcePassiveIP = globalConf.FTPD.ForcePassiveIP //nolint:staticcheck
|
||||
}
|
||||
|
||||
globalConf.FTPD.Bindings = append(globalConf.FTPD.Bindings, binding)
|
||||
globalConf.FTPD.Bindings = []ftpd.Binding{binding}
|
||||
}
|
||||
|
||||
func checkWebDAVDBindingCompatibility() {
|
||||
if len(globalConf.WebDAVD.Bindings) > 0 {
|
||||
if globalConf.WebDAVD.BindPort == 0 { //nolint:staticcheck
|
||||
return
|
||||
}
|
||||
|
||||
@@ -539,11 +539,11 @@ func checkWebDAVDBindingCompatibility() {
|
||||
binding.Address = globalConf.WebDAVD.BindAddress //nolint:staticcheck
|
||||
}
|
||||
|
||||
globalConf.WebDAVD.Bindings = append(globalConf.WebDAVD.Bindings, binding)
|
||||
globalConf.WebDAVD.Bindings = []webdavd.Binding{binding}
|
||||
}
|
||||
|
||||
func checkHTTPDBindingCompatibility() {
|
||||
if len(globalConf.HTTPDConfig.Bindings) > 0 {
|
||||
if globalConf.HTTPDConfig.BindPort == 0 { //nolint:staticcheck
|
||||
return
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ func checkHTTPDBindingCompatibility() {
|
||||
binding.Address = globalConf.HTTPDConfig.BindAddress //nolint:staticcheck
|
||||
}
|
||||
|
||||
globalConf.HTTPDConfig.Bindings = append(globalConf.HTTPDConfig.Bindings, binding)
|
||||
globalConf.HTTPDConfig.Bindings = []httpd.Binding{binding}
|
||||
}
|
||||
|
||||
func loadBindingsFromEnv() {
|
||||
|
||||
@@ -362,7 +362,6 @@ func TestServiceToStart(t *testing.T) {
|
||||
assert.True(t, config.HasServicesToStart())
|
||||
}
|
||||
|
||||
//nolint:dupl
|
||||
func TestSFTPDBindingsCompatibility(t *testing.T) {
|
||||
reset()
|
||||
|
||||
@@ -385,20 +384,11 @@ func TestSFTPDBindingsCompatibility(t *testing.T) {
|
||||
err = config.LoadConfig(configDir, confName)
|
||||
assert.NoError(t, err)
|
||||
sftpdConf = config.GetSFTPDConfig()
|
||||
// even if there is no binding configuration in sftpd conf we load the default
|
||||
// the default binding should be replaced with the deprecated configuration
|
||||
require.Len(t, sftpdConf.Bindings, 1)
|
||||
require.Equal(t, 2022, sftpdConf.Bindings[0].Port)
|
||||
require.Empty(t, sftpdConf.Bindings[0].Address)
|
||||
require.Equal(t, 9022, sftpdConf.Bindings[0].Port)
|
||||
require.Equal(t, "127.0.0.1", sftpdConf.Bindings[0].Address)
|
||||
require.True(t, sftpdConf.Bindings[0].ApplyProxyConfig)
|
||||
// now set the global value to nil and reload the configuration
|
||||
// this time we should get the values setted using the deprecated configuration
|
||||
sftpdConf.Bindings = nil
|
||||
sftpdConf.BindPort = 2022 //nolint:staticcheck
|
||||
sftpdConf.BindAddress = "" //nolint:staticcheck
|
||||
config.SetSFTPDConfig(sftpdConf)
|
||||
require.Nil(t, config.GetSFTPDConfig().Bindings)
|
||||
require.Equal(t, 2022, config.GetSFTPDConfig().BindPort) //nolint:staticcheck
|
||||
require.Empty(t, config.GetSFTPDConfig().BindAddress) //nolint:staticcheck
|
||||
|
||||
err = config.LoadConfig(configDir, confName)
|
||||
assert.NoError(t, err)
|
||||
@@ -411,7 +401,6 @@ func TestSFTPDBindingsCompatibility(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
//nolint:dupl
|
||||
func TestFTPDBindingsCompatibility(t *testing.T) {
|
||||
reset()
|
||||
|
||||
@@ -436,24 +425,7 @@ func TestFTPDBindingsCompatibility(t *testing.T) {
|
||||
err = config.LoadConfig(configDir, confName)
|
||||
assert.NoError(t, err)
|
||||
ftpdConf = config.GetFTPDConfig()
|
||||
// even if there is no binding configuration in ftpd conf we load the default
|
||||
require.Len(t, ftpdConf.Bindings, 1)
|
||||
require.Equal(t, 0, ftpdConf.Bindings[0].Port)
|
||||
require.Empty(t, ftpdConf.Bindings[0].Address)
|
||||
require.True(t, ftpdConf.Bindings[0].ApplyProxyConfig)
|
||||
// now set the global value to nil and reload the configuration
|
||||
// this time we should get the values setted using the deprecated configuration
|
||||
ftpdConf.Bindings = nil
|
||||
ftpdConf.BindPort = 0 //nolint:staticcheck
|
||||
ftpdConf.BindAddress = "" //nolint:staticcheck
|
||||
config.SetFTPDConfig(ftpdConf)
|
||||
require.Nil(t, config.GetFTPDConfig().Bindings)
|
||||
require.Equal(t, 0, config.GetFTPDConfig().BindPort) //nolint:staticcheck
|
||||
require.Empty(t, config.GetFTPDConfig().BindAddress) //nolint:staticcheck
|
||||
|
||||
err = config.LoadConfig(configDir, confName)
|
||||
assert.NoError(t, err)
|
||||
ftpdConf = config.GetFTPDConfig()
|
||||
// the default binding should be replaced with the deprecated configuration
|
||||
require.Len(t, ftpdConf.Bindings, 1)
|
||||
require.Equal(t, 9022, ftpdConf.Bindings[0].Port)
|
||||
require.Equal(t, "127.1.0.1", ftpdConf.Bindings[0].Address)
|
||||
@@ -464,7 +436,6 @@ func TestFTPDBindingsCompatibility(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
//nolint:dupl
|
||||
func TestWebDAVDBindingsCompatibility(t *testing.T) {
|
||||
reset()
|
||||
|
||||
@@ -487,24 +458,7 @@ func TestWebDAVDBindingsCompatibility(t *testing.T) {
|
||||
err = config.LoadConfig(configDir, confName)
|
||||
assert.NoError(t, err)
|
||||
webdavConf = config.GetWebDAVDConfig()
|
||||
// even if there is no binding configuration in webdav conf we load the default
|
||||
require.Len(t, webdavConf.Bindings, 1)
|
||||
require.Equal(t, 0, webdavConf.Bindings[0].Port)
|
||||
require.Empty(t, webdavConf.Bindings[0].Address)
|
||||
require.False(t, webdavConf.Bindings[0].EnableHTTPS)
|
||||
// now set the global value to nil and reload the configuration
|
||||
// this time we should get the values setted using the deprecated configuration
|
||||
webdavConf.Bindings = nil
|
||||
webdavConf.BindPort = 10080 //nolint:staticcheck
|
||||
webdavConf.BindAddress = "" //nolint:staticcheck
|
||||
config.SetWebDAVDConfig(webdavConf)
|
||||
require.Nil(t, config.GetWebDAVDConfig().Bindings)
|
||||
require.Equal(t, 10080, config.GetWebDAVDConfig().BindPort) //nolint:staticcheck
|
||||
require.Empty(t, config.GetWebDAVDConfig().BindAddress) //nolint:staticcheck
|
||||
|
||||
err = config.LoadConfig(configDir, confName)
|
||||
assert.NoError(t, err)
|
||||
webdavConf = config.GetWebDAVDConfig()
|
||||
// the default binding should be replaced with the deprecated configuration
|
||||
require.Len(t, webdavConf.Bindings, 1)
|
||||
require.Equal(t, 9080, webdavConf.Bindings[0].Port)
|
||||
require.Equal(t, "127.0.0.1", webdavConf.Bindings[0].Address)
|
||||
@@ -513,7 +467,6 @@ func TestWebDAVDBindingsCompatibility(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
//nolint:dupl
|
||||
func TestHTTPDBindingsCompatibility(t *testing.T) {
|
||||
reset()
|
||||
|
||||
@@ -536,25 +489,7 @@ func TestHTTPDBindingsCompatibility(t *testing.T) {
|
||||
err = config.LoadConfig(configDir, confName)
|
||||
assert.NoError(t, err)
|
||||
httpdConf = config.GetHTTPDConfig()
|
||||
// even if there is no binding configuration in httpd conf we load the default
|
||||
require.Len(t, httpdConf.Bindings, 1)
|
||||
require.Equal(t, 8080, httpdConf.Bindings[0].Port)
|
||||
require.Equal(t, "127.0.0.1", httpdConf.Bindings[0].Address)
|
||||
require.False(t, httpdConf.Bindings[0].EnableHTTPS)
|
||||
require.True(t, httpdConf.Bindings[0].EnableWebAdmin)
|
||||
// now set the global value to nil and reload the configuration
|
||||
// this time we should get the values setted using the deprecated configuration
|
||||
httpdConf.Bindings = nil
|
||||
httpdConf.BindPort = 10080 //nolint:staticcheck
|
||||
httpdConf.BindAddress = "" //nolint:staticcheck
|
||||
config.SetHTTPDConfig(httpdConf)
|
||||
require.Nil(t, config.GetHTTPDConfig().Bindings)
|
||||
require.Equal(t, 10080, config.GetHTTPDConfig().BindPort) //nolint:staticcheck
|
||||
require.Empty(t, config.GetHTTPDConfig().BindAddress) //nolint:staticcheck
|
||||
|
||||
err = config.LoadConfig(configDir, confName)
|
||||
assert.NoError(t, err)
|
||||
httpdConf = config.GetHTTPDConfig()
|
||||
// the default binding should be replaced with the deprecated configuration
|
||||
require.Len(t, httpdConf.Bindings, 1)
|
||||
require.Equal(t, 9080, httpdConf.Bindings[0].Port)
|
||||
require.Equal(t, "127.1.1.1", httpdConf.Bindings[0].Address)
|
||||
|
||||
Reference in New Issue
Block a user