Skip to content

Commit

Permalink
kgo tests: support 512 in KGO_TEST_SCRAM
Browse files Browse the repository at this point in the history
  • Loading branch information
twmb committed Dec 31, 2023
1 parent 4f4f0f0 commit 351ef98
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkg/kgo/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
// 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
// KGO_TEST_SCRAM: DSL is user:pass(:num); we assume 256
saslScram sasl.Mechanism

// We create topics with a different number of partitions to exercise
Expand Down Expand Up @@ -109,13 +109,26 @@ func init() {
}
if saslStr, exists := os.LookupEnv("KGO_TEST_SCRAM"); exists {
split := strings.Split(saslStr, ":")
if len(split) != 2 {
if len(split) != 2 && len(split) != 3 {
panic(fmt.Sprintf("invalid scram format %q", saslStr))
}
saslScram = (scram.Auth{
a := scram.Auth{
User: split[0],
Pass: split[1],
}).AsSha256Mechanism()
}
saslScram = a.AsSha256Mechanism()
if len(split) == 3 {
n, err := strconv.Atoi(split[2])
if err != nil {
panic(fmt.Sprintf("invalid scram alg %q: %v", split[2], err))
}
if n != 256 && n != 512 {
panic(fmt.Sprintf("invalid scram alg %q: must be 256 or 512", split[2]))
}
if n == 512 {
saslScram = a.AsSha512Mechanism()
}
}
}
}

Expand Down

0 comments on commit 351ef98

Please sign in to comment.