diff --git a/pkg/config/kafka_environment_test.go b/pkg/config/kafka_environment_test.go index a483582b..1bd2f173 100644 --- a/pkg/config/kafka_environment_test.go +++ b/pkg/config/kafka_environment_test.go @@ -12,27 +12,28 @@ import ( func TestKafkaEnvironmentConfigGenerated(t *testing.T) { var envKeys = []string{ - consts.KafkaCertificate, - consts.KafkaCa, - consts.KafkaPrivateKey, - consts.KafkaClientKeystoreP12, - consts.KafkaClientTruststoreJks, - consts.KafkaCredStorePassword, - consts.KafkaSchemaRegistry, + consts.KafkaCAKey, + consts.KafkaCertificateKey, + consts.KafkaPrivateKeyKey, + consts.KafkaClientKeyStoreP12File, + consts.KafkaClientTruststoreJksFile, + consts.KafkaCredStorePasswordKey, + consts.KafkaSchemaRegistryKey, } tmpDest := test.SetupDest(t) - kcatConfig := NewEnvConfig(test.SetupSecret(envKeys), KafkaConfigEnvToFileMap, tmpDest) + kcatConfig := NewEnvConfig(test.SetupSecret(envKeys), tmpDest) + result, err := kcatConfig.Generate() assert.NoError(t, err) - assert.True(t, strings.Contains(result, "client.truststore.jks")) - assert.True(t, strings.Contains(result, "KAFKA_CREDSTORE_PASSWORD")) - assert.True(t, strings.Contains(result, "KAFKA_SCHEMA_REGISTRY")) - assert.True(t, strings.Contains(result, "KAFKA_CERTIFICATE")) - assert.True(t, strings.Contains(result, "KAFKA_CA")) - assert.True(t, strings.Contains(result, "KAFKA_PRIVATE_KEY")) - assert.True(t, strings.Contains(result, "client.keystore.p12")) + assert.True(t, strings.Contains(result, consts.KafkaClientTruststoreJksFile)) + assert.True(t, strings.Contains(result, consts.KafkaCredStorePasswordKey)) + assert.True(t, strings.Contains(result, consts.KafkaSchemaRegistryKey)) + assert.True(t, strings.Contains(result, consts.KafkaCertificateKey)) + assert.True(t, strings.Contains(result, consts.KafkaCAKey)) + assert.True(t, strings.Contains(result, consts.KafkaPrivateKeyKey)) + assert.True(t, strings.Contains(result, consts.KafkaClientKeyStoreP12File)) defer os.Remove(tmpDest) } @@ -40,16 +41,16 @@ func TestKafkaEnvironmentConfigGenerated(t *testing.T) { func TestKafkaEnvironmentSecrettMissingRequiredData(t *testing.T) { var envKeys = []string{ - consts.KafkaCertificate, - consts.KafkaCa, - consts.KafkaPrivateKey, - consts.KafkaClientKeystoreP12, - consts.KafkaCredStorePassword, - consts.KafkaSchemaRegistry, + consts.KafkaCAKey, + consts.KafkaCertificateKey, + consts.KafkaPrivateKeyKey, + consts.KafkaClientKeyStoreP12File, + consts.KafkaCredStorePasswordKey, + consts.KafkaSchemaRegistryKey, } tmpDest := test.SetupDest(t) - kcatConfig := NewEnvConfig(test.SetupSecret(envKeys), KafkaConfigEnvToFileMap, tmpDest) + kcatConfig := NewEnvConfig(test.SetupSecret(envKeys), tmpDest) _, err := kcatConfig.Generate() assert.EqualError(t, err, "can not generate kafka-secret.env config, secret missing required key: client.truststore.jks") diff --git a/pkg/config/kcat_test.go b/pkg/config/kcat_test.go index 06d05127..044e69c5 100644 --- a/pkg/config/kcat_test.go +++ b/pkg/config/kcat_test.go @@ -12,25 +12,24 @@ import ( func TestKcatConfigGenerated(t *testing.T) { var envKeys = []string{ - consts.KafkaCertificate, - consts.KafkaCa, - consts.KafkaPrivateKey, - consts.KafkaClientKeystoreP12, - consts.KafkaClientTruststoreJks, - consts.KafkaCredStorePassword, - consts.KafkaSchemaRegistry, + consts.KafkaCAKey, + consts.KafkaCertificateKey, + consts.KafkaPrivateKeyKey, + consts.KafkaClientKeyStoreP12File, + consts.KafkaClientTruststoreJksFile, + consts.KafkaCredStorePasswordKey, + consts.KafkaSchemaRegistryKey, } tmpDest := test.SetupDest(t) - kcatConfig := NewKCatConfig(test.SetupSecret(envKeys), KCatEnvToFileMap, tmpDest) + kcatConfig := NewKCatConfig(test.SetupSecret(envKeys), tmpDest) result, err := kcatConfig.Generate() assert.NoError(t, err) - assert.NoError(t, err) - assert.True(t, strings.Contains(result, "ssl.ca.location")) - assert.True(t, strings.Contains(result, "ssl.key.location")) - assert.True(t, strings.Contains(result, "ssl.certificate")) - assert.True(t, strings.Contains(result, "security.protocol")) + assert.True(t, strings.Contains(result, KafkaCatSslCaLocation)) + assert.True(t, strings.Contains(result, KafkaCatSslKeyLocation)) + assert.True(t, strings.Contains(result, KafkaCatSslCertificateLocation)) + assert.True(t, strings.Contains(result, KafkaSecurityProtocolLocation)) defer os.Remove(tmpDest) } @@ -38,12 +37,12 @@ func TestKcatConfigGenerated(t *testing.T) { func TestKcatSecretMissingRequiredData(t *testing.T) { var envKeys = []string{ - consts.KafkaCertificate, - consts.KafkaCa, + consts.KafkaCAKey, + consts.KafkaCertificateKey, } tmpDest := test.SetupDest(t) - kcatConfig := NewKCatConfig(test.SetupSecret(envKeys), KCatEnvToFileMap, tmpDest) + kcatConfig := NewKCatConfig(test.SetupSecret(envKeys), tmpDest) _, err := kcatConfig.Generate() assert.EqualError(t, err, "can not generate kcat.conf config, secret missing required key: KAFKA_PRIVATE_KEY") diff --git a/pkg/secret/secret_test.go b/pkg/secret/secret_test.go deleted file mode 100644 index 0b4a8a30..00000000 --- a/pkg/secret/secret_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package secret - -import ( - "fmt" - "github.com/nais/nais-cli/pkg/config" - "github.com/nais/nais-cli/pkg/consts" - "github.com/nais/nais-cli/pkg/test" - "github.com/stretchr/testify/assert" - "io/ioutil" - "os" - "strings" - "testing" -) - -func TestGeneratedFilesAndSecretConfiguration(t *testing.T) { - - content := "c29tZS12YWx1ZQ==" - - var envKeys = []string{ - consts.KafkaCertificate, - consts.KafkaCa, - consts.KafkaPrivateKey, - consts.KafkaClientKeystoreP12, - consts.KafkaClientTruststoreJks, - consts.KafkaCredStorePassword, - consts.KafkaSchemaRegistry, - } - - tempDir := test.SetupDest(t) - existingSecret := test.SetupSecret(envKeys) - - secret := SetupSecretConfiguration(existingSecret, config.ENV, tempDir) - - kafkaEnvData, err := secret.Config() - assert.NoError(t, err) - - // Test kafka.env file created - assert.True(t, strings.Contains(kafkaEnvData, "client.truststore.jks")) - assert.True(t, strings.Contains(kafkaEnvData, "KAFKA_CREDSTORE_PASSWORD")) - assert.True(t, strings.Contains(kafkaEnvData, "KAFKA_SCHEMA_REGISTRY")) - assert.True(t, strings.Contains(kafkaEnvData, "KAFKA_CERTIFICATE")) - assert.True(t, strings.Contains(kafkaEnvData, "KAFKA_CA")) - assert.True(t, strings.Contains(kafkaEnvData, "KAFKA_PRIVATE_KEY")) - assert.True(t, strings.Contains(kafkaEnvData, "client.keystore.p12")) - - var fileKeys = []string{ - consts.KafkaClientCertificateCrtFile, - consts.KafkaCACrtFile, - consts.KafkaClientPrivateKeyPemFile, - consts.KafkaClientKeyStoreP12File, - consts.KafkaClientTruststoreJksFile, - } - - // Test cert files created - for _, value := range fileKeys { - certFileData, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", tempDir, value)) - assert.NoError(t, err) - assert.Equal(t, content, string(certFileData)) - } - - // Test kcat file created - secret = SetupSecretConfiguration(existingSecret, config.KCAT, tempDir) - kcatData, err := secret.Config() - assert.NoError(t, err) - assert.True(t, strings.Contains(kcatData, "ssl.ca.location")) - assert.True(t, strings.Contains(kcatData, "ssl.key.location")) - assert.True(t, strings.Contains(kcatData, "ssl.certificate")) - assert.True(t, strings.Contains(kcatData, "security.protocol")) - - defer os.Remove(tempDir) -}