test actually updating secret
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-09 12:16:02 +11:00
parent bc1ca7b481
commit f45a0f3aeb
2 changed files with 38 additions and 3 deletions

View File

@@ -200,6 +200,13 @@ func UpdateSecret(c *gin.Context) {
log.Printf("UpdateSecret received JSON input '%v'\n", input)
if len(input.SecretValue) == 0 {
errString := "UpdateSecret no updated secret specified\n"
log.Print(errString)
c.JSON(http.StatusBadRequest, gin.H{"error": errString})
return
}
// Temporarily disable because we should be able to figure it out without user specifying
/*
if input.SafeId == 0 && len(input.SafeName) == 0 {
@@ -238,7 +245,36 @@ func UpdateSecret(c *gin.Context) {
return
} else if len(secretList) == 1 {
// Update secret
log.Printf("mock updating secret\n")
//log.Printf("mock updating secret\n")
log.Printf("secretList[0]: %v\n", secretList[0])
s.SecretId = secretList[0].SecretId
// check for empty fields in the update request and update from the existing record
if s.UserName == "" {
s.UserName = secretList[0].Secret.UserName
}
if s.DeviceCategory == "" {
s.DeviceCategory = secretList[0].DeviceCategory
}
if s.DeviceName == "" {
s.DeviceName = secretList[0].DeviceName
}
// Encrypt secret
s.Secret = input.SecretValue
_, err = s.EncryptSecret()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "UpdateSecret error encrypting secret : " + err.Error()})
return
}
_, err = s.UpdateSecret()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "UpdateSecret error saving secret : " + err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "secret updated successfully"})
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "multiple secrets matched search parameters, be more specific"})