mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-11-20 00:01:06 +00:00
renderUpgradeEnv still wrote the .env with godotenv.Marshal, which turns any value that parses as an integer into its canonical form. A password such as 0123 was rewritten as 123 on upgrade, the same bug #14180 fixed for install. Use the env package marshaller, and escape $ inside double quotes there so values containing both $ and a quote still read back unchanged.
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/1Panel-dev/1Panel/agent/app/model"
|
|
"github.com/1Panel-dev/1Panel/agent/utils/docker"
|
|
"github.com/1Panel-dev/1Panel/agent/utils/re"
|
|
)
|
|
|
|
func TestRenderUpgradeEnvKeepsValuesExactly(t *testing.T) {
|
|
re.Init()
|
|
compose := []byte("services:\n demo:\n image: demo:1.0\n environment:\n PASSWORD: ${PANEL_DB_ROOT_PASSWORD}\n")
|
|
for _, password := range []string{"0123", "+123456", "-01"} {
|
|
install := &model.AppInstall{
|
|
App: model.App{Key: "demo"},
|
|
Env: `{"PANEL_DB_ROOT_PASSWORD":"` + password + `"}`,
|
|
}
|
|
content, err := renderUpgradeEnv(install, []byte("PANEL_DB_ROOT_PASSWORD=\""+password+"\"\n"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
project, err := docker.GetComposeProject("demo", t.TempDir(), compose, content, false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := ""
|
|
if value := project.Services["demo"].Environment["PASSWORD"]; value != nil {
|
|
got = *value
|
|
}
|
|
if got != password {
|
|
t.Errorf("password %q rendered as %q, which the compose project reads as %q", password, content, got)
|
|
}
|
|
}
|
|
}
|