67f2f27cf8
- Implemented ImportSuccessModal to replace alert with a modal displaying import results and guidance. - Updated ImportCaddy to show the new modal with import summary and navigation options. - Created CertificateStatusCard to display certificate provisioning status on the dashboard. - Enhanced API types and hooks to support new features. - Added unit tests for ImportSuccessModal and CertificateStatusCard components. - Updated QA report to reflect the status of the new features and tests.
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package cerberus_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/Wikid82/charon/backend/internal/cerberus"
|
|
"github.com/Wikid82/charon/backend/internal/config"
|
|
"github.com/Wikid82/charon/backend/internal/models"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func setupTestDB(t *testing.T) *gorm.DB {
|
|
// Use a unique in-memory database per test run to avoid shared state.
|
|
dsn := fmt.Sprintf("file:cerberus_test_%d?mode=memory&cache=shared", time.Now().UnixNano())
|
|
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{})
|
|
require.NoError(t, err)
|
|
// migrate only the Setting model used by Cerberus
|
|
require.NoError(t, db.AutoMigrate(&models.Setting{}))
|
|
return db
|
|
}
|
|
|
|
func TestCerberus_IsEnabled_ConfigTrue(t *testing.T) {
|
|
db := setupTestDB(t)
|
|
cfg := config.SecurityConfig{CerberusEnabled: true}
|
|
cerb := cerberus.New(cfg, db)
|
|
require.True(t, cerb.IsEnabled())
|
|
}
|
|
|
|
func TestCerberus_IsEnabled_DBSetting(t *testing.T) {
|
|
db := setupTestDB(t)
|
|
// We're storing 'feature.cerberus.enabled' key
|
|
db.Create(&models.Setting{Key: "feature.cerberus.enabled", Value: "true"})
|
|
cfg := config.SecurityConfig{CerberusEnabled: false}
|
|
cerb := cerberus.New(cfg, db)
|
|
require.True(t, cerb.IsEnabled())
|
|
}
|
|
|
|
func TestCerberus_IsEnabled_Disabled(t *testing.T) {
|
|
db := setupTestDB(t)
|
|
// Per Optional Features spec: when no DB setting exists and no config modes are enabled,
|
|
// Cerberus defaults to true (enabled). To test disabled state, we must set DB flag to false.
|
|
db.Create(&models.Setting{Key: "feature.cerberus.enabled", Value: "false"})
|
|
cfg := config.SecurityConfig{CerberusEnabled: false}
|
|
cerb := cerberus.New(cfg, db)
|
|
t.Logf("cfg: %+v", cfg)
|
|
t.Logf("IsEnabled() -> %v", cerb.IsEnabled())
|
|
require.False(t, cerb.IsEnabled())
|
|
}
|