From e84718c37d77d9ac6558fec0f054dc5f70c1b1f3 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Wed, 27 Dec 2023 12:47:43 +0000 Subject: [PATCH 01/10] append len --- pkg/parser/json/json_line.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/parser/json/json_line.go b/pkg/parser/json/json_line.go index 4d468e3d48a..a9f7bb1f058 100644 --- a/pkg/parser/json/json_line.go +++ b/pkg/parser/json/json_line.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "sort" + "strconv" "strings" "github.com/Checkmarx/kics/pkg/model" @@ -133,6 +134,7 @@ func (j *jsonLineStruct) delimSetup(v json.Delim) { j.noremoveidx[lenPathArr] = j.tmpParent } else { // the next close delimiter should not remove the last element from the pathArr + j.pathArr = append(j.pathArr, strconv.Itoa(lenPathArr)) j.noremoveidx[lenPathArr] = j.tmpParent } } From eb0f2aa4178c1237beec6195a7954e16c7e397cf Mon Sep 17 00:00:00 2001 From: Joao Reigota Date: Wed, 27 Dec 2023 17:01:11 +0000 Subject: [PATCH 02/10] fix searchLine array bug --- pkg/parser/json/json_line.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pkg/parser/json/json_line.go b/pkg/parser/json/json_line.go index a9f7bb1f058..121d30c94de 100644 --- a/pkg/parser/json/json_line.go +++ b/pkg/parser/json/json_line.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "sort" - "strconv" "strings" "github.com/Checkmarx/kics/pkg/model" @@ -134,7 +133,6 @@ func (j *jsonLineStruct) delimSetup(v json.Delim) { j.noremoveidx[lenPathArr] = j.tmpParent } else { // the next close delimiter should not remove the last element from the pathArr - j.pathArr = append(j.pathArr, strconv.Itoa(lenPathArr)) j.noremoveidx[lenPathArr] = j.tmpParent } } @@ -194,7 +192,7 @@ func (j *jsonLine) setLine(val map[string]interface{}, def int, father string, p } // iterate through the values of the object - for key, val := range val { + for key, v := range val { // if the key with father path was not found ignore if _, ok2 := j.LineInfo[key][father]; !ok2 { continue @@ -212,13 +210,13 @@ func (j *jsonLine) setLine(val map[string]interface{}, def int, father string, p lineNr = line.(*fifo).pop() } - switch v := val.(type) { + switch v := v.(type) { // value is an array and must call func setSeqLines to set element lines case []interface{}: lineArr = j.setSeqLines(v, lineNr, father, key, lineArr) // value is an object and must setLines for each element of the object case map[string]interface{}: - v["_kics_lines"] = j.setLine(v, lineNr, fmt.Sprintf("%s.%s", father, key), false) + v["_kics_lines"] = j.setLine(v, lineNr, fmt.Sprintf("%s.%s", father, key), pop) default: // value as no childs lineMap[fmt.Sprintf("_kics_%s", key)] = &model.LineObject{ @@ -244,12 +242,12 @@ func (j *jsonLine) setSeqLines(v []interface{}, def int, father, key string, // update father path with key fatherKey := father + "." + key - defaultLineArr := j.getMapDefaultLine(v, fatherKey) - if defaultLineArr == -1 { - defaultLineArr = def - } // iterate over each element of the array for _, contentEntry := range v { + defaultLineArr := j.getMapDefaultLine(v, fatherKey) + if defaultLineArr == -1 { + defaultLineArr = def + } switch con := contentEntry.(type) { // case element is a map/object call func setLine case map[string]interface{}: From 71947195fb7b1664a687b140b4156e4c386bb3d9 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Thu, 28 Dec 2023 09:59:31 +0000 Subject: [PATCH 03/10] merge master --- pkg/parser/json/parser.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/parser/json/parser.go b/pkg/parser/json/parser.go index 53c1828de5a..5aa9196e186 100644 --- a/pkg/parser/json/parser.go +++ b/pkg/parser/json/parser.go @@ -3,7 +3,6 @@ package json import ( "bytes" "encoding/json" - "github.com/Checkmarx/kics/pkg/model" "github.com/Checkmarx/kics/pkg/resolver/file" "github.com/mailru/easyjson" From 1037ac8d46dcda1ab5e7b9fbc72e1ca845474d2b Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Thu, 28 Dec 2023 11:21:33 +0000 Subject: [PATCH 04/10] unit tests --- pkg/parser/json/json_line_test.go | 973 +++++++++++++++++------------- 1 file changed, 543 insertions(+), 430 deletions(-) diff --git a/pkg/parser/json/json_line_test.go b/pkg/parser/json/json_line_test.go index a02cf3ab516..97c4c21397b 100644 --- a/pkg/parser/json/json_line_test.go +++ b/pkg/parser/json/json_line_test.go @@ -21,482 +21,417 @@ var testsinitiateJSONLine = []struct { name: "test array of ints", args: args{ doc: []byte(`{ - "father": { - "son" : [ - 1, - 2, - 3, - 0 - ] + "father": { + "son" : [ + 1, + 2, + 3, + 0 + ] + } } - } - `), + `), }, want: `{ - "LineInfo": { - "0": { - ".father.son": { - "Value": [ - 7 - ] - } - }, - "1": { - ".father.son": { - "Value": [ - 4 - ] - } - }, - "2": { - ".father.son": { - "Value": [ - 5 - ] - } - }, - "3": { - ".father.son": { - "Value": [ - 6 - ] - } - }, - "father": { - "": { - "Value": [ - 2 - ] - } - }, - "son": { - ".father": { - "Value": [ - 3 - ] + "LineInfo": { + "0": { + ".father.son": { + "Value": [ + 7 + ] + } + }, + "1": { + ".father.son": { + "Value": [ + 4 + ] + } + }, + "2": { + ".father.son": { + "Value": [ + 5 + ] + } + }, + "3": { + ".father.son": { + "Value": [ + 6 + ] + } + }, + "father": { + "": { + "Value": [ + 2 + ] + } + }, + "son": { + ".father": { + "Value": [ + 3 + ] + } + } } } - } - } - `, + `, wantKicsLine: `{ - "_kics_lines": { - "_kics__default": { - "_kics_line": 0 - }, - "_kics_father": { - "_kics_line": 2 - } - }, - "father": { - "_kics_lines": { - "_kics__default": { - "_kics_line": 2 + "_kics_lines": { + "_kics__default": { + "_kics_line": 0 + }, + "_kics_father": { + "_kics_line": 2 + } }, - "_kics_son": { - "_kics_arr": [ - { - "_kics__default": { - "_kics_line": 4 - } - }, - { - "_kics__default": { - "_kics_line": 5 - } - }, - { - "_kics__default": { - "_kics_line": 6 - } + "father": { + "_kics_lines": { + "_kics__default": { + "_kics_line": 2 }, - { - "_kics__default": { - "_kics_line": 7 - } + "_kics_son": { + "_kics_arr": [ + { + "_kics__default": { + "_kics_line": 4 + } + }, + { + "_kics__default": { + "_kics_line": 5 + } + }, + { + "_kics__default": { + "_kics_line": 6 + } + }, + { + "_kics__default": { + "_kics_line": 7 + } + } + ], + "_kics_line": 3 } - ], - "_kics_line": 3 + }, + "son": [ + 1, + 2, + 3, + 0 + ] } - }, - "son": [ - 1, - 2, - 3, - 0 - ] - } - }`, + }`, }, { name: "test array objects line", args: args{ doc: []byte(`{ - "father": [ - { - "key": "value" - } - ] - } - `), + "father": [ + { + "key": "value" + } + ] + } + `), }, wantKicsLine: ` - { - "_kics_lines": { - "_kics__default": { - "_kics_line": 0 - }, - "_kics_father": { - "_kics_arr": [ + { + "_kics_lines": { + "_kics__default": { + "_kics_line": 0 + }, + "_kics_father": { + "_kics_arr": [ + { + "_kics__default": { + "_kics_line": 4 + }, + "_kics_key": { + "_kics_line": 4 + } + } + ], + "_kics_line": 2 + } + }, + "father": [ { - "_kics__default": { - "_kics_line": 4 - }, - "_kics_key": { - "_kics_line": 4 - } + "key": "value" } - ], - "_kics_line": 2 - } - }, - "father": [ - { - "key": "value" + ] } - ] - } - `, + `, want: ` - { - "LineInfo": { - "father": { - "": { - "Value": [ - 2 - ] - } - }, - "key": { - ".father": { - "Value": [ - 4 - ] - } - }, - "value": { - ".father": { - "Value": [ - 4 - ] + { + "LineInfo": { + "father": { + "": { + "Value": [ + 2 + ] + } + }, + "key": { + ".father": { + "Value": [ + 4 + ] + } + }, + "value": { + ".father": { + "Value": [ + 4 + ] + } + } } } - } - } - `, + `, }, { name: "test initiate json line", args: args{ doc: []byte(`{ - "parameters": "simple test" - } - `), + "parameters": "simple test" + } + `), }, wantKicsLine: ` - { - "_kics_lines": { - "_kics__default": { - "_kics_line": 0 + { + "_kics_lines": { + "_kics__default": { + "_kics_line": 0 + }, + "_kics_parameters": { + "_kics_line": 2 + } }, - "_kics_parameters": { - "_kics_line": 2 - } - }, - "parameters":"simple test" - }`, + "parameters":"simple test" + }`, want: ` - { - "LineInfo": { - "parameters": { - "": { + { + "LineInfo": { + "parameters": { + "": { + "Value": [ + 2 + ] + } + }, + "simple test": { + "": { "Value": [ - 2 - ] - } - }, - "simple test": { - "": { - "Value": [ - 2 - ] + 2 + ] + } } } } - } - `, + `, }, { name: "test initiate special close json line", args: args{ doc: []byte(`{ - "father": { - "close": [ - "value" - ] + "father": { + "close": [ + "value" + ] + } } - } - `), + `), }, wantKicsLine: ` - { - "_kics_lines": { - "_kics__default": { - "_kics_line": 0 - }, - "_kics_father": { - "_kics_line": 2 - } - }, - "father": { - "_kics_lines": { - "_kics__default": { - "_kics_line": 2 + { + "_kics_lines": { + "_kics__default": { + "_kics_line": 0 + }, + "_kics_father": { + "_kics_line": 2 + } }, - "_kics_close": { - "_kics_arr": [ - { - "_kics__default": { - "_kics_line": 4 - } + "father": { + "_kics_lines": { + "_kics__default": { + "_kics_line": 2 + }, + "_kics_close": { + "_kics_arr": [ + { + "_kics__default": { + "_kics_line": 4 + } + } + ], + "_kics_line": 3 } - ], - "_kics_line": 3 - } - }, - "close": [ - "value" - ] - } - } - `, - want: ` - { - "LineInfo": { - "close": { - ".father": { - "Value": [ - 3 - ] - } - }, - "father": { - "": { - "Value": [ - 2 + }, + "close": [ + "value" ] } - }, - "value": { - ".father.close": { - "Value": [ - 4 - ] + } + `, + want: ` + { + "LineInfo": { + "close": { + ".father": { + "Value": [ + 3 + ] + } + }, + "father": { + "": { + "Value": [ + 2 + ] + } + }, + "value": { + ".father.close": { + "Value": [ + 4 + ] + } + } } } - } - } - `, + `, }, { name: "test same key different path json line", args: args{ doc: []byte(`{ - "father1": { - "key": "value" - }, - "father2": { - "key": "value" + "father1": { + "key": "value" + }, + "father2": { + "key": "value" + } } - } - `), + `), }, wantKicsLine: `{ - "_kics_lines": { - "_kics__default": { - "_kics_line": 0 - }, - "_kics_father1": { - "_kics_line": 2 - }, - "_kics_father2": { - "_kics_line": 5 - } - }, - "father1": { - "_kics_lines": { - "_kics__default": { - "_kics_line": 2 - }, - "_kics_key": { - "_kics_line": 3 - } - }, - "key": "value" - }, - "father2": { - "_kics_lines": { - "_kics__default": { - "_kics_line": 5 + "_kics_lines": { + "_kics__default": { + "_kics_line": 0 + }, + "_kics_father1": { + "_kics_line": 2 + }, + "_kics_father2": { + "_kics_line": 5 + } }, - "_kics_key": { - "_kics_line": 6 - } - }, - "key": "value" - } - }`, - want: ` - { - "LineInfo": { "father1": { - "": { - "Value": [ - 2 - ] + "_kics_lines": { + "_kics__default": { + "_kics_line": 2 + }, + "_kics_key": { + "_kics_line": 3 } + }, + "key": "value" }, "father2": { - "": { - "Value": [ - 5 - ] - } - }, - "key": { - ".father1": { - "Value": [ - 3 - ] + "_kics_lines": { + "_kics__default": { + "_kics_line": 5 }, - ".father2": { - "Value": [ - 6 - ] + "_kics_key": { + "_kics_line": 6 } - }, - "value": { - ".father1": { - "Value": [ - 3 - ] + }, + "key": "value" + } + }`, + want: ` + { + "LineInfo": { + "father1": { + "": { + "Value": [ + 2 + ] + } }, - ".father2": { - "Value": [ - 6 - ] + "father2": { + "": { + "Value": [ + 5 + ] + } + }, + "key": { + ".father1": { + "Value": [ + 3 + ] + }, + ".father2": { + "Value": [ + 6 + ] + } + }, + "value": { + ".father1": { + "Value": [ + 3 + ] + }, + ".father2": { + "Value": [ + 6 + ] + } } } - } - }`, + }`, }, { name: "test with parent json line", args: args{ doc: []byte(`{ - "father": { - "son": "this is a son" + "father": { + "son": "this is a son" + } } - } - `), + `), }, wantKicsLine: ` - { - "_kics_lines": { - "_kics__default": { - "_kics_line": 0 - }, - "_kics_father":{ - "_kics_line": 2 - } - }, - "father": { + { "_kics_lines": { "_kics__default": { - "_kics_line": 2 + "_kics_line": 0 }, - "_kics_son": { - "_kics_line": 3 + "_kics_father":{ + "_kics_line": 2 } }, - "son": "this is a son" - } - }`, - want: ` - { - "LineInfo": { - "father": { - "": { - "Value": [ - 2 - ] - } - }, - "son": { - ".father": { - "Value": [ - 3 - ] - } - }, - "this is a son": { - ".father": { - "Value": [ - 3 - ] - } - } - } - } - `}, - { - name: "test with array string json line", - args: args{ - doc: []byte(`{ - "father": [ - "testing1", - "testing2" - ] - } - `), - }, - wantKicsLine: ` - { - "_kics_lines": { - "_kics__default": { - "_kics_line": 0 - }, - "_kics_father": { - "_kics_arr": [ - { - "_kics__default": { - "_kics_line": 3 - } + "father": { + "_kics_lines": { + "_kics__default": { + "_kics_line": 2 }, - { - "_kics__default": { - "_kics_line": 4 - } + "_kics_son": { + "_kics_line": 3 } - ], - "_kics_line":2 - } - }, - "father": [ - "testing1", - "testing2" - ] - }`, + }, + "son": "this is a son" + } + }`, want: ` { "LineInfo": { @@ -507,83 +442,261 @@ var testsinitiateJSONLine = []struct { ] } }, - "testing1": { + "son": { ".father": { "Value": [ 3 ] } }, - "testing2": { + "this is a son": { ".father": { "Value": [ - 4 + 3 ] } } } } - `, + `}, + { + name: "test with array string json line", + args: args{ + doc: []byte(`{ + "father": [ + "testing1", + "testing2" + ] + } + `), + }, + wantKicsLine: ` + { + "_kics_lines": { + "_kics__default": { + "_kics_line": 0 + }, + "_kics_father": { + "_kics_arr": [ + { + "_kics__default": { + "_kics_line": 3 + } + }, + { + "_kics__default": { + "_kics_line": 4 + } + } + ], + "_kics_line":2 + } + }, + "father": [ + "testing1", + "testing2" + ] + }`, + want: ` + { + "LineInfo": { + "father": { + "": { + "Value": [ + 2 + ] + } + }, + "testing1": { + ".father": { + "Value": [ + 3 + ] + } + }, + "testing2": { + ".father": { + "Value": [ + 4 + ] + } + } + } + } + `, }, { name: "test with equal string json line", args: args{ doc: []byte(`{ - "father": [ + "father": [ + "testing", + "testing" + ] + } + `), + }, + wantKicsLine: ` + { + "_kics_lines": { + "_kics__default": { + "_kics_line": 0 + }, + "_kics_father": { + "_kics_arr":[ + { + "_kics__default": { + "_kics_line": 3 + } + }, + { + "_kics__default": { + "_kics_line": 4 + } + } + ], + "_kics_line": 2 + } + }, + "father":[ "testing", "testing" ] + }`, + want: ` + { + "LineInfo": { + "father": { + "": { + "Value": [ + 2 + ] + } + }, + "testing": { + ".father": { + "Value": [ + 3, + 4 + ] + } + } + } + } + `, + }, + { + name: "my test", + args: args{ + doc: []byte(`{ + "resources": [ + { + "properties": { + "httpsOnly": false + } + }, + { + "properties": { + "httpsOnly": false + } + } + ] } `), }, wantKicsLine: ` - { - "_kics_lines": { - "_kics__default": { - "_kics_line": 0 - }, - "_kics_father": { + { + "_kics_lines":{ + "_kics__default":{ + "_kics_line":0 + }, + "_kics_resources":{ + "_kics_line":2, "_kics_arr":[ { - "_kics__default": { - "_kics_line": 3 + "_kics__default":{ + "_kics_line":4 + }, + "_kics_properties":{ + "_kics_line":4 } }, { - "_kics__default": { - "_kics_line": 4 + "_kics__default":{ + "_kics_line":9 + }, + "_kics_properties":{ + "_kics_line":9 } } - ], - "_kics_line": 2 + ] } }, - "father":[ - "testing", - "testing" + "resources":[ + { + "properties":{ + "_kics_lines":{ + "_kics__default":{ + "_kics_line":4 + }, + "_kics_httpsOnly":{ + "_kics_line":5 + } + }, + "httpsOnly":false + } + }, + { + "properties":{ + "_kics_lines":{ + "_kics__default":{ + "_kics_line":9 + }, + "_kics_httpsOnly":{ + "_kics_line":10 + } + }, + "httpsOnly":false + } + } ] }`, want: ` { - "LineInfo": { - "father": { - "": { - "Value": [ - 2 - ] - } - }, - "testing": { - ".father": { - "Value": [ - 3, - 4 - ] + "LineInfo": { + "false": { + ".resources.properties": { + "Value": [ + 5, + 10 + ] + } + }, + "httpsOnly": { + ".resources.properties": { + "Value": [ + 5, + 10 + ] + } + }, + "properties": { + ".resources": { + "Value": [ + 4, + 9 + ] + } + }, + "resources": { + "": { + "Value": [ + 2 + ] + } } } - } - } - `, + }`, }, } From a781cf2ff4c0a662ab7f043c381d2ecc58f90292 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Thu, 28 Dec 2023 11:31:28 +0000 Subject: [PATCH 05/10] linter --- pkg/parser/json/parser.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/parser/json/parser.go b/pkg/parser/json/parser.go index 5aa9196e186..53c1828de5a 100644 --- a/pkg/parser/json/parser.go +++ b/pkg/parser/json/parser.go @@ -3,6 +3,7 @@ package json import ( "bytes" "encoding/json" + "github.com/Checkmarx/kics/pkg/model" "github.com/Checkmarx/kics/pkg/resolver/file" "github.com/mailru/easyjson" From 9b3b30fe1fd0e77ae1e432312f55b8169831ae94 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Thu, 28 Dec 2023 15:32:30 +0000 Subject: [PATCH 06/10] e2e --- e2e/fixtures/E2E_CLI_077_RESULT.json | 68 +++++++++++++++++++ .../e2e-cli-077_fix_similarity_id.go | 27 ++++++++ .../similarity_id/1_general_deployment.json | 43 ++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 e2e/fixtures/E2E_CLI_077_RESULT.json create mode 100644 e2e/testcases/e2e-cli-077_fix_similarity_id.go create mode 100644 test/fixtures/similarity_id/1_general_deployment.json diff --git a/e2e/fixtures/E2E_CLI_077_RESULT.json b/e2e/fixtures/E2E_CLI_077_RESULT.json new file mode 100644 index 00000000000..72e81a69201 --- /dev/null +++ b/e2e/fixtures/E2E_CLI_077_RESULT.json @@ -0,0 +1,68 @@ +{ + "kics_version": "development", + "files_scanned": 1, + "lines_scanned": 43, + "files_parsed": 1, + "lines_parsed": 43, + "lines_ignored": 0, + "files_failed_to_scan": 0, + "queries_total": 1, + "queries_failed_to_execute": 0, + "queries_failed_to_compute_similarity_id": 0, + "scan_id": "console", + "severity_counters": { + "HIGH": 2, + "INFO": 0, + "LOW": 0, + "MEDIUM": 0, + "TRACE": 0 + }, + "total_counter": 2, + "total_bom_resources": 0, + "start": "2023-12-27T09:48:54.183217Z", + "end": "2023-12-27T09:48:57.0673037Z", + "paths": [ + "C:\\Users\\joaom\\Downloads\\small-sample\\azure_resource_manager_my" + ], + "queries": [ + { + "query_name": "Website Not Forcing HTTPS", + "query_id": "488847ff-6031-487c-bf42-98fd6ac5c9a0", + "query_url": "https://docs.microsoft.com/en-us/azure/templates/microsoft.web/sites?tabs=json#siteproperties-object", + "severity": "HIGH", + "platform": "AzureResourceManager", + "category": "Insecure Configurations", + "experimental": false, + "description": "'Microsoft.Web/sites' should force the use of HTTPS", + "description_id": "3af52329", + "files": [ + { + "file_name": "path\\test\\fixtures\\similarity_id\\1_general_deployment.json", + "similarity_id": "60db1dec778c035dd27b92ac2a39f06a8e44d5e16fc81140d7a70d86cee4a370", + "line": 34, + "resource_type": "Microsoft.Web/sites", + "resource_name": "[variables('functionApp').microsoft_unbilled_synchronization]", + "issue_type": "IncorrectValue", + "search_key": "resources.name={{[variables('functionApp').microsoft_unbilled_synchronization]}}.properties.httpsOnly", + "search_line": -1, + "search_value": "", + "expected_value": "resource with type 'Microsoft.Web/sites' should have the 'httpsOnly' false set to true", + "actual_value": "resource with type 'Microsoft.Web/sites' doesn't have 'httpsOnly' set to true" + }, + { + "file_name": "path\\test\\fixtures\\similarity_id\\1_general_deployment.json", + "similarity_id": "ce5fe80b1d6f673cd23c2e92e490cae2fb8616a482058547d9e63b5417a92b25", + "line": 18, + "resource_type": "Microsoft.Web/sites", + "resource_name": "[variables('functionApp').unbilled_usage_process]", + "issue_type": "IncorrectValue", + "search_key": "resources.name={{[variables('functionApp').unbilled_usage_process]}}.properties.httpsOnly", + "search_line": -1, + "search_value": "", + "expected_value": "resource with type 'Microsoft.Web/sites' should have the 'httpsOnly' false set to true", + "actual_value": "resource with type 'Microsoft.Web/sites' doesn't have 'httpsOnly' set to true" + } + ] + } + ] +} diff --git a/e2e/testcases/e2e-cli-077_fix_similarity_id.go b/e2e/testcases/e2e-cli-077_fix_similarity_id.go new file mode 100644 index 00000000000..54998583898 --- /dev/null +++ b/e2e/testcases/e2e-cli-077_fix_similarity_id.go @@ -0,0 +1,27 @@ +package testcases + +// E2E-CLI-077 - KICS scan +// should perform a scan, present two results, without the same similarity id +func init() { //nolint + testSample := TestCase{ + Name: "should perform a scan, present two results, without the same similarity id [E2E-CLI-077]", + Args: args{ + Args: []cmdArgs{ + []string{"scan", "-o", "/path/e2e/output", + "--output-name", "E2E_CLI_077_RESULT", + "-p", "\"/path/test/fixtures/similarity_id\"", + "-i", "488847ff-6031-487c-bf42-98fd6ac5c9a0", + }, + }, + ExpectedResult: []ResultsValidation{ + { + ResultsFile: "E2E_CLI_077_RESULT", + ResultsFormats: []string{"json"}, + }, + }, + }, + WantStatus: []int{00}, + } + + Tests = append(Tests, testSample) +} diff --git a/test/fixtures/similarity_id/1_general_deployment.json b/test/fixtures/similarity_id/1_general_deployment.json new file mode 100644 index 00000000000..aa8fd77a5a2 --- /dev/null +++ b/test/fixtures/similarity_id/1_general_deployment.json @@ -0,0 +1,43 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + }, + "resources": [ + { + "type": "Microsoft.Web/sites", + "apiVersion": "2021-03-01", + "name": "[variables('functionApp').unbilled_usage_process]", + "location": "[resourceGroup().location]", + "dependsOn": [ + ], + "tags": { + }, + "kind": "functionapp,linux", + "properties": { + "httpsOnly": false, + "keyVaultReferenceIdentity": "SystemAssigned" + }, + "resources": [ + ] + }, + { + "type": "Microsoft.Web/sites", + "apiVersion": "2021-03-01", + "name": "[variables('functionApp').microsoft_unbilled_synchronization]", + "location": "[resourceGroup().location]", + "dependsOn": [], + "tags": { + }, + "kind": "functionapp,linux", + "properties": { + "httpsOnly": false, + "keyVaultReferenceIdentity": "SystemAssigned" + }, + "resources": [ + ] + } + ], + "outputs": { + } +} From c7fe29fba8e0d27510a308467e0a9995a92e1003 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Thu, 28 Dec 2023 15:40:45 +0000 Subject: [PATCH 07/10] fix --- e2e/testcases/e2e-cli-077_fix_similarity_id.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/testcases/e2e-cli-077_fix_similarity_id.go b/e2e/testcases/e2e-cli-077_fix_similarity_id.go index 54998583898..9d33799291e 100644 --- a/e2e/testcases/e2e-cli-077_fix_similarity_id.go +++ b/e2e/testcases/e2e-cli-077_fix_similarity_id.go @@ -20,7 +20,7 @@ func init() { //nolint }, }, }, - WantStatus: []int{00}, + WantStatus: []int{50}, } Tests = append(Tests, testSample) From 8378683e300ba4fb85825bab89eb7110381322cb Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Thu, 28 Dec 2023 16:21:40 +0000 Subject: [PATCH 08/10] fix --- e2e/fixtures/E2E_CLI_077_RESULT.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/e2e/fixtures/E2E_CLI_077_RESULT.json b/e2e/fixtures/E2E_CLI_077_RESULT.json index 72e81a69201..5e8fb2144c5 100644 --- a/e2e/fixtures/E2E_CLI_077_RESULT.json +++ b/e2e/fixtures/E2E_CLI_077_RESULT.json @@ -1,9 +1,9 @@ { "kics_version": "development", "files_scanned": 1, - "lines_scanned": 43, + "lines_scanned": 44, "files_parsed": 1, - "lines_parsed": 43, + "lines_parsed": 44, "lines_ignored": 0, "files_failed_to_scan": 0, "queries_total": 1, @@ -22,7 +22,7 @@ "start": "2023-12-27T09:48:54.183217Z", "end": "2023-12-27T09:48:57.0673037Z", "paths": [ - "C:\\Users\\joaom\\Downloads\\small-sample\\azure_resource_manager_my" + "/path/test/fixtures/similarity_id/" ], "queries": [ { @@ -38,26 +38,26 @@ "files": [ { "file_name": "path\\test\\fixtures\\similarity_id\\1_general_deployment.json", - "similarity_id": "60db1dec778c035dd27b92ac2a39f06a8e44d5e16fc81140d7a70d86cee4a370", + "similarity_id": "f649e674f984920f340e4078adb4d472fa857d1a8bcfa3e4e0418743faa946fd", "line": 34, "resource_type": "Microsoft.Web/sites", "resource_name": "[variables('functionApp').microsoft_unbilled_synchronization]", "issue_type": "IncorrectValue", "search_key": "resources.name={{[variables('functionApp').microsoft_unbilled_synchronization]}}.properties.httpsOnly", - "search_line": -1, + "search_line": 34, "search_value": "", "expected_value": "resource with type 'Microsoft.Web/sites' should have the 'httpsOnly' false set to true", "actual_value": "resource with type 'Microsoft.Web/sites' doesn't have 'httpsOnly' set to true" }, { "file_name": "path\\test\\fixtures\\similarity_id\\1_general_deployment.json", - "similarity_id": "ce5fe80b1d6f673cd23c2e92e490cae2fb8616a482058547d9e63b5417a92b25", + "similarity_id": "8e341b61966dfc47b2e78304b28b445c9891be5143fcf6bd09f5ba0679e1b0ca", "line": 18, "resource_type": "Microsoft.Web/sites", "resource_name": "[variables('functionApp').unbilled_usage_process]", "issue_type": "IncorrectValue", "search_key": "resources.name={{[variables('functionApp').unbilled_usage_process]}}.properties.httpsOnly", - "search_line": -1, + "search_line": 18, "search_value": "", "expected_value": "resource with type 'Microsoft.Web/sites' should have the 'httpsOnly' false set to true", "actual_value": "resource with type 'Microsoft.Web/sites' doesn't have 'httpsOnly' set to true" From f3f8f799e6c875e1e331ef8271ff6154976c70dd Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Thu, 28 Dec 2023 17:01:29 +0000 Subject: [PATCH 09/10] fix e2e --- e2e/fixtures/E2E_CLI_077_RESULT.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/fixtures/E2E_CLI_077_RESULT.json b/e2e/fixtures/E2E_CLI_077_RESULT.json index 5e8fb2144c5..e7288fe1221 100644 --- a/e2e/fixtures/E2E_CLI_077_RESULT.json +++ b/e2e/fixtures/E2E_CLI_077_RESULT.json @@ -22,7 +22,7 @@ "start": "2023-12-27T09:48:54.183217Z", "end": "2023-12-27T09:48:57.0673037Z", "paths": [ - "/path/test/fixtures/similarity_id/" + "/path/test/fixtures/similarity_id" ], "queries": [ { From d887cf7a164c6b20bdf028172464158eb46e5eb4 Mon Sep 17 00:00:00 2001 From: JoaoCxMartins Date: Fri, 5 Jan 2024 10:30:55 +0000 Subject: [PATCH 10/10] change name of the test --- pkg/parser/json/json_line_test.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/parser/json/json_line_test.go b/pkg/parser/json/json_line_test.go index 97c4c21397b..2f1f7421a40 100644 --- a/pkg/parser/json/json_line_test.go +++ b/pkg/parser/json/json_line_test.go @@ -586,7 +586,7 @@ var testsinitiateJSONLine = []struct { `, }, { - name: "my test", + name: "test arrays with objects", args: args{ doc: []byte(`{ "resources": [ @@ -712,19 +712,20 @@ func Test_initializeJSONLine(t *testing.T) { func compareJSONLine(t *testing.T, test1 interface{}, test2 string) { stringefiedJSON, err := json.Marshal(&test1) require.NoError(t, err) - require.JSONEq(t, test2, string(stringefiedJSON)) + aux := string(stringefiedJSON) + require.JSONEq(t, test2, aux) } func Test_jsonLine_setLineInfo(t *testing.T) { for _, tt := range testsinitiateJSONLine { - t.Run(tt.name, func(t *testing.T) { - unmarshaledJSON := make(map[string]interface{}) - err := json.Unmarshal(tt.args.doc, &unmarshaledJSON) - require.NoError(t, err) - j := initializeJSONLine(tt.args.doc) - got := j.setLineInfo(unmarshaledJSON) - compareJSONLine(t, got, tt.wantKicsLine) - }) + //t.Run(tt.name, func(t *testing.T) { + unmarshaledJSON := make(map[string]interface{}) + err := json.Unmarshal(tt.args.doc, &unmarshaledJSON) + require.NoError(t, err) + j := initializeJSONLine(tt.args.doc) + got := j.setLineInfo(unmarshaledJSON) + compareJSONLine(t, got, tt.wantKicsLine) + //}) } }