mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-28 22:08:34 +00:00
More pre-loaded
This commit is contained in:
@@ -48,7 +48,8 @@ func TestEntries(t *testing.T) {
|
||||
t.FailNow()
|
||||
}
|
||||
GetOasGeneratorInstance().Start()
|
||||
loadStartingOAS()
|
||||
loadStartingOAS("test_artifacts/catalogue.json", "catalogue")
|
||||
loadStartingOAS("test_artifacts/trcc.json", "trcc-api-service")
|
||||
|
||||
cnt, err := feedEntries(files, true)
|
||||
if err != nil {
|
||||
@@ -175,8 +176,7 @@ func waitQueueProcessed() {
|
||||
}
|
||||
}
|
||||
|
||||
func loadStartingOAS() {
|
||||
file := "test_artifacts/catalogue.json"
|
||||
func loadStartingOAS(file string, label string) {
|
||||
fd, err := os.Open(file)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -195,10 +195,10 @@ func loadStartingOAS() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
gen := NewGen("catalogue")
|
||||
gen := NewGen(label)
|
||||
gen.StartFromSpec(doc)
|
||||
|
||||
GetOasGeneratorInstance().ServiceSpecs.Store("catalogue", gen)
|
||||
GetOasGeneratorInstance().ServiceSpecs.Store(label, gen)
|
||||
}
|
||||
|
||||
func TestEntriesNegative(t *testing.T) {
|
||||
|
25
agent/pkg/oas/test_artifacts/trcc.json
Normal file
25
agent/pkg/oas/test_artifacts/trcc.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Preloaded TRCC",
|
||||
"version": "0.1",
|
||||
"description": "Test file for loading pre-existing OAS"
|
||||
},
|
||||
"paths": {
|
||||
"/models/{id}": {
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"style": "simple",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"pattern": ".+(_|-|\\.).+"
|
||||
},
|
||||
"example": "some-uuid-maybe"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@@ -51,7 +51,7 @@ func (n *Node) getOrSet(path NodePath, existingPathObj *openapi.PathObj) (node *
|
||||
node = n.searchInConstants(pathChunk)
|
||||
}
|
||||
|
||||
if node == nil {
|
||||
if node == nil && pathChunk != "" {
|
||||
node = n.searchInParams(paramObj, pathChunk, chunkIsGibberish)
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ func getPatternFromExamples(exmp *openapi.Examples) *openapi.Regexp {
|
||||
|
||||
if allInts {
|
||||
re := new(openapi.Regexp)
|
||||
re.Regexp = regexp.MustCompile("\\d+")
|
||||
re.Regexp = regexp.MustCompile(`\d+`)
|
||||
return re
|
||||
}
|
||||
return nil
|
||||
@@ -153,10 +153,6 @@ func (n *Node) createParam() *openapi.ParameterObj {
|
||||
}
|
||||
|
||||
func (n *Node) searchInParams(paramObj *openapi.ParameterObj, chunk string, chunkIsGibberish bool) *Node {
|
||||
if paramObj != nil || chunkIsGibberish {
|
||||
logger.Log.Debugf("")
|
||||
}
|
||||
|
||||
// look among params
|
||||
for _, subnode := range n.children {
|
||||
if subnode.constant != nil {
|
||||
@@ -172,6 +168,8 @@ func (n *Node) searchInParams(paramObj *openapi.ParameterObj, chunk string, chun
|
||||
// TODO: and not in exceptions
|
||||
if subnode.pathParam.Schema.Pattern.Match([]byte(chunk)) {
|
||||
return subnode
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user