Skip to content

Commit 31d6f5f

Browse files
authored
[test] Update failing tests in ruleset (#278)
test: clean-up bundle_test.go for failing tests Signed-off-by: Ben Stickel <[email protected]>
1 parent 186f399 commit 31d6f5f

File tree

2 files changed

+101
-104
lines changed

2 files changed

+101
-104
lines changed

pkg/bundle/ruleset/bundle_test.go

+101-103
Original file line numberDiff line numberDiff line change
@@ -21,69 +21,61 @@ import (
2121
"testing"
2222

2323
bundlev1 "github.com/elastic/harp/api/gen/go/harp/bundle/v1"
24-
"github.com/golang/protobuf/proto"
24+
25+
"github.com/stretchr/testify/assert"
2526
)
2627

2728
func TestFromBundle(t *testing.T) {
28-
type args struct {
29-
b *bundlev1.Bundle
30-
}
3129
tests := []struct {
3230
name string
33-
args args
31+
bundle *bundlev1.Bundle
3432
want *bundlev1.RuleSet
3533
wantErr bool
3634
}{
3735
{
38-
name: "nil",
39-
args: args{
40-
b: nil,
41-
},
36+
name: "nil",
37+
bundle: &bundlev1.Bundle{},
4238
want: nil,
4339
wantErr: true,
4440
},
4541
{
46-
name: "packages are nil",
47-
args: args{
48-
b: &bundlev1.Bundle{
49-
Labels: map[string]string{
50-
"test": "true",
51-
},
52-
Annotations: map[string]string{
53-
"harp.elastic.co/v1/testing#bundlePurpose": "test",
54-
},
55-
Packages: nil,
42+
name: "empty packages",
43+
bundle: &bundlev1.Bundle{
44+
Labels: map[string]string{
45+
"test": "true",
5646
},
47+
Annotations: map[string]string{
48+
"harp.elastic.co/v1/testing#bundlePurpose": "test",
49+
},
50+
Packages: nil,
5751
},
5852
want: nil,
5953
wantErr: true,
6054
},
6155
{
6256
name: "secrets are nil",
63-
args: args{
64-
b: &bundlev1.Bundle{
65-
Labels: map[string]string{
66-
"test": "true",
67-
},
68-
Annotations: map[string]string{
69-
"harp.elastic.co/v1/testing#bundlePurpose": "test",
70-
},
71-
Packages: []*bundlev1.Package{
72-
{
73-
Labels: map[string]string{
74-
"external": "true",
75-
},
76-
Annotations: map[string]string{
77-
"infosec.elastic.co/v1/SecretPolicy#rotationMethod": "ci",
78-
"infosec.elastic.co/v1/SecretPolicy#rotationPeriod": "90d",
79-
"infosec.elastic.co/v1/SecretPolicy#serviceType": "authentication",
80-
"infosec.elastic.co/v1/SecretPolicy#severity": "high",
81-
"infra.elastic.co/v1/CI#jobName": "rotate-external-api-key",
82-
"harp.elastic.co/v1/package#encryptionKeyAlias": "test",
83-
},
84-
Name: "app/production/testAccount/testService/v1.0.0/internalTestComponent/authentication/api_key",
85-
Secrets: nil,
57+
bundle: &bundlev1.Bundle{
58+
Labels: map[string]string{
59+
"test": "true",
60+
},
61+
Annotations: map[string]string{
62+
"harp.elastic.co/v1/testing#bundlePurpose": "test",
63+
},
64+
Packages: []*bundlev1.Package{
65+
{
66+
Labels: map[string]string{
67+
"external": "true",
8668
},
69+
Annotations: map[string]string{
70+
"infosec.elastic.co/v1/SecretPolicy#rotationMethod": "ci",
71+
"infosec.elastic.co/v1/SecretPolicy#rotationPeriod": "90d",
72+
"infosec.elastic.co/v1/SecretPolicy#serviceType": "authentication",
73+
"infosec.elastic.co/v1/SecretPolicy#severity": "high",
74+
"infra.elastic.co/v1/CI#jobName": "rotate-external-api-key",
75+
"harp.elastic.co/v1/package#encryptionKeyAlias": "test",
76+
},
77+
Name: "app/production/testAccount/testService/v1.0.0/internalTestComponent/authentication/api_key",
78+
Secrets: nil,
8779
},
8880
},
8981
},
@@ -101,31 +93,29 @@ func TestFromBundle(t *testing.T) {
10193
},
10294
{
10395
name: "secret data is nil",
104-
args: args{
105-
b: &bundlev1.Bundle{
106-
Labels: map[string]string{
107-
"test": "true",
108-
},
109-
Annotations: map[string]string{
110-
"harp.elastic.co/v1/testing#bundlePurpose": "test",
111-
},
112-
Packages: []*bundlev1.Package{
113-
{
114-
Labels: map[string]string{
115-
"external": "true",
116-
},
117-
Annotations: map[string]string{
118-
"infosec.elastic.co/v1/SecretPolicy#rotationMethod": "ci",
119-
"infosec.elastic.co/v1/SecretPolicy#rotationPeriod": "90d",
120-
"infosec.elastic.co/v1/SecretPolicy#serviceType": "authentication",
121-
"infosec.elastic.co/v1/SecretPolicy#severity": "high",
122-
"infra.elastic.co/v1/CI#jobName": "rotate-external-api-key",
123-
"harp.elastic.co/v1/package#encryptionKeyAlias": "test",
124-
},
125-
Name: "app/production/testAccount/testService/v1.0.0/internalTestComponent/authentication/api_key",
126-
Secrets: &bundlev1.SecretChain{
127-
Data: nil,
128-
},
96+
bundle: &bundlev1.Bundle{
97+
Labels: map[string]string{
98+
"test": "true",
99+
},
100+
Annotations: map[string]string{
101+
"harp.elastic.co/v1/testing#bundlePurpose": "test",
102+
},
103+
Packages: []*bundlev1.Package{
104+
{
105+
Labels: map[string]string{
106+
"external": "true",
107+
},
108+
Annotations: map[string]string{
109+
"infosec.elastic.co/v1/SecretPolicy#rotationMethod": "ci",
110+
"infosec.elastic.co/v1/SecretPolicy#rotationPeriod": "90d",
111+
"infosec.elastic.co/v1/SecretPolicy#serviceType": "authentication",
112+
"infosec.elastic.co/v1/SecretPolicy#severity": "high",
113+
"infra.elastic.co/v1/CI#jobName": "rotate-external-api-key",
114+
"harp.elastic.co/v1/package#encryptionKeyAlias": "test",
115+
},
116+
Name: "app/production/testAccount/testService/v1.0.0/internalTestComponent/authentication/api_key",
117+
Secrets: &bundlev1.SecretChain{
118+
Data: nil,
129119
},
130120
},
131121
},
@@ -144,38 +134,36 @@ func TestFromBundle(t *testing.T) {
144134
},
145135
{
146136
name: "package and secrets define with annotations and labels",
147-
args: args{
148-
b: &bundlev1.Bundle{
149-
Labels: map[string]string{
150-
"test": "true",
151-
},
152-
Annotations: map[string]string{
153-
"harp.elastic.co/v1/testing#bundlePurpose": "test",
154-
},
155-
Packages: []*bundlev1.Package{
156-
{
137+
bundle: &bundlev1.Bundle{
138+
Labels: map[string]string{
139+
"test": "true",
140+
},
141+
Annotations: map[string]string{
142+
"harp.elastic.co/v1/testing#bundlePurpose": "test",
143+
},
144+
Packages: []*bundlev1.Package{
145+
{
146+
Labels: map[string]string{
147+
"external": "true",
148+
},
149+
Annotations: map[string]string{
150+
"harp.elastic.co/v1/package#encryptionKeyAlias": "test",
151+
"infra.elastic.co/v1/CI#jobName": "rotate-external-api-key",
152+
"infosec.elastic.co/v1/SecretPolicy#rotationMethod": "ci",
153+
"infosec.elastic.co/v1/SecretPolicy#rotationPeriod": "90d",
154+
"infosec.elastic.co/v1/SecretPolicy#serviceType": "authentication",
155+
"infosec.elastic.co/v1/SecretPolicy#severity": "high",
156+
},
157+
Name: "app/production/testAccount/testService/v1.0.0/internalTestComponent/authentication/api_key",
158+
Secrets: &bundlev1.SecretChain{
157159
Labels: map[string]string{
158-
"external": "true",
159-
},
160-
Annotations: map[string]string{
161-
"harp.elastic.co/v1/package#encryptionKeyAlias": "test",
162-
"infra.elastic.co/v1/CI#jobName": "rotate-external-api-key",
163-
"infosec.elastic.co/v1/SecretPolicy#rotationMethod": "ci",
164-
"infosec.elastic.co/v1/SecretPolicy#rotationPeriod": "90d",
165-
"infosec.elastic.co/v1/SecretPolicy#serviceType": "authentication",
166-
"infosec.elastic.co/v1/SecretPolicy#severity": "high",
160+
"vendor": "true",
167161
},
168-
Name: "app/production/testAccount/testService/v1.0.0/internalTestComponent/authentication/api_key",
169-
Secrets: &bundlev1.SecretChain{
170-
Labels: map[string]string{
171-
"vendor": "true",
172-
},
173-
Data: []*bundlev1.KV{
174-
{
175-
Key: "API_KEY",
176-
Type: "string",
177-
Value: []byte("3YGVuHwUqYVkjk-c6lQgfVQwFHawPG36TgAm72sPZGE="),
178-
},
162+
Data: []*bundlev1.KV{
163+
{
164+
Key: "API_KEY",
165+
Type: "string",
166+
Value: []byte("3YGVuHwUqYVkjk-c6lQgfVQwFHawPG36TgAm72sPZGE="),
179167
},
180168
},
181169
},
@@ -213,13 +201,23 @@ func TestFromBundle(t *testing.T) {
213201
}
214202
for _, tt := range tests {
215203
t.Run(tt.name, func(t *testing.T) {
216-
got, err := FromBundle(tt.args.b)
217-
if (err != nil) != tt.wantErr {
218-
t.Errorf("error = %v, wantErr %v", err, tt.wantErr)
219-
}
204+
got, err := FromBundle(tt.bundle)
205+
if tt.wantErr {
206+
assert.Error(t, err)
207+
} else {
208+
assert.NoError(t, err)
209+
assert.Equal(t, tt.want.ApiVersion, got.ApiVersion)
210+
assert.Equal(t, tt.want.Kind, got.Kind)
211+
assert.Equal(t, tt.want.Meta, got.Meta)
212+
assert.Equal(t, len(tt.want.Spec.Rules), len(got.Spec.Rules))
220213

221-
if !proto.Equal(got, tt.want) {
222-
t.Errorf("Ruleset not equal = %v, want %v", got, tt.want)
214+
for idx, expectedRule := range tt.want.Spec.Rules {
215+
gotRule := got.Spec.Rules[idx]
216+
assert.Equal(t, expectedRule.Name, gotRule.Name)
217+
assert.Equal(t, expectedRule.Path, gotRule.Path)
218+
assert.Equal(t, len(expectedRule.Constraints), len(gotRule.Constraints))
219+
assert.ElementsMatch(t, expectedRule.GetConstraints(), gotRule.GetConstraints())
220+
}
223221
}
224222
})
225223
}

pkg/sdk/value/encryption/transformer_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727

2828
"github.com/elastic/harp/pkg/sdk/value"
2929
"github.com/elastic/harp/pkg/sdk/value/encryption"
30-
3130
// Register encryption transformers
3231
_ "github.com/elastic/harp/pkg/sdk/value/encryption/aead"
3332
_ "github.com/elastic/harp/pkg/sdk/value/encryption/age"

0 commit comments

Comments
 (0)