Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmrod committed Nov 15, 2024
1 parent ae15d88 commit 9d215b9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions orbit/pkg/table/codesign/codesign_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func parseCodesignOutput(output []byte) parsedInfo {
var info parsedInfo
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, teamIdentifier) {
info.teamIdentifier = strings.TrimSpace(strings.TrimPrefix(line, teamIdentifier))
if strings.HasPrefix(line, teamIdentifierPrefix) {
info.teamIdentifier = strings.TrimSpace(strings.TrimPrefix(line, teamIdentifierPrefix))
// "not set" is usually displayed on Apple builtin apps.
if info.teamIdentifier == "not set" {
info.teamIdentifier = ""
Expand Down
2 changes: 1 addition & 1 deletion schema/osquery_fleet_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4188,7 +4188,7 @@
"name": "team_identifier",
"type": "text",
"required": false,
"description": "Unique 10-character string generated by Apple that's assigned to a developer account to sign packages. This value is empty on unsigned applications and builtin Apple applications."
"description": "Unique 10-character string generated by Apple that's assigned to a developer account to sign packages. This value is empty on unsigned applications and built-in Apple applications."
}
],
"notes": "This table is not a core osquery table. It is included as part of Fleet's agent ([fleetd](https://fleetdm.com/docs/get-started/anatomy#fleetd)).",
Expand Down
31 changes: 31 additions & 0 deletions server/datastore/mysql/software_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestSoftware(t *testing.T) {
{"HostSoftwareInstalledPathsDelta", testHostSoftwareInstalledPathsDelta},
{"DeleteHostSoftwareInstalledPaths", testDeleteHostSoftwareInstalledPaths},
{"InsertHostSoftwareInstalledPaths", testInsertHostSoftwareInstalledPaths},
{"VerifySoftwareChecksum", testVerifySoftwareChecksum},
{"ListHostSoftware", testListHostSoftware},
{"ListIOSHostSoftware", testListIOSHostSoftware},
{"SetHostSoftwareInstallResult", testSetHostSoftwareInstallResult},
Expand Down Expand Up @@ -3130,6 +3131,36 @@ func testUpdateHostSoftwareDeadlock(t *testing.T, ds *Datastore) {
require.NoError(t, err)
}

func testVerifySoftwareChecksum(t *testing.T, ds *Datastore) {
ctx := context.Background()
host := test.NewHost(t, ds, "host1", "", "host1key", "host1uuid", time.Now())

software := []fleet.Software{
{Name: "foo", Version: "0.0.1", Source: "test"},
{Name: "foo", Version: "0.0.1", Source: "test", Browser: "firefox"},
{Name: "foo", Version: "0.0.1", Source: "test", ExtensionID: "ext"},
{Name: "foo", Version: "0.0.2", Source: "test"},
}

_, err := ds.UpdateHostSoftware(ctx, host.ID, software)
require.NoError(t, err)

checksums := make([]string, len(software))
for i, sw := range software {
checksum, err := computeRawChecksum(sw)
require.NoError(t, err)
checksums[i] = hex.EncodeToString(checksum)
}
for i, cs := range checksums {
var got fleet.Software
ExecAdhocSQL(t, ds, func(q sqlx.ExtContext) error {
return sqlx.GetContext(ctx, q, &got,
`SELECT name, version, source, bundle_identifier, `+"`release`"+`, arch, vendor, browser, extension_id FROM software WHERE checksum = UNHEX(?)`, cs)
})
require.Equal(t, software[i], got)
}
}

func testListHostSoftware(t *testing.T, ds *Datastore) {
ctx := context.Background()
host := test.NewHost(t, ds, "host1", "", "host1key", "host1uuid", time.Now(), test.WithPlatform("darwin"))
Expand Down
2 changes: 1 addition & 1 deletion server/fleet/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ type Datastore interface {
// UpdateHostSoftwareInstalledPaths looks at all software for 'hostID' and based on the contents of
// 'reported', either inserts or deletes the corresponding entries in the
// 'host_software_installed_paths' table. 'reported' is a set of
// 'installed_path\0team_identifier\0software.ToUniqueStr()h' strings. 'mutationResults' contains the software inventory of
// 'installed_path\0team_identifier\0software.ToUniqueStr()' strings. 'mutationResults' contains the software inventory of
// the host (pre-mutations) and the mutations performed after calling 'UpdateHostSoftware',
// it is used as DB optimization.
//
Expand Down

0 comments on commit 9d215b9

Please sign in to comment.