1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-16 05:16:08 +02:00

consider alias during secret resolving (#2327)

This commit is contained in:
Kevin Stiehl 2020-11-06 17:54:01 +01:00 committed by GitHub
parent 14d7196495
commit 9d461c6753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -151,7 +151,7 @@ func lookupPath(client vaultClient, path string, param *StepParameters) *string
// try parameter aliases
for _, alias := range param.Aliases {
field := secret[param.Name]
field := secret[alias.Name]
if field != "" {
log.RegisterSecret(field)
if alias.Deprecated {

View File

@ -6,10 +6,9 @@ import (
"os"
"testing"
"github.com/stretchr/testify/mock"
"github.com/SAP/jenkins-library/pkg/config/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestVaultConfigLoad(t *testing.T) {
@ -64,6 +63,21 @@ func TestVaultConfigLoad(t *testing.T) {
assert.Len(t, stepConfig.Config, 1)
})
t.Run("Alias names should be considered", func(t *testing.T) {
aliasName := "alias"
vaultMock := &mocks.VaultMock{}
stepConfig := StepConfig{Config: map[string]interface{}{
"vaultBasePath": "team1",
}}
param := stepParam(secretName, "vaultSecret", "$(vaultBasePath)/pipelineA")
addAlias(&param, aliasName)
stepParams := []StepParameters{param}
vaultData := map[string]string{aliasName: "value1"}
vaultMock.On("GetKvSecret", "team1/pipelineA").Return(vaultData, nil)
resolveAllVaultReferences(&stepConfig, vaultMock, stepParams)
assert.Equal(t, "value1", stepConfig.Config[secretName])
})
t.Run("Search over multiple paths", func(t *testing.T) {
vaultMock := &mocks.VaultMock{}
stepConfig := StepConfig{Config: map[string]interface{}{
@ -148,7 +162,8 @@ func TestVaultSecretFiles(t *testing.T) {
func stepParam(name string, refType string, refPaths ...string) StepParameters {
return StepParameters{
Name: name,
Name: name,
Aliases: []Alias{},
ResourceRef: []ResourceReference{
{
Type: refType,
@ -157,3 +172,8 @@ func stepParam(name string, refType string, refPaths ...string) StepParameters {
},
}
}
func addAlias(param *StepParameters, aliasName string) {
alias := Alias{Name: aliasName}
param.Aliases = append(param.Aliases, alias)
}