refactor: remove dead code across server, templ pages, and client modules
Deadcode-verified removals (RTA reachability from main, cross-checked with -test and textual xrefs): Go server: - whole files: middleware/transaction.go, middleware/error_handler.go, middleware/password_validator.go (live registration machinery kept), handlers/sync.go, sync/offline.go - unrouted endpoints: auth UpdateUsername/UpdateEmail, timezone settings handler, OPDS RegisterOPDS, Kobo LibrarySync handler, ReaderHandler.ShowReader, JSON-data twins on collections/library - duplicate book-matching handlers (book_matching.go Handler twins, matching.go MatchingHandler twins), superseded helpers (router.parseUUID, handlers.ValidateDeviceToken, normalizePath, userExists, generateLockID) Templ/client: - never-routed pages: api_explorer.templ, queue.templ and their client modules api-explorer.ts, api-explorer-docs.ts, queue.ts - fully orphaned wrapper modules events.ts, dom.ts - broken clearSyncQueue (called a nonexistent endpoint) and the hidden, never-populated sync-queue section on the devices page - 166+ unused exports demoted to private (knip-verified); ~85 truly dead declarations removed via tsc noUnusedLocals fixpoint - stale 'interactive API Explorer' claims dropped from docs The docs drift-gate package (internal/docs), templ-bound modules (dashboard, stats, header, index, login, profile*, bookshelf, collections, toast-error), sqlc-generated code, and web/static are intentionally untouched.
This commit is contained in:
1 parent
8733e83f1f
commit
8631aa00bf
107 files changed
+689
-3443
No files matched your search
@@ -7,127 +7,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPasswordValidator_ValidatePassword(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
password string
|
||||
wantValid bool
|
||||
}{
|
||||
{
|
||||
name: "valid password with all requirements",
|
||||
password: "Test@Pass123!",
|
||||
wantValid: true,
|
||||
},
|
||||
{
|
||||
name: "valid password with special chars",
|
||||
password: "MyP@ssw0rd#2024",
|
||||
wantValid: true,
|
||||
},
|
||||
{
|
||||
name: "too short",
|
||||
password: "Test1!",
|
||||
wantValid: false,
|
||||
},
|
||||
{
|
||||
name: "no uppercase",
|
||||
password: "test@pass123!",
|
||||
wantValid: false,
|
||||
},
|
||||
{
|
||||
name: "no lowercase",
|
||||
password: "TEST@PASS123!",
|
||||
wantValid: false,
|
||||
},
|
||||
{
|
||||
name: "no number",
|
||||
password: "Test@Password!",
|
||||
wantValid: false,
|
||||
},
|
||||
{
|
||||
name: "no special character",
|
||||
password: "TestPassword123",
|
||||
wantValid: false,
|
||||
},
|
||||
{
|
||||
name: "empty string",
|
||||
password: "",
|
||||
wantValid: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := ValidatePassword(tt.password)
|
||||
if tt.wantValid {
|
||||
assert.NoError(t, err)
|
||||
} else {
|
||||
assert.Error(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPasswordValidator_ErrorMessages(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
password string
|
||||
expectedInError string
|
||||
}{
|
||||
{
|
||||
name: "too short error",
|
||||
password: "Short1!",
|
||||
expectedInError: "at least 8 characters",
|
||||
},
|
||||
{
|
||||
name: "no uppercase error",
|
||||
password: "alllower123!",
|
||||
expectedInError: "uppercase letter",
|
||||
},
|
||||
{
|
||||
name: "no lowercase error",
|
||||
password: "ALLUPPER123!",
|
||||
expectedInError: "lowercase letter",
|
||||
},
|
||||
{
|
||||
name: "no number error",
|
||||
password: "NoNumbers!",
|
||||
expectedInError: "number",
|
||||
},
|
||||
{
|
||||
name: "no special char error",
|
||||
password: "NoSpecialChars123",
|
||||
expectedInError: "special character",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := ValidatePassword(tt.password)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), tt.expectedInError)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPasswordRequirements(t *testing.T) {
|
||||
requirements := GetPasswordRequirements()
|
||||
|
||||
assert.NotEmpty(t, requirements)
|
||||
assert.Greater(t, len(requirements), 3)
|
||||
|
||||
// Check for common requirements
|
||||
requirementText := ""
|
||||
for _, req := range requirements {
|
||||
requirementText += req + " "
|
||||
}
|
||||
|
||||
assert.Contains(t, requirementText, "8")
|
||||
assert.Contains(t, requirementText, "uppercase")
|
||||
assert.Contains(t, requirementText, "lowercase")
|
||||
assert.Contains(t, requirementText, "number")
|
||||
assert.Contains(t, requirementText, "special")
|
||||
}
|
||||
|
||||
func TestLoginAttemptTracker_RecordFailedAttempt(t *testing.T) {
|
||||
tracker := NewLoginAttemptTracker(3, 5*time.Minute, 5*time.Minute)
|
||||
|
||||
@@ -231,13 +110,6 @@ func TestDeviceRateLimiter_CheckRateLimit(t *testing.T) {
|
||||
// Get remaining requests
|
||||
remaining := limiter.GetRemainingRequests(deviceID, requestType, config)
|
||||
assert.Equal(t, 0, remaining)
|
||||
|
||||
// Reset and verify
|
||||
limiter.Reset(deviceID)
|
||||
|
||||
// Should be allowed again
|
||||
allowed = limiter.CheckRateLimit(deviceID, requestType, config)
|
||||
assert.True(t, allowed, "Request after reset should be allowed")
|
||||
}
|
||||
|
||||
func TestDeviceRateLimiter_DifferentDevices(t *testing.T) {
|
||||
@@ -285,34 +157,12 @@ func TestDeviceRateLimiter_GetRemainingRequests(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewRateLimiter(t *testing.T) {
|
||||
config := DefaultRateLimiterConfig()
|
||||
config := RateLimiterConfig{
|
||||
Enabled: true,
|
||||
RequestsPerMinute: 60,
|
||||
CleanupInterval: time.Minute,
|
||||
}
|
||||
limiter := NewRateLimiter(config)
|
||||
|
||||
assert.NotNil(t, limiter)
|
||||
}
|
||||
|
||||
func TestHTTPError_Error(t *testing.T) {
|
||||
err := NewHTTPError(404, "Not Found", nil)
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, 404, err.Code)
|
||||
assert.Equal(t, "Not Found", err.Message)
|
||||
}
|
||||
|
||||
func TestHTTPError_ErrorWithInternal(t *testing.T) {
|
||||
internalErr := assert.AnError
|
||||
err := NewHTTPError(500, "Internal Error", internalErr)
|
||||
|
||||
assert.Equal(t, "Internal Error: assert.AnError general error for testing", err.Error())
|
||||
assert.Equal(t, 500, err.Code)
|
||||
assert.Equal(t, "Internal Error", err.Message)
|
||||
assert.Equal(t, internalErr, err.Err)
|
||||
}
|
||||
|
||||
func TestNewHTTPError(t *testing.T) {
|
||||
err := NewHTTPError(404, "Not Found", nil)
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, 404, err.Code)
|
||||
assert.Equal(t, "Not Found", err.Message)
|
||||
}
|
||||
Reference in new issue
Block a user