-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The [opa eval] command is unable to access Rego policies located on other drives on windows #6922
Changes from all commits
3a9a702
02dc039
9601e7e
b2f071f
035070d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
"path" | ||
"path/filepath" | ||
"reflect" | ||
"runtime" | ||
"sort" | ||
"strings" | ||
"testing" | ||
|
@@ -808,15 +809,19 @@ func TestLoadFileURL(t *testing.T) { | |
files := map[string]string{ | ||
"/a/a/1.json": `1`, // this will load as a directory (e.g., file://a/a) | ||
"b.json": `{"b": 2}`, // this will load as a normal file | ||
"c.json": `3`, // this will loas as rooted file | ||
"c.json": `3`, // this will load as rooted file | ||
"d.json": `{"d": 4}`, // this will load as a normal file without the prefix file:/// | ||
} | ||
test.WithTempFS(files, func(rootDir string) { | ||
|
||
paths := mustListPaths(rootDir, false)[1:] | ||
sort.Strings(paths) | ||
|
||
for i := range paths { | ||
paths[i] = "file://" + paths[i] | ||
fileURLPrefix := "file://" | ||
if IsWindows() { | ||
fileURLPrefix = "file:///" | ||
} | ||
for i := range paths[:3] { | ||
paths[i] = fileURLPrefix + paths[i] | ||
} | ||
|
||
paths[2] = "c:" + paths[2] | ||
|
@@ -826,13 +831,18 @@ func TestLoadFileURL(t *testing.T) { | |
t.Fatal(err) | ||
} | ||
|
||
exp := parseJSON(`{"a": 1, "b": 2, "c": 3}`) | ||
exp := parseJSON(`{"a": 1, "b": 2, "c": 3, "d":4}`) | ||
if !reflect.DeepEqual(exp, result.Documents) { | ||
t.Fatalf("Expected %v but got %v", exp, result.Documents) | ||
} | ||
}) | ||
} | ||
|
||
// IsWindows: checks if the user's OS is Windows | ||
func IsWindows() bool { | ||
return runtime.GOOS == "windows" | ||
} | ||
|
||
func TestUnsupportedURLScheme(t *testing.T) { | ||
_, err := NewFileLoader().All([]string{"http://openpolicyagent.org"}) | ||
if err == nil || !strings.Contains(err.Error(), "unsupported URL scheme: http://openpolicyagent.org") { | ||
|
@@ -879,6 +889,15 @@ func TestSplitPrefix(t *testing.T) { | |
wantParts: []string{"x", "y"}, | ||
wantPath: "file:///c:/a/b/c", | ||
}, | ||
{ | ||
input: "c:/a/b/c", | ||
wantPath: "c:/a/b/c", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem compatible with how data prefixes work in OPA, as we'd expect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it advisable to always use a file URL(ex: In this image, we see that using |
||
}, | ||
{ | ||
input: "c:file:///c:/a/b/c", | ||
wantParts: []string{"c"}, | ||
wantPath: "file:///c:/a/b/c", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we put significance on the path containing
file:///
or the document prefix being more than one chars long for us to return those parts rather than the givenpath
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add some context: I believe the prefix part is the prefix for which the contents of that file will be found under the
data
document during evaluation.E.g.: given the following data file
data.json
:and we run:
we expect the output:
But if we add the
a:
prefix to the file path, we expect this prefix to be added to the data document: