Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions pkg/detectors/jdbc/jdbc_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestJdbcVerified(t *testing.T) {
postgresUser := gofakeit.Username()
postgresPass := gofakeit.Password(true, true, true, false, false, 10)
postgresDB := gofakeit.Word()
postgresContainer, err := postgres.RunContainer(ctx,
testcontainers.WithImage("postgres:13-alpine"),
postgresContainer, err := postgres.Run(ctx,
"postgres:13-alpine",
postgres.WithDatabase(postgresDB),
postgres.WithUsername(postgresUser),
postgres.WithPassword(postgresPass),
Expand All @@ -56,8 +56,8 @@ func TestJdbcVerified(t *testing.T) {
mysqlUser := gofakeit.Username()
mysqlPass := gofakeit.Password(true, true, true, false, false, 10)
mysqlDatabase := gofakeit.Word()
mysqlC, err := mysql.RunContainer(ctx,
mysql.WithDatabase(mysqlDatabase),
mysqlC, err := mysql.Run(ctx,
"mysql:8.0.36",
mysql.WithUsername(mysqlUser),
mysql.WithPassword(mysqlPass),
)
Expand All @@ -79,8 +79,8 @@ func TestJdbcVerified(t *testing.T) {
sqlServerPass := gofakeit.Password(true, true, true, false, false, 10)
sqlServerDatabase := "master"

mssqlContainer, err := mssql.RunContainer(ctx,
testcontainers.WithImage("mcr.microsoft.com/azure-sql-edge"),
mssqlContainer, err := mssql.Run(ctx,
"mcr.microsoft.com/azure-sql-edge",
mssql.WithAcceptEULA(),
mssql.WithPassword(sqlServerPass),
)
Expand Down Expand Up @@ -125,6 +125,10 @@ func TestJdbcVerified(t *testing.T) {
Verified: true,
Redacted: fmt.Sprintf("jdbc:postgresql://%s:%s/%s?sslmode=disable&password=%s&user=%s",
postgresHost, postgresPort.Port(), postgresDB, strings.Repeat("*", len(postgresPass)), postgresUser),
AnalysisInfo: map[string]string{
"connection_string": fmt.Sprintf("jdbc:postgresql://%s:%s/%s?sslmode=disable&password=%s&user=%s",
postgresHost, postgresPort.Port(), postgresDB, postgresPass, postgresUser),
},
},
},
wantErr: false,
Expand All @@ -143,6 +147,10 @@ func TestJdbcVerified(t *testing.T) {
Verified: true,
Redacted: fmt.Sprintf(`jdbc:mysql://%s:%s@tcp(%s:%s)/%s`,
mysqlUser, strings.Repeat("*", len(mysqlPass)), mysqlHost, mysqlPort.Port(), mysqlDatabase),
AnalysisInfo: map[string]string{
"connection_string": fmt.Sprintf(`jdbc:mysql://%s:%s@tcp(%s:%s)/%s`,
mysqlUser, mysqlPass, mysqlHost, mysqlPort.Port(), mysqlDatabase),
},
},
},
wantErr: false,
Expand All @@ -161,6 +169,10 @@ func TestJdbcVerified(t *testing.T) {
Verified: true,
Redacted: fmt.Sprintf("jdbc:sqlserver://odbc:server=%s;port=%s;database=%s;password=%s",
sqlServerHost, sqlServerPort.Port(), sqlServerDatabase, strings.Repeat("*", len(sqlServerPass))),
AnalysisInfo: map[string]string{
"connection_string": fmt.Sprintf("jdbc:sqlserver://odbc:server=%s;port=%s;database=%s;password=%s",
sqlServerHost, sqlServerPort.Port(), sqlServerDatabase, sqlServerPass),
},
},
},
wantErr: false,
Expand Down
3 changes: 2 additions & 1 deletion pkg/detectors/jdbc/mysql_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func TestMySQL(t *testing.T) {

ctx := context.Background()

mysqlC, err := mysql.RunContainer(ctx,
mysqlC, err := mysql.Run(ctx,
"mysql:8.0.36",
mysql.WithDatabase(mysqlDatabase),
mysql.WithUsername(mysqlUser),
mysql.WithPassword(mysqlPass),
Expand Down
9 changes: 2 additions & 7 deletions pkg/detectors/jdbc/postgres_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package jdbc
import (
"context"
"fmt"
"log"
"testing"
"time"

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

ctx := context.Background()
postgresContainer, err := postgres.RunContainer(ctx,
testcontainers.WithImage("postgres:13-alpine"),
postgresContainer, err := postgres.Run(ctx,
"postgres:13-alpine",
postgres.WithDatabase(dbName),
postgres.WithUsername(user),
postgres.WithPassword(pass),
Expand All @@ -56,10 +55,6 @@ func TestPostgres(t *testing.T) {
if err != nil {
t.Fatal(err)
}

if err != nil {
log.Fatalf("failed to start container: %s", err)
}
defer postgresContainer.Terminate(ctx)

tests := []struct {
Expand Down
7 changes: 3 additions & 4 deletions pkg/detectors/jdbc/sqlserver_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

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

mssqlContainer, err := mssql.RunContainer(ctx,
testcontainers.WithImage("mcr.microsoft.com/azure-sql-edge"),
mssqlContainer, err := mssql.Run(ctx,
"mcr.microsoft.com/azure-sql-edge",
mssql.WithAcceptEULA(),
mssql.WithPassword(sqlServerPass),
)
Expand Down Expand Up @@ -62,7 +61,7 @@ func TestSqlServer(t *testing.T) {
want: result{pingOk: true, pingDeterminate: true},
},
{
input: "//server=badhost;user id=sa;database=master;password=",
input: fmt.Sprintf("//server=badhost;user id=sa;database=master;password=%s", sqlServerPass),
want: result{pingOk: false, pingDeterminate: false},
},
{
Expand Down