package sprig import ( "crypto/x509" "encoding/base64" "encoding/pem" "fmt" "strings" "testing" "github.com/stretchr/testify/assert" bcrypt_lib "golang.org/x/crypto/bcrypt" ) const ( beginCertificate = "-----BEGIN CERTIFICATE-----" endCertificate = "-----END CERTIFICATE-----" ) var ( // fastCertKeyAlgos is the list of private key algorithms that are supported for certificate use, and // are fast to generate. fastCertKeyAlgos = []string{ "ecdsa", "ed25519", } ) func TestSha256Sum(t *testing.T) { tpl := `{{"abc" | sha256sum}}` if err := runt(tpl, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"); err != nil { t.Error(err) } } func TestSha1Sum(t *testing.T) { tpl := `{{"abc" | sha1sum}}` if err := runt(tpl, "a9993e364706816aba3e25717850c26c9cd0d89d"); err != nil { t.Error(err) } } func TestAdler32Sum(t *testing.T) { tpl := `{{"abc" | adler32sum}}` if err := runt(tpl, "38600999"); err != nil { t.Error(err) } } func TestBcrypt(t *testing.T) { out, err := runRaw(`{{"abc" | bcrypt}}`, nil) if err != nil { t.Error(err) } if bcrypt_lib.CompareHashAndPassword([]byte(out), []byte("abc")) != nil { t.Error("Generated hash is not the equivalent for password:", "abc") } } type HtpasswdCred struct { Username string Password string Valid bool } func TestHtpasswd(t *testing.T) { expectations := []HtpasswdCred{ {Username: "myUser", Password: "myPassword", Valid: true}, {Username: "special'o79Cv_*qFe,)