Skip to content

Commit

Permalink
🐛 compute checksum for properties of queries
Browse files Browse the repository at this point in the history
We had missed to process checksums for properties of queries with this call. Since semantically it is supposed to refresh the entire checksum of the Mquery object, it needs to cover properties as well.

Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus committed Sep 21, 2023
1 parent 55a1586 commit 5aea249
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/complex.mql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ packs:
# This MQL uses the property defined above. You can override it via
# e.g. --props "home='/home/user'"
mql: |
file( props.home ) { * }
file( props.home ) { basename user group }
# These are shared queries that can be used in any querypack
queries:
Expand Down
3 changes: 3 additions & 0 deletions explorer/mquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ func (m *Mquery) RefreshChecksum(

for i := range m.Props {
prop := m.Props[i]
if _, err := prop.RefreshChecksumAndType(schema); err != nil {
return err
}
if prop.Checksum == "" {
return errors.New("referenced property '" + prop.Mrn + "' checksum is empty")
}
Expand Down
20 changes: 20 additions & 0 deletions explorer/mquery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@
package explorer

import (
"context"
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mondoo.com/cnquery/providers-sdk/v1/testutils"
)

func TestMquery_RefreshChecksum(t *testing.T) {
a := &Mquery{
Mql: "mondoo.version != props.world",
Props: []*Property{{Mql: "'hi'", Uid: "world"}},
}
x := testutils.LinuxMock()
err := a.RefreshChecksum(
context.Background(),
x.Schema(),
func(ctx context.Context, mrn string) (*Mquery, error) {
return nil, nil
},
)
require.NoError(t, err)
assert.Equal(t, "t2slvX2k58s=", a.Checksum)
assert.Equal(t, "0xgs2tmERsM=", a.Props[0].Checksum)
}

func TestMqueryMerge(t *testing.T) {
a := &Mquery{
Mql: "base",
Expand Down

0 comments on commit 5aea249

Please sign in to comment.