From 6fb819199e64cf3c29e1d0b56a12a59216e3980a Mon Sep 17 00:00:00 2001 From: secsys-go Date: Thu, 7 Sep 2023 03:36:02 +0000 Subject: [PATCH 1/3] add a fuzz driver whose fuzzing result is helpful --- ...t.go_Test_getPostgreSQLConnectionString.go | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go diff --git a/tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go b/tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go new file mode 100644 index 0000000000000..3e122c993f7bc --- /dev/null +++ b/tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go @@ -0,0 +1,67 @@ +package setting + +import ( + "secsys/gout-transformation/pkg/transstruct" +) +import ( + "os" +) +import ( + "github.com/stretchr/testify/assert" +) +import ( + "testing" +) + +func FuzzTest_getPostgreSQLConnectionString(XVl []byte) int { + t := &testing.T{} + _ = t + var skippingTableDriven bool + _, skippingTableDriven = os.LookupEnv("SKIPPING_TABLE_DRIVEN") + _ = skippingTableDriven + transstruct.SetFuzzData(XVl) + FDG_FuzzGlobal() + + tests := []struct { + Host string + Port string + User string + Passwd string + Name string + Param string + SSLMode string + Output string + }{ + { + Host: transstruct.GetString("/tmp/pg.sock"), + Port: "4321", + User: transstruct.GetString("testuser"), + Passwd: transstruct.GetString("space space !#$%^^%^```-=?="), + Name: transstruct.GetString("gitea"), + Param: transstruct.GetString(""), + SSLMode: transstruct.GetString("false"), + Output: "postgres://testuser:space%20space%20%21%23$%25%5E%5E%25%5E%60%60%60-=%3F=@:5432/giteasslmode=false&host=/tmp/pg.sock", + }, + { + Host: transstruct.GetString("localhost"), + Port: "1234", + User: transstruct.GetString("pgsqlusername"), + Passwd: transstruct.GetString("I love Gitea!"), + Name: transstruct.GetString("gitea"), + Param: transstruct.GetString(""), + SSLMode: transstruct.GetString("true"), + Output: "postgres://pgsqlusername:I%20love%20Gitea%21@localhost:5432/giteasslmode=true", + }, + } + + for _, test := range tests { + connStr := getPostgreSQLConnectionString(test.Host, test.User, test.Passwd, test.Name, test.Param, test.SSLMode) + assert.Equal(t, test.Output, connStr) + } + + return 1 +} + +func FDG_FuzzGlobal() { + +} From b7c724378241f176c58ebdc034bef229081acd07 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Thu, 7 Sep 2023 11:33:35 -0400 Subject: [PATCH 2/3] Update database_test.go_Test_getPostgreSQLConnectionString.go --- ...est.go_Test_getPostgreSQLConnectionString.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go b/tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go index 3e122c993f7bc..be02ab0f54718 100644 --- a/tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go +++ b/tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go @@ -1,16 +1,11 @@ -package setting +package fuzz import ( - "secsys/gout-transformation/pkg/transstruct" -) -import ( - "os" -) -import ( - "github.com/stretchr/testify/assert" -) -import ( - "testing" + "os" + "testing" + + "secsys/gout-transformation/pkg/transstruct" + "github.com/stretchr/testify/assert" ) func FuzzTest_getPostgreSQLConnectionString(XVl []byte) int { From bf6f981cc9974a367e7693805e9eab7966a6b025 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Thu, 7 Sep 2023 11:35:07 -0400 Subject: [PATCH 3/3] Update database_test.go_Test_getPostgreSQLConnectionString.go --- .../database_test.go_Test_getPostgreSQLConnectionString.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go b/tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go index be02ab0f54718..9f77bc0e664ef 100644 --- a/tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go +++ b/tests/fuzz/database_test.go_Test_getPostgreSQLConnectionString.go @@ -1,3 +1,6 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + package fuzz import (