Skip to content

Commit

Permalink
added a hash function and return plush errors
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed May 7, 2018
1 parent f1fb25a commit e2e0134
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fix/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func Init(box packr.Box) error {
}

x, err := render(file)
if err != nil {
return errors.Wrap(errors.WithStack(err), path)
}

sc := Scenarios{}
_, err = toml.Decode(x, &sc)
Expand Down
10 changes: 10 additions & 0 deletions fix/plush.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gobuffalo/plush"
"github.com/gobuffalo/uuid"
"github.com/pkg/errors"
"golang.org/x/crypto/bcrypt"
)

func render(file packr.File) (string, error) {
Expand All @@ -23,8 +24,17 @@ func render(file packr.File) (string, error) {
},
"uuidNamed": uuidNamed,
"now": time.Now,
"hash": hash,
}))
}

func hash(s string, opts map[string]interface{}, help plush.HelperContext) (string, error) {
cost := bcrypt.DefaultCost
if i, ok := opts["cost"].(int); ok {
cost = i
}
ph, err := bcrypt.GenerateFromPassword([]byte(s), cost)
return string(ph), err
}

func uuidNamed(name string, help plush.HelperContext) uuid.UUID {
Expand Down
15 changes: 15 additions & 0 deletions fix/plush_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package fix

import (
"testing"

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

func Test_hash(t *testing.T) {
r := require.New(t)
s, err := hash("password", map[string]interface{}{}, plush.HelperContext{})

This comment has been minimized.

Copy link
@robbyoconnor

robbyoconnor May 7, 2018

Contributor

This is probably my newbieness -- but doesn't the order matter?

r.NoError(err)
r.NotEqual("password", s)
}

0 comments on commit e2e0134

Please sign in to comment.