Skip to content

Commit 716927e

Browse files
committed
test: cover PAM-backed store password import
1 parent d2629a3 commit 716927e

19 files changed

Lines changed: 72 additions & 36 deletions

File tree

cmd/storesBulkOperations.go

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -393,29 +393,11 @@ If you do not wish to include credentials in your CSV file they can be provided
393393
reqJson.Delete("Properties") // todo: why is this deleting the properties from the request json?
394394

395395
rowStorePassword := reqJson.S("Password").Data()
396-
passwdParams := api.UpdateStorePasswordConfig{
397-
SecretValue: nil,
398-
}
396+
passwdParams := buildUpdateStorePasswordConfig(rowStorePassword)
399397
switch rowStorePassword.(type) {
400398
case string:
401399
if rowStorePassword != "" {
402400
reqJson.Delete("Password")
403-
passwdValue := rowStorePassword.(string)
404-
passwdParams.SecretValue = &passwdValue
405-
}
406-
case map[string]interface{}:
407-
// try to convert it to api.UpdateStorePasswordConfig
408-
rowPasswordMap := rowStorePassword.(map[string]interface{})
409-
if providerId, ok := rowPasswordMap["ProviderId"].(int); ok {
410-
passwdParams.Provider = providerId
411-
}
412-
if params, ok := rowPasswordMap["Parameters"].(map[string]interface{}); ok {
413-
for k, v := range params {
414-
if passwdParams.Parameters == nil {
415-
passwdParams.Parameters = make(map[string]string)
416-
}
417-
passwdParams.Parameters[k] = fmt.Sprintf("%v", v)
418-
}
419401
}
420402
}
421403

@@ -1187,6 +1169,35 @@ func shouldTreatCSVValueAsSecretString(header string) bool {
11871169
}
11881170
}
11891171

1172+
func buildUpdateStorePasswordConfig(rowStorePassword interface{}) api.UpdateStorePasswordConfig {
1173+
passwdParams := api.UpdateStorePasswordConfig{
1174+
SecretValue: nil,
1175+
}
1176+
1177+
switch typedPassword := rowStorePassword.(type) {
1178+
case string:
1179+
if typedPassword != "" {
1180+
passwdParams.SecretValue = &typedPassword
1181+
}
1182+
case map[string]interface{}:
1183+
if providerId, ok := typedPassword["ProviderId"].(int); ok {
1184+
passwdParams.Provider = providerId
1185+
} else if providerId, ok := typedPassword["Provider"].(int); ok {
1186+
passwdParams.Provider = providerId
1187+
}
1188+
if params, ok := typedPassword["Parameters"].(map[string]interface{}); ok {
1189+
for k, v := range params {
1190+
if passwdParams.Parameters == nil {
1191+
passwdParams.Parameters = make(map[string]string)
1192+
}
1193+
passwdParams.Parameters[k] = fmt.Sprintf("%v", v)
1194+
}
1195+
}
1196+
}
1197+
1198+
return passwdParams
1199+
}
1200+
11901201
func writeCsvFile(outpath string, rows [][]string) error {
11911202
log.Debug().Msgf("Writing CSV file '%s'", outpath)
11921203
csvFile, err := os.Create(outpath)

cmd/stores_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,31 @@ func Test_GetJsonForRequest_TreatsJsonSecretValuesAsStrings(t *testing.T) {
369369
assert.Equal(t, row[1], reqJson.S("Properties", "ServerUsername", "SecretValue").Data())
370370
}
371371

372+
func Test_BuildUpdateStorePasswordConfig_FormatsManagedPamStorePassword(t *testing.T) {
373+
header := []string{
374+
"Password.ProviderId",
375+
"Password.Parameters.SecretName",
376+
"Password.Parameters.SecretType",
377+
"Password.Parameters.StaticSecretFieldName",
378+
}
379+
row := []string{"30", "dev/aks/kf-integrations", "static_json", " "}
380+
381+
reqJson := getJsonForRequest(header, row)
382+
storePassword := buildUpdateStorePasswordConfig(reqJson.S("Password").Data())
383+
384+
assert.Equal(t, 30, storePassword.Provider)
385+
assert.Nil(t, storePassword.SecretValue)
386+
assert.Equal(
387+
t,
388+
map[string]string{
389+
"SecretName": "dev/aks/kf-integrations",
390+
"SecretType": "static_json",
391+
"StaticSecretFieldName": " ",
392+
},
393+
storePassword.Parameters,
394+
)
395+
}
396+
372397
func testExportStore(t *testing.T, storeTypeName string) (string, []string) {
373398
var (
374399
output string

docs/use-cases/Certificate Store Operations/Store Types/citrixadc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Properties.ServerPassword.Provider,Properties.ServerPassword.Parameters.<Paramet
115115

116116
Use the PAM parameter names in the table below, or check the provider type in Command if your environment uses custom PAM types.
117117

118-
The store password uses the `Password` column. For a PAM-backed store password, use `Password.Provider` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
118+
The store password uses the `Password` column. For a PAM-backed store password, use `Password.ProviderId` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
119119

120120
| PAM type | Store CSV parameter names |
121121
| --- | --- |

docs/use-cases/Certificate Store Operations/Store Types/f5-sl-rest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Properties.ServerPassword.Provider,Properties.ServerPassword.Parameters.<Paramet
120120

121121
Use the PAM parameter names in the table below, or check the provider type in Command if your environment uses custom PAM types.
122122

123-
The store password uses the `Password` column. For a PAM-backed store password, use `Password.Provider` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
123+
The store password uses the `Password` column. For a PAM-backed store password, use `Password.ProviderId` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
124124

125125
| PAM type | Store CSV parameter names |
126126
| --- | --- |

docs/use-cases/Certificate Store Operations/Store Types/fortigate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ This store type does not define additional `Properties.*` CSV columns.
8585

8686
## Secret And PAM Formatting
8787

88-
The store password uses the `Password` column. For a PAM-backed store password, use `Password.Provider` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
88+
The store password uses the `Password` column. For a PAM-backed store password, use `Password.ProviderId` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
8989

9090
| PAM type | Store CSV parameter names |
9191
| --- | --- |

docs/use-cases/Certificate Store Operations/Store Types/gcpscrtmgr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ These parameters apply to certificate add/enrollment operations for this store t
9696

9797
## Secret And PAM Formatting
9898

99-
The store password uses the `Password` column. For a PAM-backed store password, use `Password.Provider` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
99+
The store password uses the `Password` column. For a PAM-backed store password, use `Password.ProviderId` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
100100

101101
| PAM type | Store CSV parameter names |
102102
| --- | --- |

docs/use-cases/Certificate Store Operations/Store Types/hcvkvjks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Properties.ServerPassword.Provider,Properties.ServerPassword.Parameters.<Paramet
107107

108108
Use the PAM parameter names in the table below, or check the provider type in Command if your environment uses custom PAM types.
109109

110-
The store password uses the `Password` column. For a PAM-backed store password, use `Password.Provider` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
110+
The store password uses the `Password` column. For a PAM-backed store password, use `Password.ProviderId` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
111111

112112
| PAM type | Store CSV parameter names |
113113
| --- | --- |

docs/use-cases/Certificate Store Operations/Store Types/hcvkvp12.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Properties.ServerPassword.Provider,Properties.ServerPassword.Parameters.<Paramet
107107

108108
Use the PAM parameter names in the table below, or check the provider type in Command if your environment uses custom PAM types.
109109

110-
The store password uses the `Password` column. For a PAM-backed store password, use `Password.Provider` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
110+
The store password uses the `Password` column. For a PAM-backed store password, use `Password.ProviderId` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
111111

112112
| PAM type | Store CSV parameter names |
113113
| --- | --- |

docs/use-cases/Certificate Store Operations/Store Types/hcvkvpem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Properties.ServerPassword.Provider,Properties.ServerPassword.Parameters.<Paramet
107107

108108
Use the PAM parameter names in the table below, or check the provider type in Command if your environment uses custom PAM types.
109109

110-
The store password uses the `Password` column. For a PAM-backed store password, use `Password.Provider` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
110+
The store password uses the `Password` column. For a PAM-backed store password, use `Password.ProviderId` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
111111

112112
| PAM type | Store CSV parameter names |
113113
| --- | --- |

docs/use-cases/Certificate Store Operations/Store Types/hcvkvpfx.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Properties.ServerPassword.Provider,Properties.ServerPassword.Parameters.<Paramet
107107

108108
Use the PAM parameter names in the table below, or check the provider type in Command if your environment uses custom PAM types.
109109

110-
The store password uses the `Password` column. For a PAM-backed store password, use `Password.Provider` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
110+
The store password uses the `Password` column. For a PAM-backed store password, use `Password.ProviderId` and `Password.Parameters.<ParameterName>` columns. The `Parameters.*` columns must match the instance-level parameters for the configured PAM provider type.
111111

112112
| PAM type | Store CSV parameter names |
113113
| --- | --- |

0 commit comments

Comments
 (0)