mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Backport from 1.5.x: Require valid module name (#373)
This commit is contained in:
parent
c45a8b48ca
commit
065ca8fb3b
@ -21,6 +21,7 @@ BUG FIXES:
|
||||
* Transitive dependencies were lost during apply when the referenced resource expanded into zero instances ([#33403](https://github.com/hashicorp/terraform/issues/33403))
|
||||
* OpenTF will no longer override SSH settings in local git configuration when installing modules. ([#33592](https://github.com/hashicorp/terraform/issues/33592))
|
||||
* Handle file-operation errors in `internal/states/statemgr`. ([#278](https://github.com/opentffoundation/opentf/issues/278))
|
||||
* `opentf init`: OpenTF will no longer allow downloading remote modules to invalid paths. ([#356](https://github.com/opentffoundation/opentf/issues/356))
|
||||
|
||||
## Previous Releases
|
||||
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"github.com/apparentlymart/go-versions/versions"
|
||||
version "github.com/hashicorp/go-version"
|
||||
"github.com/hashicorp/hcl/v2"
|
||||
"github.com/hashicorp/hcl/v2/hclsyntax"
|
||||
|
||||
"github.com/placeholderplaceholderplaceholder/opentf/internal/addrs"
|
||||
"github.com/placeholderplaceholderplaceholder/opentf/internal/configs"
|
||||
@ -162,6 +163,13 @@ func (i *ModuleInstaller) moduleInstallWalker(ctx context.Context, manifest mods
|
||||
return nil, nil, diags
|
||||
}
|
||||
|
||||
if !hclsyntax.ValidIdentifier(req.Name) {
|
||||
// A module with an invalid name shouldn't be installed at all. This is
|
||||
// mostly a concern for remote modules, since we need to be able to convert
|
||||
// the name to a valid path.
|
||||
return nil, nil, diags
|
||||
}
|
||||
|
||||
key := manifest.ModuleKey(req.Path)
|
||||
instPath := i.packageInstallPath(req.Path)
|
||||
|
||||
|
@ -139,6 +139,26 @@ func TestModuleInstaller_emptyModuleName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleInstaller_invalidModuleName(t *testing.T) {
|
||||
fixtureDir := filepath.Clean("testdata/invalid-module-name")
|
||||
dir, done := tempChdir(t, fixtureDir)
|
||||
defer done()
|
||||
|
||||
hooks := &testInstallHooks{}
|
||||
|
||||
modulesDir := filepath.Join(dir, ".terraform/modules")
|
||||
|
||||
loader, close := configload.NewLoaderForTests(t)
|
||||
defer close()
|
||||
inst := NewModuleInstaller(modulesDir, loader, registry.NewClient(nil, nil))
|
||||
_, diags := inst.InstallModules(context.Background(), dir, "tests", false, false, hooks)
|
||||
if !diags.HasErrors() {
|
||||
t.Fatal("expected error")
|
||||
} else {
|
||||
assertDiagnosticSummary(t, diags, "Invalid module instance name")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModuleInstaller_packageEscapeError(t *testing.T) {
|
||||
fixtureDir := filepath.Clean("testdata/load-module-package-escape")
|
||||
dir, done := tempChdir(t, fixtureDir)
|
||||
|
3
internal/initwd/testdata/invalid-module-name/child/main.tf
vendored
Normal file
3
internal/initwd/testdata/invalid-module-name/child/main.tf
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
output "boop" {
|
||||
value = "beep"
|
||||
}
|
3
internal/initwd/testdata/invalid-module-name/main.tf
vendored
Normal file
3
internal/initwd/testdata/invalid-module-name/main.tf
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
module "../invalid" {
|
||||
source = "./child"
|
||||
}
|
Loading…
Reference in New Issue
Block a user