From 7805aad4571d46655666fdf664562fff84cf0f02 Mon Sep 17 00:00:00 2001 From: Paul Galceran <29601422+citizen8@users.noreply.github.com> Date: Thu, 4 Sep 2025 22:42:12 +0200 Subject: [PATCH] test: add a test for automatic entry of src and dst ports --- console/filter_test.go | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/console/filter_test.go b/console/filter_test.go index 07adf3c2..6d02ac99 100644 --- a/console/filter_test.go +++ b/console/filter_test.go @@ -132,6 +132,50 @@ LIMIT 20`, "6540"). {"65402:200:100", "large community"}, }). Return(nil) + mockConn.EXPECT(). + Select(gomock.Any(), gomock.Any(), ` +SELECT label, detail FROM ( + SELECT toString(SrcPort) AS label, dictGet('tcp', 'name', SrcPort) AS detail, 1 AS rank, count(*) AS c + FROM flows + WHERE TimeReceived > date_sub(minute, 1, now()) + AND detail != '' + AND positionCaseInsensitive(detail, $1) >= 1 + AND Proto = 6 + GROUP BY SrcPort + ORDER BY COUNT(*) DESC + LIMIT 20 +UNION DISTINCT + SELECT toString(SrcPort) AS label, dictGet(udp, 'name', SrcPort) AS detail, 1 AS rank, count(*) AS c + FROM flows + WHERE TimeReceived > date_sub(minute, 1, now()) + AND detail != '' + AND positionCaseInsensitive(detail, $1) >= 1 + AND Proto = 17 + GROUP BY SrcPort + ORDER BY COUNT(*) DESC + LIMIT 20 +UNION DISTINCT + SELECT toString(port) AS label, name AS detail, 2 AS rank, 0 AS c + FROM tcp + WHERE positionCaseInsensitive(name, $1) >= 1 + ORDER BY positionCaseInsensitive(name, $1) ASC, port ASC + LIMIT 20 +UNION DISTINCT + SELECT toString(port) AS label, name AS detail, 2 AS rank, 0 AS c + FROM udp + WHERE positionCaseInsensitive(name, $1) >= 1 + ORDER BY positionCaseInsensitive(name, $1) ASC, port ASC + LIMIT 20 +) GROUP BY rank, label, detail ORDER BY rank ASC, MAX(c) DESC, MIN(rowNumberInBlock()) ASC LIMIT 20`, "http"). + SetArg(1, []struct { + Label string `ch:"label"` + Detail string `ch:"detail"` + }{ + {"443", "https"}, + {"80", "http"}, + {"8080", "http-alt"}, + }). + Return(nil) helpers.TestHTTPEndpoints(t, h.LocalAddr(), helpers.HTTPEndpointCases{ { @@ -269,6 +313,16 @@ LIMIT 20`, "6540"). {"label": "AS41264", "detail": "Google Switzerland", "quoted": false}, }}, }, + { + URL: "/api/v0/console/filter/complete", + StatusCode: 200, + JSONInput: gin.H{"what": "value", "column": "srcport", "prefix": "http"}, + JSONOutput: gin.H{"completions": []gin.H{ + {"label": "443", "detail": "https", "quoted": false}, + {"label": "80", "detail": "http", "quoted": false}, + {"label": "8080", "detail": "http-alt", "quoted": false}, + }}, + }, { URL: "/api/v0/console/filter/complete", StatusCode: 200,