mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 15:38:57 +01:00
config: Fix generated passwords being stored as empty password - Fixes #3492
This commit is contained in:
parent
0edbc9578d
commit
693112d57e
@ -89,6 +89,9 @@ var (
|
|||||||
// For security reasons, the temp file is deleted once the configKey is successfully loaded.
|
// For security reasons, the temp file is deleted once the configKey is successfully loaded.
|
||||||
// This can be used to pass the configKey to a child process.
|
// This can be used to pass the configKey to a child process.
|
||||||
PassConfigKeyForDaemonization = false
|
PassConfigKeyForDaemonization = false
|
||||||
|
|
||||||
|
// Password can be used to configure the random password generator
|
||||||
|
Password = random.Password
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -854,6 +857,7 @@ func ChooseOption(o *fs.Option, name string) string {
|
|||||||
actions = append(actions, "nNo leave this optional password blank")
|
actions = append(actions, "nNo leave this optional password blank")
|
||||||
}
|
}
|
||||||
var password string
|
var password string
|
||||||
|
var err error
|
||||||
switch i := Command(actions); i {
|
switch i := Command(actions); i {
|
||||||
case 'y':
|
case 'y':
|
||||||
password = ChangePassword("the")
|
password = ChangePassword("the")
|
||||||
@ -861,7 +865,7 @@ func ChooseOption(o *fs.Option, name string) string {
|
|||||||
for {
|
for {
|
||||||
fmt.Printf("Password strength in bits.\n64 is just about memorable\n128 is secure\n1024 is the maximum\n")
|
fmt.Printf("Password strength in bits.\n64 is just about memorable\n128 is secure\n1024 is the maximum\n")
|
||||||
bits := ChooseNumber("Bits", 64, 1024)
|
bits := ChooseNumber("Bits", 64, 1024)
|
||||||
password, err := random.Password(bits)
|
password, err = Password(bits)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to make password: %v", err)
|
log.Fatalf("Failed to make password: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ func testConfigFile(t *testing.T, configFileName string) func() {
|
|||||||
oldConfig := fs.Config
|
oldConfig := fs.Config
|
||||||
oldConfigFile := configFile
|
oldConfigFile := configFile
|
||||||
oldReadLine := ReadLine
|
oldReadLine := ReadLine
|
||||||
|
oldPassword := Password
|
||||||
os.Stdout = nil
|
os.Stdout = nil
|
||||||
ConfigPath = path
|
ConfigPath = path
|
||||||
fs.Config = &fs.ConfigInfo{}
|
fs.Config = &fs.ConfigInfo{}
|
||||||
@ -63,6 +64,7 @@ func testConfigFile(t *testing.T, configFileName string) func() {
|
|||||||
os.Stdout = oldOsStdout
|
os.Stdout = oldOsStdout
|
||||||
ConfigPath = oldConfigPath
|
ConfigPath = oldConfigPath
|
||||||
ReadLine = oldReadLine
|
ReadLine = oldReadLine
|
||||||
|
Password = oldPassword
|
||||||
fs.Config = oldConfig
|
fs.Config = oldConfig
|
||||||
configFile = oldConfigFile
|
configFile = oldConfigFile
|
||||||
|
|
||||||
@ -71,24 +73,28 @@ func testConfigFile(t *testing.T, configFileName string) func() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCRUD(t *testing.T) {
|
// makeReadLine makes a simple readLine which returns a fixed list of
|
||||||
defer testConfigFile(t, "crud.conf")()
|
// strings
|
||||||
|
func makeReadLine(answers []string) func() string {
|
||||||
// expect script for creating remote
|
|
||||||
i := 0
|
i := 0
|
||||||
ReadLine = func() string {
|
return func() string {
|
||||||
answers := []string{
|
|
||||||
"config_test_remote", // type
|
|
||||||
"true", // bool value
|
|
||||||
"y", // type my own password
|
|
||||||
"secret", // password
|
|
||||||
"secret", // repeat
|
|
||||||
"y", // looks good, save
|
|
||||||
}
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
return answers[i-1]
|
return answers[i-1]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCRUD(t *testing.T) {
|
||||||
|
defer testConfigFile(t, "crud.conf")()
|
||||||
|
|
||||||
|
// script for creating remote
|
||||||
|
ReadLine = makeReadLine([]string{
|
||||||
|
"config_test_remote", // type
|
||||||
|
"true", // bool value
|
||||||
|
"y", // type my own password
|
||||||
|
"secret", // password
|
||||||
|
"secret", // repeat
|
||||||
|
"y", // looks good, save
|
||||||
|
})
|
||||||
NewRemote("test")
|
NewRemote("test")
|
||||||
|
|
||||||
assert.Equal(t, []string{"test"}, configFile.GetSectionList())
|
assert.Equal(t, []string{"test"}, configFile.GetSectionList())
|
||||||
@ -97,7 +103,11 @@ func TestCRUD(t *testing.T) {
|
|||||||
assert.Equal(t, "secret", obscure.MustReveal(FileGet("test", "pass")))
|
assert.Equal(t, "secret", obscure.MustReveal(FileGet("test", "pass")))
|
||||||
|
|
||||||
// normal rename, test → asdf
|
// normal rename, test → asdf
|
||||||
ReadLine = func() string { return "asdf" }
|
ReadLine = makeReadLine([]string{
|
||||||
|
"asdf",
|
||||||
|
"asdf",
|
||||||
|
"asdf",
|
||||||
|
})
|
||||||
RenameRemote("test")
|
RenameRemote("test")
|
||||||
|
|
||||||
assert.Equal(t, []string{"asdf"}, configFile.GetSectionList())
|
assert.Equal(t, []string{"asdf"}, configFile.GetSectionList())
|
||||||
@ -118,6 +128,41 @@ func TestCRUD(t *testing.T) {
|
|||||||
assert.Equal(t, []string{}, configFile.GetSectionList())
|
assert.Equal(t, []string{}, configFile.GetSectionList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestChooseOption(t *testing.T) {
|
||||||
|
defer testConfigFile(t, "crud.conf")()
|
||||||
|
|
||||||
|
// script for creating remote
|
||||||
|
ReadLine = makeReadLine([]string{
|
||||||
|
"config_test_remote", // type
|
||||||
|
"false", // bool value
|
||||||
|
"x", // bad choice
|
||||||
|
"g", // generate password
|
||||||
|
"1024", // very big
|
||||||
|
"y", // password OK
|
||||||
|
"y", // looks good, save
|
||||||
|
})
|
||||||
|
Password = func(bits int) (string, error) {
|
||||||
|
assert.Equal(t, 1024, bits)
|
||||||
|
return "not very random password", nil
|
||||||
|
}
|
||||||
|
NewRemote("test")
|
||||||
|
|
||||||
|
assert.Equal(t, "false", FileGet("test", "bool"))
|
||||||
|
assert.Equal(t, "not very random password", obscure.MustReveal(FileGet("test", "pass")))
|
||||||
|
|
||||||
|
// script for creating remote
|
||||||
|
ReadLine = makeReadLine([]string{
|
||||||
|
"config_test_remote", // type
|
||||||
|
"true", // bool value
|
||||||
|
"n", // not required
|
||||||
|
"y", // looks good, save
|
||||||
|
})
|
||||||
|
NewRemote("test")
|
||||||
|
|
||||||
|
assert.Equal(t, "true", FileGet("test", "bool"))
|
||||||
|
assert.Equal(t, "", FileGet("test", "pass"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateUpatePasswordRemote(t *testing.T) {
|
func TestCreateUpatePasswordRemote(t *testing.T) {
|
||||||
defer testConfigFile(t, "update.conf")()
|
defer testConfigFile(t, "update.conf")()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user