mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-08-03 16:38:50 +00:00
We should only allow project names (which are specified in an atlantis.yaml file) that don't need to be url escaped. The one exceptional character is '/' which we allow because users like to name their projects to match the directory they're in. We use the same rule that Terraform uses for workspace names. I've also changed the characters that are replaced when writing out the plan filename to only remove invalid filename characters instead of just allowing alphanumeric. This is the smallest amount of change required to ensure the filename is valid.
73 lines
1.3 KiB
Go
73 lines
1.3 KiB
Go
package runtime_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/runatlantis/atlantis/server/events/runtime"
|
|
"github.com/runatlantis/atlantis/server/events/yaml/valid"
|
|
. "github.com/runatlantis/atlantis/testing"
|
|
)
|
|
|
|
func TestGetPlanFilename(t *testing.T) {
|
|
cases := []struct {
|
|
workspace string
|
|
maybeCfg *valid.Project
|
|
exp string
|
|
}{
|
|
{
|
|
"workspace",
|
|
nil,
|
|
"workspace.tfplan",
|
|
},
|
|
{
|
|
"workspace",
|
|
&valid.Project{},
|
|
"workspace.tfplan",
|
|
},
|
|
{
|
|
"workspace",
|
|
&valid.Project{
|
|
Name: String("project"),
|
|
},
|
|
"project-workspace.tfplan",
|
|
},
|
|
{
|
|
"workspace",
|
|
&valid.Project{
|
|
Name: String("project/with/slash"),
|
|
},
|
|
"project-with-slash-workspace.tfplan",
|
|
},
|
|
{
|
|
"workspace",
|
|
&valid.Project{
|
|
Name: String("project with space"),
|
|
},
|
|
"project with space-workspace.tfplan",
|
|
},
|
|
{
|
|
"workspace😀",
|
|
&valid.Project{
|
|
Name: String("project😀"),
|
|
},
|
|
"project😀-workspace😀.tfplan",
|
|
},
|
|
{
|
|
"default",
|
|
&valid.Project{
|
|
Name: String(`all.invalid.chars \/"*?<>`),
|
|
},
|
|
"all.invalid.chars --------default.tfplan",
|
|
},
|
|
}
|
|
|
|
for i, c := range cases {
|
|
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
|
|
Equals(t, c.exp, runtime.GetPlanFilename(c.workspace, c.maybeCfg))
|
|
})
|
|
}
|
|
}
|
|
|
|
func String(v string) *string { return &v }
|