Skip to content

Commit

Permalink
Refactored tests (Velocidex#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
scudette authored Aug 15, 2021
1 parent bb2b43c commit 09b9c86
Show file tree
Hide file tree
Showing 54 changed files with 2,078 additions and 1,283 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ debug_golden:

lint:
golangci-lint run

KapeFilesSync:
python3 scripts/kape_files.py ~/projects/KapeFiles/ > artifacts/definitions/Windows/KapeFiles/Targets.yaml
7 changes: 6 additions & 1 deletion api/notebooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,11 @@ func (self *ApiServer) updateNotebookCell(
ListenForNotification(in.CellId)
defer remove_notification()

default_notebook_expiry := self.config.Defaults.NotebookCellTimeoutMin
if default_notebook_expiry == 0 {
default_notebook_expiry = 10
}

select {
// Query is done - get out of here.
case <-query_ctx.Done():
Expand All @@ -752,7 +757,7 @@ func (self *ApiServer) updateNotebookCell(
tmpl.Scope.Log("Cancelled after %v !", time.Since(start_time))

// Set a timeout.
case <-time.After(10 * time.Minute):
case <-time.After(time.Duration(default_notebook_expiry) * time.Minute):
tmpl.Scope.Log("Query timed out after %v !", time.Since(start_time))
}

Expand Down
24 changes: 12 additions & 12 deletions api/proto/api.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions artifacts/definitions/Demo/Plugins/GUI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,20 @@ sources:
check it is being updated.
{{ Scope "Timeline" | Timeline }}
- type: VQL
template: |
/*
# Test table scrolling.
Check both expanded and contracted states of the cell
*/
LET Test = "Hellothereongline"
SELECT Test AS Test1, Test AS Test2, Test AS Test3,
Test AS Test4, Test AS Test5,
Test AS Test11, Test AS Test21,
Test AS Test13, Test AS Test14, Test AS Test15,
Test AS Test21, Test AS Test22,
Test AS Test23, Test AS Test24, Test AS Test25
FROM range(start=0, end=100, step=1)
11 changes: 9 additions & 2 deletions artifacts/definitions/Linux/Search/FileFinder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ precondition:

parameters:
- name: SearchFilesGlob
default: /home/*/**
default: /home/*
description: Use a glob to define the files that will be searched.

- name: SearchFilesGlobTable
type: csv
default: |
Glob
/home/someuser/*
description: Alternative specify multiple globs in a table

- name: Keywords
default:
description: A comma delimited list of strings to search for.
Expand Down Expand Up @@ -69,7 +76,7 @@ sources:
Mtime AS MTime,
Ctime AS CTime,
IsDir, Mode
FROM glob(globs=SearchFilesGlob,
FROM glob(globs=SearchFilesGlobTable.Glob + SearchFilesGlob,
accessor="file")

- LET more_recent = SELECT * FROM if(
Expand Down
707 changes: 358 additions & 349 deletions artifacts/definitions/Windows/KapeFiles/Targets.yaml

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions artifacts/definitions/Windows/Search/FileFinder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ precondition:

parameters:
- name: SearchFilesGlob
default: C:\Users\**
default: C:\Users\*
description: Use a glob to define the files that will be searched.

- name: SearchFilesGlobTable
type: csv
default: |
Glob
C:/Users/SomeUser/*
description: Alternative specify multiple globs in a table

- name: Accessor
default: auto
description: The accessor to use
Expand Down Expand Up @@ -72,7 +79,8 @@ sources:
Atime AS ATime,
Mtime AS MTime, "" AS Keywords,
Ctime AS CTime, IsDir
FROM glob(globs=SearchFilesGlob, accessor=Accessor)
FROM glob(globs=SearchFilesGlobTable.Glob + SearchFilesGlob,
accessor=Accessor)
LET more_recent = SELECT * FROM if(
condition=MoreRecentThan,
Expand Down
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ func GetDefaultConfig() *config_proto.Config {
BindPort: 8003,
},
ApiConfig: &config_proto.ApiClientConfig{},
Defaults: &config_proto.Defaults{
HuntExpiryHours: 24 * 7,
NotebookCellTimeoutMin: 10,
},
}

// The client's version needs to keep in sync with the
Expand Down
19 changes: 19 additions & 0 deletions config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,25 @@ func (self *Loader) WithEnvLoader(env_var string) *Loader {
return self
}

func (self *Loader) WithEnvLiteralLoader(env_var string) *Loader {
self = self.Copy()
self.loaders = append(self.loaders, func(self *Loader) (*config_proto.Config, error) {
env_config := os.Getenv(env_var)
if env_config != "" {
self.Log("Loading literal config from env %v", env_var)
result := &config_proto.Config{}
err := yaml.UnmarshalStrict([]byte(env_config), result)
if err != nil {
return nil, errors.WithStack(err)
}
return result, nil
}
return nil, errors.New(fmt.Sprintf("Env var %v is not set", env_var))
})

return self
}

func (self *Loader) WithEmbedded() *Loader {
self = self.Copy()
self.loaders = append(self.loaders, func(self *Loader) (*config_proto.Config, error) {
Expand Down
7 changes: 7 additions & 0 deletions config/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ func migrate_0_6_1(config_obj *config_proto.Config) {
config_obj.Datastore.FilestoreDirectory = strings.TrimSuffix(
config_obj.Datastore.FilestoreDirectory, "/")
}

if config_obj.Defaults == nil {
config_obj.Defaults = &config_proto.Defaults{
HuntExpiryHours: 24 * 7,
NotebookCellTimeoutMin: 10,
}
}
}

func migrate(config_obj *config_proto.Config) {
Expand Down
Loading

0 comments on commit 09b9c86

Please sign in to comment.