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: env:
HBOX_STORAGE_SQLITE_URL: .data/homebox.db?_fk=1 HBOX_STORAGE_SQLITE_URL: .data/homebox.db?_fk=1
UNSAFE_DISABLE_PASSWORD_PROJECTION: "yes_i_am_sure"
tasks: tasks:
setup: setup:
desc: Install dependencies desc: Install dependencies

View file

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

View file

@ -1,13 +1,37 @@
package hasher 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) { func HashPassword(password string) (string, error) {
if !enabled {
return password, nil
}
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return string(bytes), err return string(bytes), err
} }
func CheckPasswordHash(password, hash string) bool { func CheckPasswordHash(password, hash string) bool {
if !enabled {
return password == hash
}
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil return err == nil
} }