-
Notifications
You must be signed in to change notification settings - Fork 112
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
(spyglass/lenses) allow configuration sandbox permissions #296
Changes from 1 commit
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 |
---|---|---|
|
@@ -50,10 +50,11 @@ const ( | |
var defaultHighlightLineLengthMax = 10000 // Default maximum length of a line worth highlighting | ||
|
||
type config struct { | ||
HighlightRegexes []string `json:"highlight_regexes"` | ||
HideRawLog bool `json:"hide_raw_log,omitempty"` | ||
Highlighter *highlightConfig `json:"highlighter,omitempty"` | ||
HighlightLengthMax *int `json:"highlight_line_length_max,omitempty"` | ||
HighlightRegexes []string `json:"highlight_regexes"` | ||
HideRawLog bool `json:"hide_raw_log,omitempty"` | ||
Highlighter *highlightConfig `json:"highlighter,omitempty"` | ||
HighlightLengthMax *int `json:"highlight_line_length_max,omitempty"` | ||
IframeSandboxPermissions []string `json:"iframe_sandbox_permissions,omitempty"` | ||
} | ||
|
||
type highlightConfig struct { | ||
|
@@ -68,10 +69,11 @@ type highlightConfig struct { | |
} | ||
|
||
type parsedConfig struct { | ||
highlightRegex *regexp.Regexp | ||
showRawLog bool | ||
highlighter *highlightConfig | ||
highlightLengthMax int | ||
highlightRegex *regexp.Regexp | ||
showRawLog bool | ||
highlighter *highlightConfig | ||
highlightLengthMax int | ||
IframeSandboxPermissions string | ||
} | ||
|
||
var _ api.Lens = Lens{} | ||
|
@@ -97,6 +99,17 @@ func (lens Lens) Header(artifacts []api.Artifact, resourceDir string, config jso | |
// It is only used if highlight_regexes is not specified in the lens config. | ||
var defaultErrRE = regexp.MustCompile(`timed out|ERROR:|(FAIL|Failure \[)\b|panic\b|^E\d{4} \d\d:\d\d:\d\d\.\d\d\d]`) | ||
|
||
// defaultSandboxPermissions is the default value for iframe_sandbox_permissions lense config if it is not specified. | ||
var defaultSandboxPermissions = strings.Join( | ||
[]string{ | ||
"allow-scripts", | ||
"allow-top-navigation", | ||
"allow-popups", | ||
"allow-same-origin", | ||
}, | ||
" ", | ||
) | ||
Comment on lines
+103
to
+111
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 is defaultSandboxPermissions for the parsedConfig, tho I personally like to work with arrays instead of strings with Not sure if you prefer this or the Please let me know, I'll update if you want to change it. 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. Suggestion is to do another PR after this to adjust the defaults to not combine 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. Arrays sound reasonable to me, and I think it's easier to catch differences. And that sounds good to me. |
||
|
||
func init() { | ||
lenses.RegisterLens(Lens{}) | ||
} | ||
|
@@ -170,8 +183,9 @@ type buildLogsView struct { | |
|
||
func getConfig(rawConfig json.RawMessage) parsedConfig { | ||
conf := parsedConfig{ | ||
highlightRegex: defaultErrRE, | ||
showRawLog: true, | ||
highlightRegex: defaultErrRE, | ||
showRawLog: true, | ||
IframeSandboxPermissions: defaultSandboxPermissions, | ||
} | ||
|
||
// No config at all is fine. | ||
|
@@ -189,6 +203,13 @@ func getConfig(rawConfig json.RawMessage) parsedConfig { | |
conf.highlighter = nil | ||
} | ||
conf.showRawLog = !c.HideRawLog | ||
|
||
if c.IframeSandboxPermissions == nil { | ||
conf.IframeSandboxPermissions = defaultSandboxPermissions | ||
} else { | ||
conf.IframeSandboxPermissions = strings.Join(c.IframeSandboxPermissions, " ") | ||
} | ||
|
||
if len(c.HighlightRegexes) == 0 { | ||
return conf | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,8 @@ import ( | |
|
||
func TestGetConfig(t *testing.T) { | ||
def := parsedConfig{ | ||
showRawLog: true, | ||
showRawLog: true, | ||
IframeSandboxPermissions: defaultSandboxPermissions, | ||
} | ||
cases := []struct { | ||
name string | ||
|
@@ -61,6 +62,14 @@ func TestGetConfig(t *testing.T) { | |
} | ||
return d | ||
}(), | ||
}, { | ||
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. nit: Add test case verifying what the iframe permissions are if none are specified. 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. Added test @michelle192837 , good nit 👍 |
||
name: "configure iframe sandbox permissions", | ||
raw: `{"iframe_sandbox_permissions": ["allow-scripts", "allow-downloads"]}`, | ||
want: func() parsedConfig { | ||
d := def | ||
d.IframeSandboxPermissions = "allow-scripts allow-downloads" | ||
return d | ||
}(), | ||
}, | ||
} | ||
|
||
|
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.
Updated this as it looked like a sane idea to do if this is supposed to demostrate a full configuration file example.