-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(terraform): detect recursive modules (#1454)
* fix(terraform): detect recursive modules * clean up src path
- Loading branch information
Showing
5 changed files
with
98 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package resolvers | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/aquasecurity/defsec/pkg/debug" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_ResolveRecursiveSource(t *testing.T) { | ||
|
||
tests := []struct { | ||
name string | ||
dir string | ||
opt Options | ||
}{ | ||
{ | ||
name: "child module", | ||
dir: "testdata/recursive/child_module", | ||
opt: Options{ | ||
Source: "../foo", | ||
OriginalSource: "../foo", | ||
WorkingDir: "foo", | ||
Name: "module.foo", | ||
ModulePath: "foo", | ||
DebugLogger: debug.Logger{}, | ||
}, | ||
}, | ||
{ | ||
name: "dot source", | ||
dir: "testdata/recursive/dot_source", | ||
opt: Options{ | ||
Source: "./.", | ||
OriginalSource: "./.", | ||
WorkingDir: ".", | ||
Name: "module.foo", | ||
ModulePath: ".", | ||
DebugLogger: debug.Logger{}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
_, _, _, _, err := Local.Resolve(context.TODO(), os.DirFS(tt.dir), tt.opt) | ||
assert.ErrorContains(t, err, "cannot use itself as a child") | ||
}) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
pkg/scanners/terraform/parser/resolvers/testdata/recursive/child_module/foo/foo.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module "foo" { | ||
source = "../foo" | ||
} |
3 changes: 3 additions & 0 deletions
3
pkg/scanners/terraform/parser/resolvers/testdata/recursive/dot_source/foo.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module "foo" { | ||
source = "./." | ||
} |