speedup test runner with disable hasher

This commit is contained in:
Hayden 2022-10-16 18:09:09 -08:00
parent ea750c9ec3
commit a28d03a675
3 changed files with 31 additions and 8 deletions

View file

@ -2,7 +2,7 @@ version: "3"
env:
HBOX_STORAGE_SQLITE_URL: .data/homebox.db?_fk=1
UNSAFE_DISABLE_PASSWORD_PROJECTION: "yes_i_am_sure"
tasks:
setup:
desc: Install dependencies

View file

@ -33,6 +33,8 @@ type V1Controller struct {
}
type (
ReadyFunc func() bool
Build struct {
Version string `json:"version"`
Commit string `json:"commit"`
@ -53,7 +55,6 @@ func BaseUrlFunc(prefix string) func(s string) string {
return func(s string) string {
return prefix + "/v1" + s
}
}
func NewControllerV1(svc *services.AllServices, options ...func(*V1Controller)) *V1Controller {
@ -69,8 +70,6 @@ func NewControllerV1(svc *services.AllServices, options ...func(*V1Controller))
return ctrl
}
type ReadyFunc func() bool
// HandleBase godoc
// @Summary Retrieves the basic information about the API
// @Tags Base

View file

@ -1,13 +1,37 @@
package hasher
import "golang.org/x/crypto/bcrypt"
import (
"fmt"
"os"
"golang.org/x/crypto/bcrypt"
)
var enabled = true
func init() {
disableHas := os.Getenv("UNSAFE_DISABLE_PASSWORD_PROJECTION") == "yes_i_am_sure"
if disableHas {
fmt.Println("WARNING: Password projection is disabled. This is unsafe in production.")
enabled = false
}
}
func HashPassword(password string) (string, error) {
if !enabled {
return password, nil
}
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return string(bytes), err
}
func CheckPasswordHash(password, hash string) bool {
if !enabled {
return password == hash
}
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}