From a702f0f93a5cb24face5f1abf8ed4ed426f84f46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Mert=20Y=C4=B1ld=C4=B1ran?= Date: Sat, 22 Jan 2022 20:09:31 +0300 Subject: [PATCH 1/2] Merge repeated keys in query parameters into arrays (#674) --- tap/extensions/http/helpers.go | 52 ++++++++++++++++++++++++++++++---- tap/extensions/http/main.go | 5 ++-- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/tap/extensions/http/helpers.go b/tap/extensions/http/helpers.go index 9bf15fca1..c40c1d738 100644 --- a/tap/extensions/http/helpers.go +++ b/tap/extensions/http/helpers.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "reflect" "strconv" "github.com/up9inc/mizu/tap/api" @@ -18,16 +19,55 @@ func mapSliceRebuildAsMap(mapSlice []interface{}) (newMap map[string]interface{} return } +func mapSliceMergeRepeatedKeys(mapSlice []interface{}) (newMapSlice []interface{}) { + newMapSlice = make([]interface{}, 0) + valuesMap := make(map[string][]interface{}) + for _, item := range mapSlice { + h := item.(map[string]interface{}) + key := h["name"].(string) + valuesMap[key] = append(valuesMap[key], h["value"]) + } + + for key, values := range valuesMap { + h := make(map[string]interface{}) + h["name"] = key + if len(values) == 1 { + h["value"] = values[0] + } else { + h["value"] = values + } + newMapSlice = append(newMapSlice, h) + } + + return +} + func representMapSliceAsTable(mapSlice []interface{}, selectorPrefix string) (representation string) { var table []api.TableData for _, item := range mapSlice { h := item.(map[string]interface{}) - selector := fmt.Sprintf("%s[\"%s\"]", selectorPrefix, h["name"].(string)) - table = append(table, api.TableData{ - Name: h["name"].(string), - Value: h["value"], - Selector: selector, - }) + key := h["name"].(string) + value := h["value"] + switch reflect.TypeOf(value).Kind() { + case reflect.Slice: + fallthrough + case reflect.Array: + for i, el := range value.([]interface{}) { + selector := fmt.Sprintf("%s.%s[%d]", selectorPrefix, key, i) + table = append(table, api.TableData{ + Name: fmt.Sprintf("%s [%d]", key, i), + Value: el, + Selector: selector, + }) + } + default: + selector := fmt.Sprintf("%s[\"%s\"]", selectorPrefix, key) + table = append(table, api.TableData{ + Name: key, + Value: value, + Selector: selector, + }) + } } obj, _ := json.Marshal(table) diff --git a/tap/extensions/http/main.go b/tap/extensions/http/main.go index df9432bc5..00365b9f2 100644 --- a/tap/extensions/http/main.go +++ b/tap/extensions/http/main.go @@ -239,7 +239,8 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, resolvedSource string, resDetails["cookies"] = mapSliceRebuildAsMap(resDetails["_cookies"].([]interface{})) reqDetails["_queryString"] = reqDetails["queryString"] - reqDetails["queryString"] = mapSliceRebuildAsMap(reqDetails["_queryString"].([]interface{})) + reqDetails["_queryStringMerged"] = mapSliceMergeRepeatedKeys(reqDetails["_queryString"].([]interface{})) + reqDetails["queryString"] = mapSliceRebuildAsMap(reqDetails["_queryStringMerged"].([]interface{})) method := reqDetails["method"].(string) statusCode := int(resDetails["status"].(float64)) @@ -336,7 +337,7 @@ func representRequest(request map[string]interface{}) (repRequest []interface{}) repRequest = append(repRequest, api.SectionData{ Type: api.TABLE, Title: "Query String", - Data: representMapSliceAsTable(request["_queryString"].([]interface{}), `request.queryString`), + Data: representMapSliceAsTable(request["_queryStringMerged"].([]interface{}), `request.queryString`), }) postData, _ := request["postData"].(map[string]interface{}) From 2638672603d7299280618602db194acd8358ca92 Mon Sep 17 00:00:00 2001 From: Gustavo Massaneiro Date: Sat, 22 Jan 2022 15:33:48 -0300 Subject: [PATCH 2/2] updated debug.Dockerfile to use node 16 (#675) --- debug.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug.Dockerfile b/debug.Dockerfile index 51fe4a549..9bf2754b5 100644 --- a/debug.Dockerfile +++ b/debug.Dockerfile @@ -1,5 +1,5 @@ # creates image in which mizu agent is remotely debuggable using delve -FROM node:14-slim AS site-build +FROM node:16-slim AS site-build WORKDIR /app/ui-build