Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testing_for_plain_test
Browse files Browse the repository at this point in the history
Signed-off-by: mehul gautam <[email protected]>
mehul gautam committed Jun 27, 2024
1 parent ee78dbe commit d6efe4f
Showing 3 changed files with 24 additions and 44 deletions.
2 changes: 2 additions & 0 deletions cmd/ingester/app/flags_test.go
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ func TestOptionsWithFlags(t *testing.T) {
"--kafka.consumer.protocol-version=1.0.0",
"--ingester.parallelism=5",
"--ingester.deadlockInterval=2m",
"--kafka.consumer.authentication=tls",
})
o.InitFromViper(v)

@@ -56,6 +57,7 @@ func TestOptionsWithFlags(t *testing.T) {
assert.Equal(t, 5, o.Parallelism)
assert.Equal(t, 2*time.Minute, o.DeadlockInterval)
assert.Equal(t, kafka.EncodingJSON, o.Encoding)
assert.Equal(t, "tls", o.AuthenticationConfig.Authentication)
}

func TestTLSFlags(t *testing.T) {
65 changes: 21 additions & 44 deletions pkg/kafka/auth/config_test.go → pkg/kafka/auth/config_test.txt
Original file line number Diff line number Diff line change
@@ -8,55 +8,14 @@ import (

"github.com/Shopify/sarama"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
//"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
//"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
)

func Test_InitFromViper(t *testing.T) {
v := viper.New()
configPrefix := "kafka.auth."
v.Set(configPrefix+suffixAuthentication, "tls")
v.Set(configPrefix+kerberosPrefix+suffixKerberosServiceName, "kafka")
v.Set(configPrefix+kerberosPrefix+suffixKerberosRealm, "EXAMPLE.COM")
v.Set(configPrefix+kerberosPrefix+suffixKerberosUseKeyTab, true)
v.Set(configPrefix+kerberosPrefix+suffixKerberosUsername, "user")
v.Set(configPrefix+kerberosPrefix+suffixKerberosPassword, "password")
v.Set(configPrefix+kerberosPrefix+suffixKerberosConfig, "/path/to/krb5.conf")
v.Set(configPrefix+kerberosPrefix+suffixKerberosKeyTab, "/path/to/keytab")
v.Set(configPrefix+kerberosPrefix+suffixKerberosDisablePAFXFAST, true)
v.Set(configPrefix+plainTextPrefix+suffixPlainTextUsername, "user")
v.Set(configPrefix+plainTextPrefix+suffixPlainTextPassword, "password")
v.Set(configPrefix+plainTextPrefix+suffixPlainTextMechanism, "SCRAM-SHA-256")

authConfig := &AuthenticationConfig{}
err := authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
expectedConfig := &AuthenticationConfig{
Authentication: "tls",
Kerberos: KerberosConfig{
ServiceName: "kafka",
Realm: "EXAMPLE.COM",
UseKeyTab: true,
Username: "user",
Password: "password",
ConfigPath: "/path/to/krb5.conf",
KeyTabPath: "/path/to/keytab",
DisablePAFXFast: true,
},
TLS: tlscfg.Options{
Enabled: true,
},
PlainText: PlainTextConfig{
Username: "user",
Password: "password",
Mechanism: "SCRAM-SHA-256",
},
}
assert.Equal(t, expectedConfig, authConfig)
}

func TestSetConfiguration(t *testing.T) {
logger, _ := zap.NewDevelopment()
@@ -80,12 +39,30 @@ func TestSetConfiguration(t *testing.T) {
err := authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
require.NoError(t, authConfig.SetConfiguration(saramaConfig, logger))
// plaintest test
// plaintest test(SCRAM-SHA-256)
v.Set(configPrefix+suffixAuthentication, "plaintext")
authConfig = &AuthenticationConfig{}
err = authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
require.NoError(t, authConfig.SetConfiguration(saramaConfig, logger))
// plaintest test(SCRAM-SHA-512)
v.Set(configPrefix+plainTextPrefix+suffixPlainTextMechanism, "SCRAM-SHA-512")
authConfig = &AuthenticationConfig{}
err = authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
require.NoError(t, authConfig.SetConfiguration(saramaConfig, logger))
// plaintest test(PLAIN)
v.Set(configPrefix+plainTextPrefix+suffixPlainTextMechanism, "PLAIN")
authConfig = &AuthenticationConfig{}
err = authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
require.NoError(t, authConfig.SetConfiguration(saramaConfig, logger))
// default value
v.Set(configPrefix+suffixAuthentication, "none")
authConfig = &AuthenticationConfig{}
err = authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
require.Error(t, authConfig.SetConfiguration(saramaConfig, logger), nil)
// none value
v.Set(configPrefix+suffixAuthentication, " ")
authConfig = &AuthenticationConfig{}
1 change: 1 addition & 0 deletions plugin/storage/integration/kafka_test.go
Original file line number Diff line number Diff line change
@@ -82,6 +82,7 @@ func (s *KafkaIntegrationTestSuite) initialize(t *testing.T) {
clientID,
"--ingester.parallelism",
"1000",
"--kafka.consumer.authentication=plaintext",
})
require.NoError(t, err)
options := app.Options{

0 comments on commit d6efe4f

Please sign in to comment.