Skip to content

Commit 07b249e

Browse files
committed
Add tests
1 parent cf83bd2 commit 07b249e

17 files changed

Lines changed: 556 additions & 4 deletions

File tree

code/go/internal/validator/semantic/validate_minimum_kibana_version.go

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,24 @@ func ValidateMinimumKibanaVersion(fsys fspath.FS) ve.ValidationErrors {
3333
return ve.ValidationErrors{err}
3434
}
3535

36+
var errs ve.ValidationErrors
3637
err = validateMinimumKibanaVersionInputPackages(pkg.Type, *pkg.Version, kibanaVersionCondition)
3738
if err != nil {
38-
return ve.ValidationErrors{err}
39+
errs.Append(ve.ValidationErrors{err})
3940
}
4041

4142
err = validateMinimumKibanaVersionRuntimeFields(fsys, *pkg.Version, kibanaVersionCondition)
4243
if err != nil {
43-
return ve.ValidationErrors{err}
44+
errs.Append(ve.ValidationErrors{err})
45+
}
46+
47+
err = validateMinimumKibanaVersionSavedObjectTags(fsys, *pkg.Version, kibanaVersionCondition)
48+
if err != nil {
49+
errs.Append(ve.ValidationErrors{err})
50+
}
51+
52+
if errs != nil {
53+
return errs
4454
}
4555

4656
return nil
@@ -65,7 +75,7 @@ func validateMinimumKibanaVersionInputPackages(packageType string, packageVersio
6575
return fmt.Errorf("conditions.kibana.version must be ^%s or greater for non experimental input packages (version > 1.0.0)", minimumKibanaVersion)
6676
}
6777

68-
// validateMinimumKibanaVersionInputPackages ensures the minimum kibana version if the package defines any runtime field,
78+
// validateMinimumKibanaVersionRuntimeFields ensures the minimum kibana version if the package defines any runtime field,
6979
// then the kibana version condition for the package must be >= 8.10.0
7080
func validateMinimumKibanaVersionRuntimeFields(fsys fspath.FS, packageVersion semver.Version, kibanaVersionCondition string) error {
7181
const minimumKibanaVersion = "8.10.0"
@@ -81,6 +91,28 @@ func validateMinimumKibanaVersionRuntimeFields(fsys fspath.FS, packageVersion se
8191
return fmt.Errorf("conditions.kibana.version must be ^%s or greater to include runtime fields", minimumKibanaVersion)
8292
}
8393

94+
// validateMinimumKibanaVersionSavedObjectTags ensures the minimum kibana version if the package defines saved object tags file,
95+
// then the kibana version condition for the package must be >= 8.10.0
96+
func validateMinimumKibanaVersionSavedObjectTags(fsys fspath.FS, packageVersion semver.Version, kibanaVersionCondition string) error {
97+
const minimumKibanaVersion = "8.10.0"
98+
99+
manifestPath := "kibana/tags.yml"
100+
f, err := pkgpath.Files(fsys, manifestPath)
101+
if err != nil {
102+
return fmt.Errorf("can't locate files with %v: %w", manifestPath, err)
103+
}
104+
105+
if len(f) == 0 {
106+
return nil
107+
}
108+
109+
if kibanaVersionConditionIsGreaterThanOrEqualTo(kibanaVersionCondition, minimumKibanaVersion) {
110+
return nil
111+
}
112+
113+
return fmt.Errorf("conditions.kibana.version must be ^%s or greater to include saved object tags file: %s", minimumKibanaVersion, manifestPath)
114+
}
115+
84116
func readManifest(fsys fspath.FS) (*pkgpath.File, error) {
85117
manifestPath := "manifest.yml"
86118
f, err := pkgpath.Files(fsys, manifestPath)
@@ -95,6 +127,20 @@ func readManifest(fsys fspath.FS) (*pkgpath.File, error) {
95127
return &f[0], nil
96128
}
97129

130+
func readSavedObjectTags(fsys fspath.FS) (*pkgpath.File, error) {
131+
manifestPath := "kibana/tags.yml"
132+
f, err := pkgpath.Files(fsys, manifestPath)
133+
if err != nil {
134+
return nil, fmt.Errorf("can't locate kibana/tags file: %w", err)
135+
}
136+
137+
if len(f) != 1 {
138+
return nil, fmt.Errorf("single kibana/tags file expected")
139+
}
140+
141+
return &f[0], nil
142+
}
143+
98144
func getKibanaVersionCondition(manifest pkgpath.File) (string, error) {
99145

100146
val, err := manifest.Values("$.conditions[\"kibana.version\"]")

code/go/pkg/validator/validator_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ func TestValidateFile(t *testing.T) {
184184
"field (root): Additional property max_age is not allowed",
185185
},
186186
},
187+
"bad_saved_object_tags": {
188+
"kibana/tags.yml",
189+
[]string{
190+
`field 0.asset_types.12: 0.asset_types.12 must be one of the following: "dashboard", "visualization", "search", "map", "lens", "index_pattern", "security_rule", "csp_rule_template", "ml_module", "tag", "osquery_pack_asset", "osquery_saved_query"`,
191+
`field 1.asset_ids.1: Invalid type. Expected: string, given: integer`,
192+
`field 2: Must not be present`,
193+
},
194+
},
187195
}
188196

189197
for pkgName, test := range tests {
@@ -439,6 +447,9 @@ func TestValidateMinimumKibanaVersions(t *testing.T) {
439447
"bad_runtime_kibana_version": []string{
440448
"conditions.kibana.version must be ^8.10.0 or greater to include runtime fields",
441449
},
450+
"bad_saved_object_tags_kibana_version": []string{
451+
"conditions.kibana.version must be ^8.10.0 or greater to include saved object tags file: kibana/tags.yml",
452+
},
442453
}
443454

444455
for pkgName, expectedErrorMessages := range tests {
@@ -463,7 +474,7 @@ func TestValidateMinimumKibanaVersions(t *testing.T) {
463474
}
464475
}
465476
if !found {
466-
t.Errorf("expected error: %q", expectedError)
477+
t.Errorf("expected error: %q, found: %q", expectedError, errs)
467478
}
468479
}
469480
})
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Elastic License 2.0
2+
3+
URL: https://www.elastic.co/licensing/elastic-license
4+
5+
## Acceptance
6+
7+
By using the software, you agree to all of the terms and conditions below.
8+
9+
## Copyright License
10+
11+
The licensor grants you a non-exclusive, royalty-free, worldwide,
12+
non-sublicensable, non-transferable license to use, copy, distribute, make
13+
available, and prepare derivative works of the software, in each case subject to
14+
the limitations and conditions below.
15+
16+
## Limitations
17+
18+
You may not provide the software to third parties as a hosted or managed
19+
service, where the service provides users with access to any substantial set of
20+
the features or functionality of the software.
21+
22+
You may not move, change, disable, or circumvent the license key functionality
23+
in the software, and you may not remove or obscure any functionality in the
24+
software that is protected by the license key.
25+
26+
You may not alter, remove, or obscure any licensing, copyright, or other notices
27+
of the licensor in the software. Any use of the licensor’s trademarks is subject
28+
to applicable law.
29+
30+
## Patents
31+
32+
The licensor grants you a license, under any patent claims the licensor can
33+
license, or becomes able to license, to make, have made, use, sell, offer for
34+
sale, import and have imported the software, in each case subject to the
35+
limitations and conditions in this license. This license does not cover any
36+
patent claims that you cause to be infringed by modifications or additions to
37+
the software. If you or your company make any written claim that the software
38+
infringes or contributes to infringement of any patent, your patent license for
39+
the software granted under these terms ends immediately. If your company makes
40+
such a claim, your patent license ends immediately for work on behalf of your
41+
company.
42+
43+
## Notices
44+
45+
You must ensure that anyone who gets a copy of any part of the software from you
46+
also gets a copy of these terms.
47+
48+
If you modify the software, you must include in any modified copies of the
49+
software prominent notices stating that you have modified the software.
50+
51+
## No Other Rights
52+
53+
These terms do not imply any licenses other than those expressly granted in
54+
these terms.
55+
56+
## Termination
57+
58+
If you use the software in violation of these terms, such use is not licensed,
59+
and your licenses will automatically terminate. If the licensor provides you
60+
with a notice of your violation, and you cease all violation of this license no
61+
later than 30 days after you receive that notice, your licenses will be
62+
reinstated retroactively. However, if you violate these terms after such
63+
reinstatement, any additional violation of these terms will cause your licenses
64+
to terminate automatically and permanently.
65+
66+
## No Liability
67+
68+
*As far as the law allows, the software comes as is, without any warranty or
69+
condition, and the licensor will not be liable to you for any damages arising
70+
out of these terms or the use or nature of the software, under any kind of
71+
legal claim.*
72+
73+
## Definitions
74+
75+
The **licensor** is the entity offering these terms, and the **software** is the
76+
software the licensor makes available under these terms, including any portion
77+
of it.
78+
79+
**you** refers to the individual or entity agreeing to these terms.
80+
81+
**your company** is any legal entity, sole proprietorship, or other kind of
82+
organization that you work for, plus all organizations that have control over,
83+
are under the control of, or are under common control with that
84+
organization. **control** means ownership of substantially all the assets of an
85+
entity, or the power to direct its management and policies by vote, contract, or
86+
otherwise. Control can be direct or indirect.
87+
88+
**your licenses** are all the licenses granted to you for the software under
89+
these terms.
90+
91+
**use** means anything you do with the software requiring one of your licenses.
92+
93+
**trademark** means trademarks, service marks, and similar rights.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# newer versions go on top
2+
- version: "0.0.1"
3+
changes:
4+
- description: Initial draft of the package
5+
type: enhancement
6+
link: https://github.com/elastic/integrations/pull/1 # FIXME Replace with the real PR link
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<!-- Use this template language as a starting point, replacing {placeholder text} with details about the integration. -->
2+
<!-- Find more detailed documentation guidelines in https://github.com/elastic/integrations/blob/main/docs/documentation_guidelines.md -->
3+
4+
# Bad Saved Object Tags
5+
6+
<!-- The Bad Saved Object Tags integration allows you to monitor {name of service}. {name of service} is {describe service}.
7+
8+
Use the Bad Saved Object Tags integration to {purpose}. Then visualize that data in Kibana, create alerts to notify you if something goes wrong, and reference {data stream type} when troubleshooting an issue.
9+
10+
For example, if you wanted to {sample use case} you could {action}. Then you can {visualize|alert|troubleshoot} by {action}. -->
11+
12+
## Data streams
13+
14+
<!-- The Bad Saved Object Tags integration collects {one|two} type{s} of data streams: {logs and/or metrics}. -->
15+
16+
<!-- If applicable -->
17+
<!-- **Logs** help you keep a record of events happening in {service}.
18+
Log data streams collected by the {name} integration include {sample data stream(s)} and more. See more details in the [Logs](#logs-reference). -->
19+
20+
<!-- If applicable -->
21+
<!-- **Metrics** give you insight into the state of {service}.
22+
Metric data streams collected by the {name} integration include {sample data stream(s)} and more. See more details in the [Metrics](#metrics-reference). -->
23+
24+
<!-- Optional: Any additional notes on data streams -->
25+
26+
## Requirements
27+
28+
You need Elasticsearch for storing and searching your data and Kibana for visualizing and managing it.
29+
You can use our hosted Elasticsearch Service on Elastic Cloud, which is recommended, or self-manage the Elastic Stack on your own hardware.
30+
31+
<!--
32+
Optional: Other requirements including:
33+
* System compatibility
34+
* Supported versions of third-party products
35+
* Permissions needed
36+
* Anything else that could block a user from successfully using the integration
37+
-->
38+
39+
## Setup
40+
41+
<!-- Any prerequisite instructions -->
42+
43+
For step-by-step instructions on how to set up an integration, see the
44+
[Getting started](https://www.elastic.co/guide/en/welcome-to-elastic/current/getting-started-observability.html) guide.
45+
46+
<!-- Additional set up instructions -->
47+
48+
<!-- If applicable -->
49+
<!-- ## Logs reference -->
50+
51+
<!-- Repeat for each data stream of the current type -->
52+
<!-- ### {Data stream name}
53+
54+
The `{data stream name}` data stream provides events from {source} of the following types: {list types}. -->
55+
56+
<!-- Optional -->
57+
<!-- #### Example
58+
59+
An example event for `{data stream name}` looks as following:
60+
61+
{code block with example} -->
62+
63+
<!-- #### Exported fields
64+
65+
{insert table} -->
66+
67+
<!-- If applicable -->
68+
<!-- ## Metrics reference -->
69+
70+
<!-- Repeat for each data stream of the current type -->
71+
<!-- ### {Data stream name}
72+
73+
The `{data stream name}` data stream provides events from {source} of the following types: {list types}. -->
74+
75+
<!-- Optional -->
76+
<!-- #### Example
77+
78+
An example event for `{data stream name}` looks as following:
79+
80+
{code block with example} -->
81+
82+
<!-- #### Exported fields
83+
84+
{insert table} -->
Lines changed: 1 addition & 0 deletions
Loading
18.4 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
- text: Something
2+
asset_types:
3+
- dashboard
4+
- visualization
5+
- search
6+
- map
7+
- lens
8+
- index_pattern
9+
- security_rule
10+
- csp_rule_template
11+
- ml_module
12+
- tag
13+
- osquery_pack_asset
14+
- osquery_saved_query
15+
- foo
16+
- text: Other
17+
asset_ids:
18+
- id1
19+
- 43
20+
- text: Something
21+
asset_types:
22+
- dashboard
23+
- tag
24+
asset_ids:
25+
- id1
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
format_version: 2.10.0
2+
name: bad_saved_object_tags
3+
title: "Bad Saved Object Tags"
4+
version: 0.0.1
5+
source:
6+
license: "Elastic-2.0"
7+
description: "Package containig wrong saved object tags"
8+
type: integration
9+
categories:
10+
- custom
11+
conditions:
12+
kibana.version: "^8.10.0"
13+
elastic.subscription: "basic"
14+
screenshots:
15+
- src: /img/sample-screenshot.png
16+
title: Sample screenshot
17+
size: 600x600
18+
type: image/png
19+
icons:
20+
- src: /img/sample-logo.svg
21+
title: Sample logo
22+
size: 32x32
23+
type: image/svg+xml
24+
policy_templates:
25+
- name: sample
26+
title: Sample logs
27+
description: Collect sample logs
28+
inputs:
29+
- type: logfile
30+
title: Collect sample logs from instances
31+
description: Collecting sample logs
32+
owner:
33+
github: elastic/integrations

0 commit comments

Comments
 (0)