-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package oci | ||
|
||
import "testing" | ||
|
||
// Test_isWithin ensures that the isWithin method checks | ||
// that various combinations of parent and child paths. | ||
func Test_isWithin(t *testing.T) { | ||
tests := []struct { | ||
parent string | ||
child string | ||
want bool | ||
name string | ||
}{ | ||
{"/", "/b", true, "Base case, a subdir of an absolute path"}, | ||
{"/a", "/ab", false, "Ensure simple substring does not match"}, | ||
{"./", ".", true, "Ensure links are both made absolute"}, | ||
{"/a/b/../c", "/a/c/d/../", true, "Ensure the links are both sanitized"}, | ||
{"/a", "/a/b/../../", false, "Ensure escaping the parent is a mismatch"}, | ||
{"./", "../", false, "Ensure simple relative mismatch"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := isWithin(tt.parent, tt.child) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if got != tt.want { | ||
t.Log(tt.name) | ||
t.Errorf("isWithin() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
|
||
} |