feat: add SQL/SQLite, AppSec, Capstone incident-tracker, Gitea Actions CI and spaced repetition
Test and Lint / quality (push) Successful in 2m13s
Test and Lint / quality (push) Successful in 2m13s
This commit is contained in:
1 parent
011f23e637
commit
33082598fc
19 files changed
+496
-6
No files matched your search
@@ -0,0 +1,40 @@
|
||||
package appsec
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSafeJoinBlocksTraversal(t *testing.T) {
|
||||
base := t.TempDir()
|
||||
got, err := SafeJoin(base, filepath.Join("configs", "app.yaml"))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
want := filepath.Join(base, "configs", "app.yaml")
|
||||
if got != want {
|
||||
t.Fatalf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
if _, err := SafeJoin(base, "../../etc/passwd"); !errors.Is(err, ErrPathTraversal) {
|
||||
t.Fatalf("expected ErrPathTraversal, got %v", err)
|
||||
}
|
||||
if _, err := SafeJoin(base, "/etc/passwd"); !errors.Is(err, ErrPathTraversal) {
|
||||
t.Fatalf("expected ErrPathTraversal for abs path, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedactSecrets(t *testing.T) {
|
||||
line := "auth failed header=Bearer s3cr3tTok3n user=admin password=hunter2 token=abc_123"
|
||||
cleaned := RedactSecrets(line)
|
||||
for _, leaked := range []string{"s3cr3tTok3n", "hunter2", "abc_123"} {
|
||||
if strings.Contains(cleaned, leaked) {
|
||||
t.Errorf("secret %q leaked in %q", leaked, cleaned)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(cleaned, "user=admin") {
|
||||
t.Errorf("non-secret field lost in %q", cleaned)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user