Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate all Kibana object filenames #72

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/tools v0.0.0-20201021000207-d49c4edd7d96 // indirect
golang.org/x/tools v0.0.0-20201029135353-690a3c245f28 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
)
9 changes: 9 additions & 0 deletions code/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,26 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 h1:EBZoQjiKKPaLbPrbpssUfuHtwM6KV/vb4U85g/cigFY=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20201021000207-d49c4edd7d96 h1:K+nJoPcImWk+ZGPHOKkDocKcQPACCz8usiCiVQYfXsk=
golang.org/x/tools v0.0.0-20201021000207-d49c4edd7d96/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/tools v0.0.0-20201028224754-2c115999a7f0 h1:XGD9jHm8W1VxgkBYiLwvm2ff2ZJFyjfjNoxGhTO7Rp8=
golang.org/x/tools v0.0.0-20201028224754-2c115999a7f0/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201029135353-690a3c245f28 h1:KmEPH4S/AVTMSlbgNWC4xKvfsqvw/dNDUo/bGDqbDdo=
golang.org/x/tools v0.0.0-20201029135353-690a3c245f28/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion code/go/internal/spec/statik.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
42 changes: 30 additions & 12 deletions code/go/pkg/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,50 @@ func TestValidateFile(t *testing.T) {
}

func TestValidateItemNotAllowed(t *testing.T) {
tests := map[string]struct {
itemFolder string
invalidItems []string
}{
"wrong_dashboard_filename": {
"kibana/dashboard",
[]string{
tests := map[string]map[string][]string{
"wrong_kibana_filename": {
"kibana/dashboard": []string{
"b7e55b73-97cc-44fd-8555-d01b7e13e70d.json",
"bad-dashboard.json",
},
"kibana/map": []string{
"06149856-cbc1-4988-a93a-815915c4408e.json",
"bad-map.json",
},
"kibana/search": []string{
"691240b5-7ec9-4fd7-8750-4ef97944f960.json",
"bad-search.json",
},
"kibana/visualization": []string{
"defa1bcc-1ab6-4069-adec-8c997b069a5e.json",
"bad-visualization.json",
},
},
}

for pkgName, test := range tests {
for pkgName, invalidItemsPerFolder := range tests {
t.Run(pkgName, func(t *testing.T) {
pkgRootPath := filepath.Join("..", "..", "internal", "validator", "test", "packages", pkgName)

errs := ValidateFromPath(pkgRootPath)
require.Error(t, errs)
require.Len(t, errs, len(test.invalidItems))
vErrs, ok := errs.(validator.ValidationErrors)
require.True(t, ok)
for idx, err := range vErrs {
expected := fmt.Sprintf("item [%s] is not allowed in folder [%s/%s]", test.invalidItems[idx], pkgRootPath, test.itemFolder)
require.Contains(t, err.Error(), expected)

var errMessages []string
for _, vErr := range vErrs {
errMessages = append(errMessages, vErr.Error())
}

var c int
for itemFolder, invalidItems := range invalidItemsPerFolder {
for _, invalidItem := range invalidItems {
c++
expected := fmt.Sprintf("item [%s] is not allowed in folder [%s/%s]", invalidItem, pkgRootPath, itemFolder)
require.Contains(t, errMessages, expected)
}
}
require.Len(t, errs, c)
})
}
}
6 changes: 3 additions & 3 deletions versions/1/kibana/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- description: A visualization asset file
type: file
contentMediaType: "application/json"
pattern: '.+\.json'
pattern: '{PACKAGE_NAME}-.+\.json'
- description: Folder containing Kibana saved search assets
type: folder
name: search
Expand All @@ -27,7 +27,7 @@
- description: A saved search asset file
type: file
contentMediaType: "application/json"
pattern: '.+\.json'
pattern: '{PACKAGE_NAME}-.+\.json'
- description: Folder containing Kibana map assets
type: folder
name: map
Expand All @@ -36,7 +36,7 @@
- description: A map asset file
type: file
contentMediaType: "application/json"
pattern: '.+\.json'
pattern: '{PACKAGE_NAME}-.+\.json'
- description: Folder containing Kibana index pattern assets
type: folder
name: "index_pattern"
Expand Down