-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathresolver_test.go
83 lines (66 loc) · 1.79 KB
/
resolver_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1
package policy_test
import (
"context"
"strings"
"testing"
"github.com/stretchr/testify/require"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/testutils"
"go.mondoo.com/cnspec/v11/internal/datalakes/inmemory"
"go.mondoo.com/cnspec/v11/policy"
)
type testAsset struct {
asset string
policies []string
frameworks []string
}
func parseBundle(t *testing.T, data string) *policy.Bundle {
res, err := policy.BundleFromYAML([]byte(data))
require.NoError(t, err)
return res
}
func initResolver(t *testing.T, assets []*testAsset, bundles []*policy.Bundle) *policy.LocalServices {
runtime := testutils.LinuxMock()
_, srv, err := inmemory.NewServices(runtime, nil)
require.NoError(t, err)
for i := range bundles {
bundle := bundles[i]
_, err := srv.SetBundle(context.Background(), bundle)
require.NoError(t, err)
}
for i := range assets {
asset := assets[i]
_, err := srv.Assign(context.Background(), &policy.PolicyAssignment{
AssetMrn: asset.asset,
PolicyMrns: asset.policies,
FrameworkMrns: asset.frameworks,
})
require.NoError(t, err)
}
return srv
}
func policyMrn(uid string) string {
return "//test.sth/policies/" + uid
}
func frameworkMrn(uid string) string {
return "//test.sth/frameworks/" + uid
}
func controlMrn(uid string) string {
return "//test.sth/controls/" + uid
}
func queryMrn(uid string) string {
return "//test.sth/queries/" + uid
}
func riskFactorMrn(uid string) string {
return "//test.sth/risks/" + uid
}
func isFramework(queryId string) bool {
return strings.Contains(queryId, "/frameworks/")
}
func isControl(queryId string) bool {
return strings.Contains(queryId, "/controls/")
}
func isPolicy(queryId string) bool {
return strings.Contains(queryId, "/policies/")
}