Skip to content

Commit

Permalink
Fixed reading secret file (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlfredBroda authored Jul 25, 2019
1 parent cafd637 commit ed1ae76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion action/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func getCommonParameters(c *cli.Context) CommonConfig {
}

// GetSecretFromFile reads a value from provided file
func (config CommonConfig) GetSecretFromFile(secretFile string) error {
func (config *CommonConfig) GetSecretFromFile(secretFile string) error {
secret, err := ioutil.ReadFile(secretFile)
if err != nil {
return fmt.Errorf("unable to read secret from file: %s, %s", secretFile, err)
Expand Down
27 changes: 27 additions & 0 deletions action/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package action

import (
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/require"
)

func TestGetSecretFromFileCorrectly(t *testing.T) {
config := CommonConfig{
VaaSKeyFile: "vaas-secret",
}
secretContent := "secret token"

data := []byte(secretContent)
err := ioutil.WriteFile(config.VaaSKeyFile, data, 0644)
require.NoError(t, err)

err = config.GetSecretFromFile(config.VaaSKeyFile)
require.NoError(t, err)
require.Equal(t, config.VaaSKey, secretContent)

err = os.Remove(config.VaaSKeyFile)
require.NoError(t, err)
}

0 comments on commit ed1ae76

Please sign in to comment.