-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-linux-support-to-google_chrome_profiles
- Loading branch information
Showing
19 changed files
with
696 additions
and
45 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,53 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/osquery/osquery-go" | ||
) | ||
|
||
type OsqueryClienter interface { | ||
NewOsqueryClient() (OsqueryClient, error) | ||
} | ||
|
||
type OsqueryClient interface { | ||
QueryRows(query string) ([]map[string]string, error) | ||
QueryRow(query string) (map[string]string, error) | ||
Close() | ||
} | ||
|
||
type SocketOsqueryClienter struct { | ||
SocketPath string | ||
Timeout time.Duration | ||
} | ||
|
||
func (s *SocketOsqueryClienter) NewOsqueryClient() (OsqueryClient, error) { | ||
osqueryClient, err := osquery.NewClient(s.SocketPath, s.Timeout) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not create osquery client: %w", err) | ||
} | ||
return osqueryClient, nil | ||
} | ||
|
||
type MockOsqueryClienter struct { | ||
Data map[string][]map[string]string | ||
} | ||
|
||
func (m *MockOsqueryClienter) NewOsqueryClient() (OsqueryClient, error) { | ||
return &MockOsqueryClient{Data: m.Data}, nil | ||
} | ||
|
||
type MockOsqueryClient struct { | ||
Data map[string][]map[string]string | ||
} | ||
|
||
func (m *MockOsqueryClient) QueryRows(query string) ([]map[string]string, error) { | ||
return m.Data[query], nil | ||
} | ||
|
||
func (m *MockOsqueryClient) QueryRow(query string) (map[string]string, error) { | ||
return m.Data[query][0], nil | ||
} | ||
|
||
func (m *MockOsqueryClient) Close() {} |
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,40 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestQueryRows(t *testing.T) { | ||
query := "SELECT * FROM table" | ||
clienter := &MockOsqueryClienter{ | ||
Data: map[string][]map[string]string{ | ||
query: {{"column1": "value1", "column2": "value2"}}, | ||
}, | ||
} | ||
|
||
mock, err := clienter.NewOsqueryClient() | ||
require.NoError(t, err) | ||
|
||
data, err := mock.QueryRows(query) | ||
require.NoError(t, err) | ||
assert.Equal(t, clienter.Data[query], data) | ||
} | ||
|
||
func TestQueryRow(t *testing.T) { | ||
query := "SELECT * FROM table" | ||
clienter := &MockOsqueryClienter{ | ||
Data: map[string][]map[string]string{ | ||
query: {{"column1": "value1", "column2": "value2"}}, | ||
}, | ||
} | ||
|
||
mock, err := clienter.NewOsqueryClient() | ||
require.NoError(t, err) | ||
|
||
data, err := mock.QueryRow("SELECT * FROM table") | ||
require.NoError(t, err) | ||
assert.Equal(t, clienter.Data[query][0], data) | ||
} |
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,25 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "alt_system_info", | ||
srcs = ["alt_system_info.go"], | ||
importpath = "github.com/macadmins/osquery-extension/tables/alt_system_info", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/utils", | ||
"@com_github_groob_plist//:plist", | ||
"@com_github_osquery_osquery_go//plugin/table", | ||
"@org_golang_x_sync//errgroup:go_default_library", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "alt_system_info_test", | ||
srcs = ["alt_system_info_test.go"], | ||
deps = [ | ||
":alt_system_info", | ||
"//pkg/utils", | ||
"@com_github_stretchr_testify//assert", | ||
"@com_github_stretchr_testify//require", | ||
], | ||
) |
Oops, something went wrong.