-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add validations for symlink (#316)
Added validations to make sure singingkeys.json, trustpolicy.json and config.json doesnt read's symlink closes notaryproject/notation#634 Signed-off-by: Pritesh Bandi <[email protected]>
- Loading branch information
1 parent
9b0e472
commit 69cf11b
Showing
4 changed files
with
139 additions
and
62 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 config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/notaryproject/notation-go/dir" | ||
) | ||
|
||
func TestLoadNonExistentFile(t *testing.T) { | ||
dir.UserConfigDir = "testdata/valid" | ||
|
||
var config string | ||
err := load("non-existent", &config) | ||
if err == nil { | ||
t.Fatalf("load() expected error but not found") | ||
} | ||
} | ||
|
||
func TestLoadSymlink(t *testing.T) { | ||
root := t.TempDir() | ||
dir.UserConfigDir = root | ||
fileName := "symlink" | ||
os.Symlink("testdata/valid/config.json", filepath.Join(root, fileName)) | ||
|
||
expectedError := fmt.Sprintf("\"%s/%s\" is not a regular file (symlinks are not supported)", dir.UserConfigDir, fileName) | ||
var config string | ||
err := load(fileName, &config) | ||
if err != nil && err.Error() != expectedError { | ||
t.Fatalf("load() expected error= %s but found= %v", expectedError, err) | ||
} | ||
} |
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