Skip to content

Commit

Permalink
kgo tests: add KGO_TEST_SCRAM
Browse files Browse the repository at this point in the history
  • Loading branch information
twmb committed Dec 31, 2023
1 parent 5f0a3fa commit 4f4f0f0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/kgo/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (

"github.com/twmb/franz-go/pkg/kerr"
"github.com/twmb/franz-go/pkg/kmsg"
"github.com/twmb/franz-go/pkg/sasl"
"github.com/twmb/franz-go/pkg/sasl/scram"
)

var (
Expand All @@ -38,9 +40,12 @@ var (
// cannot use EndAndBeginTransaction with EndBeginTxnUnsafe.
allowUnsafe = false

// DSL syntax is ({ca|cert|key}:path),{1,3}
// KGO_TEST_TLS: DSL syntax is ({ca|cert|key}:path),{1,3}
testCert *tls.Config

// KGO_TEST_SCRAM: DSL is user:pass; we require SCRAM-SHA-256
saslScram sasl.Mechanism

// We create topics with a different number of partitions to exercise
// a few extra code paths; we index into npartitions with npartitionsAt,
// an atomic that we modulo after load.
Expand Down Expand Up @@ -102,13 +107,26 @@ func init() {
testCert.Certificates = append(testCert.Certificates, cert)
}
}
if saslStr, exists := os.LookupEnv("KGO_TEST_SCRAM"); exists {
split := strings.Split(saslStr, ":")
if len(split) != 2 {
panic(fmt.Sprintf("invalid scram format %q", saslStr))
}
saslScram = (scram.Auth{
User: split[0],
Pass: split[1],
}).AsSha256Mechanism()
}
}

func testClientOpts(opts ...Opt) []Opt {
opts = append(opts, getSeedBrokers())
if testCert != nil {
opts = append(opts, DialTLSConfig(testCert))
}
if saslScram != nil {
opts = append(opts, SASL(saslScram))
}
return opts
}

Expand Down

0 comments on commit 4f4f0f0

Please sign in to comment.