Skip to content

Commit f13722a

Browse files
Merge branch 'trufflesecurity:jdbc-detector-regex-fix' into jdbc-detector-regex-fix
2 parents daa94b1 + 30b4660 commit f13722a

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

pkg/detectors/jdbc/jdbc_integration_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func TestJdbcVerified(t *testing.T) {
2929
postgresUser := gofakeit.Username()
3030
postgresPass := gofakeit.Password(true, true, true, false, false, 10)
3131
postgresDB := gofakeit.Word()
32-
postgresContainer, err := postgres.RunContainer(ctx,
33-
testcontainers.WithImage("postgres:13-alpine"),
32+
postgresContainer, err := postgres.Run(ctx,
33+
"postgres:13-alpine",
3434
postgres.WithDatabase(postgresDB),
3535
postgres.WithUsername(postgresUser),
3636
postgres.WithPassword(postgresPass),
@@ -56,8 +56,8 @@ func TestJdbcVerified(t *testing.T) {
5656
mysqlUser := gofakeit.Username()
5757
mysqlPass := gofakeit.Password(true, true, true, false, false, 10)
5858
mysqlDatabase := gofakeit.Word()
59-
mysqlC, err := mysql.RunContainer(ctx,
60-
mysql.WithDatabase(mysqlDatabase),
59+
mysqlC, err := mysql.Run(ctx,
60+
"mysql:8.0.36",
6161
mysql.WithUsername(mysqlUser),
6262
mysql.WithPassword(mysqlPass),
6363
)
@@ -79,8 +79,8 @@ func TestJdbcVerified(t *testing.T) {
7979
sqlServerPass := gofakeit.Password(true, true, true, false, false, 10)
8080
sqlServerDatabase := "master"
8181

82-
mssqlContainer, err := mssql.RunContainer(ctx,
83-
testcontainers.WithImage("mcr.microsoft.com/azure-sql-edge"),
82+
mssqlContainer, err := mssql.Run(ctx,
83+
"mcr.microsoft.com/azure-sql-edge",
8484
mssql.WithAcceptEULA(),
8585
mssql.WithPassword(sqlServerPass),
8686
)
@@ -125,6 +125,10 @@ func TestJdbcVerified(t *testing.T) {
125125
Verified: true,
126126
Redacted: fmt.Sprintf("jdbc:postgresql://%s:%s/%s?sslmode=disable&password=%s&user=%s",
127127
postgresHost, postgresPort.Port(), postgresDB, strings.Repeat("*", len(postgresPass)), postgresUser),
128+
AnalysisInfo: map[string]string{
129+
"connection_string": fmt.Sprintf("jdbc:postgresql://%s:%s/%s?sslmode=disable&password=%s&user=%s",
130+
postgresHost, postgresPort.Port(), postgresDB, postgresPass, postgresUser),
131+
},
128132
},
129133
},
130134
wantErr: false,
@@ -143,6 +147,10 @@ func TestJdbcVerified(t *testing.T) {
143147
Verified: true,
144148
Redacted: fmt.Sprintf(`jdbc:mysql://%s:%s@tcp(%s:%s)/%s`,
145149
mysqlUser, strings.Repeat("*", len(mysqlPass)), mysqlHost, mysqlPort.Port(), mysqlDatabase),
150+
AnalysisInfo: map[string]string{
151+
"connection_string": fmt.Sprintf(`jdbc:mysql://%s:%s@tcp(%s:%s)/%s`,
152+
mysqlUser, mysqlPass, mysqlHost, mysqlPort.Port(), mysqlDatabase),
153+
},
146154
},
147155
},
148156
wantErr: false,
@@ -161,6 +169,10 @@ func TestJdbcVerified(t *testing.T) {
161169
Verified: true,
162170
Redacted: fmt.Sprintf("jdbc:sqlserver://odbc:server=%s;port=%s;database=%s;password=%s",
163171
sqlServerHost, sqlServerPort.Port(), sqlServerDatabase, strings.Repeat("*", len(sqlServerPass))),
172+
AnalysisInfo: map[string]string{
173+
"connection_string": fmt.Sprintf("jdbc:sqlserver://odbc:server=%s;port=%s;database=%s;password=%s",
174+
sqlServerHost, sqlServerPort.Port(), sqlServerDatabase, sqlServerPass),
175+
},
164176
},
165177
},
166178
wantErr: false,

pkg/detectors/jdbc/mysql_integration_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ func TestMySQL(t *testing.T) {
2323

2424
ctx := context.Background()
2525

26-
mysqlC, err := mysql.RunContainer(ctx,
26+
mysqlC, err := mysql.Run(ctx,
27+
"mysql:8.0.36",
2728
mysql.WithDatabase(mysqlDatabase),
2829
mysql.WithUsername(mysqlUser),
2930
mysql.WithPassword(mysqlPass),

pkg/detectors/jdbc/postgres_integration_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package jdbc
66
import (
77
"context"
88
"fmt"
9-
"log"
109
"testing"
1110
"time"
1211

@@ -34,8 +33,8 @@ func TestPostgres(t *testing.T) {
3433
t.Log("dbName: ", dbName)
3534

3635
ctx := context.Background()
37-
postgresContainer, err := postgres.RunContainer(ctx,
38-
testcontainers.WithImage("postgres:13-alpine"),
36+
postgresContainer, err := postgres.Run(ctx,
37+
"postgres:13-alpine",
3938
postgres.WithDatabase(dbName),
4039
postgres.WithUsername(user),
4140
postgres.WithPassword(pass),
@@ -56,10 +55,6 @@ func TestPostgres(t *testing.T) {
5655
if err != nil {
5756
t.Fatal(err)
5857
}
59-
60-
if err != nil {
61-
log.Fatalf("failed to start container: %s", err)
62-
}
6358
defer postgresContainer.Terminate(ctx)
6459

6560
tests := []struct {

pkg/detectors/jdbc/sqlserver_integration_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/brianvoe/gofakeit/v7"
1212
"github.com/stretchr/testify/assert"
13-
"github.com/testcontainers/testcontainers-go"
1413
"github.com/testcontainers/testcontainers-go/modules/mssql"
1514
logContext "github.com/trufflesecurity/trufflehog/v3/pkg/context"
1615
)
@@ -22,8 +21,8 @@ func TestSqlServer(t *testing.T) {
2221
sqlServerPass := gofakeit.Password(true, true, true, false, false, 10)
2322
sqlServerDB := "master"
2423

25-
mssqlContainer, err := mssql.RunContainer(ctx,
26-
testcontainers.WithImage("mcr.microsoft.com/azure-sql-edge"),
24+
mssqlContainer, err := mssql.Run(ctx,
25+
"mcr.microsoft.com/azure-sql-edge",
2726
mssql.WithAcceptEULA(),
2827
mssql.WithPassword(sqlServerPass),
2928
)
@@ -62,7 +61,7 @@ func TestSqlServer(t *testing.T) {
6261
want: result{pingOk: true, pingDeterminate: true},
6362
},
6463
{
65-
input: "//server=badhost;user id=sa;database=master;password=",
64+
input: fmt.Sprintf("//server=badhost;user id=sa;database=master;password=%s", sqlServerPass),
6665
want: result{pingOk: false, pingDeterminate: false},
6766
},
6867
{

0 commit comments

Comments
 (0)