- Implement tests for AuthMiddleware to handle cookie and token authentication. - Create tests for the Importer and Manager in the Caddy package. - Enhance AuthService tests with password change and token validation scenarios. - Introduce tests for CertificateService to validate certificate listing and expiry. - Expand LogService tests to cover log querying and pagination. - Add NotificationService tests for creating, listing, and marking notifications as read. - Implement ProxyHostService tests for CRUD operations and unique domain validation. - Create RemoteServerService tests for CRUD operations. - Add UpdateService tests to mock GitHub API responses for version checking. - Introduce UptimeService tests to check host availability and notifications for down hosts.
41 lines
1003 B
Go
41 lines
1003 B
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/Wikid82/CaddyProxyManagerPlus/backend/internal/services"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCertificateHandler_List(t *testing.T) {
|
|
// Setup temp dir
|
|
tmpDir := t.TempDir()
|
|
caddyDir := filepath.Join(tmpDir, "caddy", "certificates", "acme-v02.api.letsencrypt.org-directory")
|
|
err := os.MkdirAll(caddyDir, 0755)
|
|
require.NoError(t, err)
|
|
|
|
service := services.NewCertificateService(tmpDir)
|
|
handler := NewCertificateHandler(service)
|
|
|
|
gin.SetMode(gin.TestMode)
|
|
r := gin.New()
|
|
r.GET("/certificates", handler.List)
|
|
|
|
req, _ := http.NewRequest("GET", "/certificates", nil)
|
|
w := httptest.NewRecorder()
|
|
r.ServeHTTP(w, req)
|
|
|
|
assert.Equal(t, http.StatusOK, w.Code)
|
|
var certs []services.CertificateInfo
|
|
err = json.Unmarshal(w.Body.Bytes(), &certs)
|
|
assert.NoError(t, err)
|
|
assert.Empty(t, certs)
|
|
}
|