mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-29 03:50:18 +00:00
- Replace barrel import in AuditLogPanel.tsx to fix ad-blocker crash - Remove all Enterprise/Pro badges from nav and feature headers - Simplify upgrade CTAs to clean 'Upgrade to Pro' links - Update docs: PULSE_PRO.md, API.md, README.md, SECURITY.md - Align terminology: single Pro tier, no separate Enterprise tier Also includes prior refactoring: - Move auth package to pkg/auth for enterprise reuse - Export server functions for testability - Stabilize CLI tests
83 lines
1.9 KiB
Go
83 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/pkg/auth"
|
|
)
|
|
|
|
func TestRunUsage(t *testing.T) {
|
|
var out bytes.Buffer
|
|
code := run([]string{"hashpw"}, &out)
|
|
if code != 1 {
|
|
t.Fatalf("expected exit code 1, got %d", code)
|
|
}
|
|
if !strings.Contains(out.String(), "Usage: hashpw <password>") {
|
|
t.Fatalf("expected usage output, got %q", out.String())
|
|
}
|
|
}
|
|
|
|
func TestRunHashesPassword(t *testing.T) {
|
|
var out bytes.Buffer
|
|
code := run([]string{"hashpw", "this-is-a-test-password"}, &out)
|
|
if code != 0 {
|
|
t.Fatalf("expected exit code 0, got %d (output: %q)", code, out.String())
|
|
}
|
|
|
|
hash := strings.TrimSpace(out.String())
|
|
if hash == "" {
|
|
t.Fatalf("expected hash output, got empty string")
|
|
}
|
|
if !auth.CheckPasswordHash("this-is-a-test-password", hash) {
|
|
t.Fatalf("expected hash to validate against original password")
|
|
}
|
|
}
|
|
|
|
func TestRunError(t *testing.T) {
|
|
oldHashPassword := hashPassword
|
|
defer func() { hashPassword = oldHashPassword }()
|
|
|
|
hashPassword = func(password string) (string, error) {
|
|
return "", errors.New("forced error")
|
|
}
|
|
|
|
var out bytes.Buffer
|
|
code := run([]string{"hashpw", "password"}, &out)
|
|
if code != 1 {
|
|
t.Fatalf("expected exit code 1, got %d", code)
|
|
}
|
|
if !strings.Contains(out.String(), "Error: forced error") {
|
|
t.Fatalf("expected error message, got %q", out.String())
|
|
}
|
|
}
|
|
|
|
func TestMain(t *testing.T) {
|
|
oldOsExit := osExit
|
|
oldOsArgs := osArgs
|
|
oldStdout := stdout
|
|
defer func() {
|
|
osExit = oldOsExit
|
|
osArgs = oldOsArgs
|
|
stdout = oldStdout
|
|
}()
|
|
|
|
var exitCode int
|
|
osExit = func(code int) {
|
|
exitCode = code
|
|
}
|
|
osArgs = []string{"hashpw", "test-password"}
|
|
var out bytes.Buffer
|
|
stdout = &out
|
|
|
|
main()
|
|
|
|
if exitCode != 0 {
|
|
t.Fatalf("expected exit code 0, got %d", exitCode)
|
|
}
|
|
if !auth.CheckPasswordHash("test-password", strings.TrimSpace(out.String())) {
|
|
t.Fatalf("expected valid hash in output")
|
|
}
|
|
}
|