Skip to content

Commit

Permalink
Merge pull request #62 from moov-io/set-vault-cryptor-from-config
Browse files Browse the repository at this point in the history
fix: set vault cryptor in FromConfig
  • Loading branch information
adamdecaf authored May 10, 2024
2 parents c7c8d43 + 4b77225 commit f12be5d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func FromConfig(conf Config) (*FS, error) {
if conf.Encryption.GPG.PublicPath != "" && conf.Encryption.GPG.PrivatePath != "" {
cryptor, err = NewGPGCryptorFile(conf.Encryption.GPG.PublicPath, conf.Encryption.GPG.PrivatePath, password)
}

case conf.Encryption.Vault != nil:
cryptor, err = NewVaultCryptor(*conf.Encryption.Vault)
}
if err != nil {
return nil, fmt.Errorf("cryptor from config: %w", err)
Expand Down
14 changes: 14 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package cryptfs

import (
"fmt"
"path/filepath"
"strings"
"testing"
Expand All @@ -31,6 +32,8 @@ func TestFromConfig(t *testing.T) {
t.Run("zero value", func(t *testing.T) {
fsys, err := FromConfig(conf)
require.NoError(t, err)
require.Equal(t, "*cryptfs.nothingCryptor", fmt.Sprintf("%T", fsys.cryptor))

testCryptFS(t, fsys)
})

Expand All @@ -40,6 +43,8 @@ func TestFromConfig(t *testing.T) {

fsys, err := FromConfig(conf)
require.NoError(t, err)
require.Equal(t, "*cryptfs.nothingCryptor", fmt.Sprintf("%T", fsys.cryptor))

testCryptFS(t, fsys)
})

Expand All @@ -50,6 +55,8 @@ func TestFromConfig(t *testing.T) {

fsys, err := FromConfig(conf)
require.NoError(t, err)
require.Equal(t, "*cryptfs.AESCryptor", fmt.Sprintf("%T", fsys.cryptor))

testCryptFS(t, fsys)
})

Expand Down Expand Up @@ -83,6 +90,7 @@ func TestFromConfig(t *testing.T) {

fsys, err = FromConfig(conf)
require.NoError(t, err)
require.Equal(t, "*cryptfs.GPGCryptor", fmt.Sprintf("%T", fsys.cryptor))

bs, err := fsys.ReadFile(path)
require.NoError(t, err)
Expand All @@ -99,10 +107,14 @@ func TestFromConfig(t *testing.T) {

fsys, err := FromConfig(conf)
require.NoError(t, err)
require.Equal(t, "*cryptfs.GPGCryptor", fmt.Sprintf("%T", fsys.cryptor))

testCryptFS(t, fsys)
})

t.Run("Vault", func(t *testing.T) {
shouldSkipDockerTest(t)

conf.Encryption.GPG = nil
conf.Encryption.Vault = &VaultConfig{
Address: "http://localhost:8200",
Expand All @@ -114,6 +126,8 @@ func TestFromConfig(t *testing.T) {

fsys, err := FromConfig(conf)
require.NoError(t, err)
require.Equal(t, "*cryptfs.VaultCryptor", fmt.Sprintf("%T", fsys.cryptor))

testCryptFS(t, fsys)
})
}
17 changes: 12 additions & 5 deletions cryptor_vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ import (
)

func TestVaultCryptor(t *testing.T) {
isGithubCI := os.Getenv("GITHUB_ACTIONS") != ""
isLinux := runtime.GOOS == "linux"
if isGithubCI && !isLinux {
t.Skipf("docker is not supported on %s github runners", runtime.GOOS)
}
shouldSkipDockerTest(t)

if testing.Short() {
t.Skip("skipping network tests")
}
Expand Down Expand Up @@ -69,3 +66,13 @@ func TestVaultCryptor(t *testing.T) {
require.Equal(t, input, bs)
})
}

func shouldSkipDockerTest(t *testing.T) {
t.Helper()

isGithubCI := os.Getenv("GITHUB_ACTIONS") != ""
isLinux := runtime.GOOS == "linux"
if isGithubCI && !isLinux {
t.Skipf("docker is not supported on %s github runners", runtime.GOOS)
}
}

0 comments on commit f12be5d

Please sign in to comment.