mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-03 08:10:28 +00:00
speedup test runner with disable hasher
This commit is contained in:
parent
ea750c9ec3
commit
a28d03a675
3 changed files with 31 additions and 8 deletions
|
@ -2,14 +2,14 @@ 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
|
||||
cmds:
|
||||
- go install github.com/swaggo/swag/cmd/swag@latest
|
||||
- cd backend && go mod tidy
|
||||
- cd frontend && pnpm install --shamefully-hoist
|
||||
- go install github.com/swaggo/swag/cmd/swag@latest
|
||||
- cd backend && go mod tidy
|
||||
- cd frontend && pnpm install --shamefully-hoist
|
||||
generate:
|
||||
desc: |
|
||||
Generates collateral files from the backend project
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue