-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix Arbitrary file access during archive extraction Zip Slip findings * Fix Incorrect conversion between integer types finding * Write test for SanitizePath * gofmt the code
- Loading branch information
Showing
4 changed files
with
59 additions
and
5 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
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,46 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSanitizePath(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
expectedOutput string | ||
}{ | ||
{ | ||
name: "Basic file name", | ||
input: "test.yaml", | ||
expectedOutput: "test.yaml", | ||
}, | ||
{ | ||
name: "Basic full path", | ||
input: "/x/test.yaml", | ||
expectedOutput: "/x/test.yaml", | ||
}, | ||
{ | ||
name: "Relative path", | ||
input: "x/test.yaml", | ||
expectedOutput: "x/test.yaml", | ||
}, | ||
{ | ||
name: "Relative path with traversal segment", | ||
input: "../x/test.yaml", | ||
expectedOutput: "x/test.yaml", | ||
}, | ||
{ | ||
name: "Relative path with traversal segment", | ||
input: "/../x/test.yaml", | ||
expectedOutput: "/x/test.yaml", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
if result := SanitizePath(tt.input); result != tt.expectedOutput { | ||
t.Errorf("Test %q failed, expectedOutput %q, got %q", tt.name, tt.expectedOutput, result) | ||
} | ||
|
||
} | ||
} |