Remove runtime nil checks for always-initialized components
Since signing_key is now required at config load time, sessMgr, encGen, and signer are always initialized. Remove unnecessary nil checks that were runtime failure paths that can no longer be reached. - handlers.go: Remove conditional init, always create sessMgr/encGen - auth.go: Remove nil checks for sessMgr - imageenc.go: Remove nil check for encGen - service.go: Require signing_key in NewService, remove signer nil checks - Update tests to provide signing_key
This commit is contained in:
@@ -15,13 +15,6 @@ import (
|
||||
// HandleRoot serves the login page or generator page based on authentication state.
|
||||
func (s *Handlers) HandleRoot() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// Check if signing key is configured
|
||||
if s.sessMgr == nil {
|
||||
s.respondError(w, "signing key not configured", http.StatusServiceUnavailable)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if r.Method == http.MethodPost {
|
||||
s.handleLoginPost(w, r)
|
||||
|
||||
@@ -75,10 +68,7 @@ func (s *Handlers) handleLoginPost(w http.ResponseWriter, r *http.Request) {
|
||||
// HandleLogout clears the session and redirects to login.
|
||||
func (s *Handlers) HandleLogout() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if s.sessMgr != nil {
|
||||
s.sessMgr.ClearSession(w)
|
||||
}
|
||||
|
||||
s.sessMgr.ClearSession(w)
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
@@ -87,7 +77,7 @@ func (s *Handlers) HandleLogout() http.HandlerFunc {
|
||||
func (s *Handlers) HandleGenerateURL() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// Check authentication
|
||||
if s.sessMgr == nil || !s.sessMgr.IsAuthenticated(r) {
|
||||
if !s.sessMgr.IsAuthenticated(r) {
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user