chore: Add comprehensive tests for ImportHandler and ManualChallengeHandler

- Implement tests for ImportHandler's Cancel and Commit methods to handle missing and invalid session UUIDs.
- Add tests for ManualChallengeHandler to cover scenarios such as empty challenge ID, provider internal errors, unauthorized access, and challenge not found.
- Enhance error handling in tests to ensure proper responses for various edge cases.
This commit is contained in:
GitHub Actions
2026-01-13 20:20:17 +00:00
parent 4907efc876
commit 50798abc12
2 changed files with 1078 additions and 0 deletions

View File

@@ -897,3 +897,66 @@ func TestImportHandler_UploadMulti(t *testing.T) {
assert.Contains(t, resp["error"], "empty")
})
}
// Additional tests for comprehensive coverage
func TestImportHandler_Cancel_MissingSessionUUID(t *testing.T) {
gin.SetMode(gin.TestMode)
db := setupImportTestDB(t)
handler := handlers.NewImportHandler(db, "echo", "/tmp", "")
router := gin.New()
router.DELETE("/import/cancel", handler.Cancel)
// Missing session_uuid parameter
w := httptest.NewRecorder()
req, _ := http.NewRequest("DELETE", "/import/cancel", http.NoBody)
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusBadRequest, w.Code)
var resp map[string]any
_ = json.Unmarshal(w.Body.Bytes(), &resp)
assert.Equal(t, "session_uuid required", resp["error"])
}
func TestImportHandler_Cancel_InvalidSessionUUID(t *testing.T) {
gin.SetMode(gin.TestMode)
db := setupImportTestDB(t)
handler := handlers.NewImportHandler(db, "echo", "/tmp", "")
router := gin.New()
router.DELETE("/import/cancel", handler.Cancel)
// Test "." which becomes empty after filepath.Base processing
w := httptest.NewRecorder()
req, _ := http.NewRequest("DELETE", "/import/cancel?session_uuid=.", http.NoBody)
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusBadRequest, w.Code)
var resp map[string]any
_ = json.Unmarshal(w.Body.Bytes(), &resp)
assert.Equal(t, "invalid session_uuid", resp["error"])
}
func TestImportHandler_Commit_InvalidSessionUUID(t *testing.T) {
gin.SetMode(gin.TestMode)
db := setupImportTestDB(t)
handler := handlers.NewImportHandler(db, "echo", "/tmp", "")
router := gin.New()
router.POST("/import/commit", handler.Commit)
// Test "." which becomes empty after filepath.Base processing
payload := map[string]any{
"session_uuid": ".",
"resolutions": map[string]string{},
}
body, _ := json.Marshal(payload)
w := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/import/commit", bytes.NewBuffer(body))
req.Header.Set("Content-Type", "application/json")
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusBadRequest, w.Code)
var resp map[string]any
_ = json.Unmarshal(w.Body.Bytes(), &resp)
assert.Equal(t, "invalid session_uuid", resp["error"])
}

File diff suppressed because it is too large Load Diff