feat: add integration tests for CrowdSec preset pull and apply

- Introduced `crowdsec_integration_test.go` to validate the integration of the CrowdSec preset pull and apply functionality.
- Updated `RealCommandExecutor` to return combined output for command execution.
- Enhanced `CrowdsecHandler` to map errors to appropriate HTTP status codes, including handling timeouts.
- Added tests for timeout scenarios in `crowdsec_presets_handler_test.go`.
- Improved `HubService` to support configurable pull and apply timeouts via environment variables.
- Implemented fallback logic for fetching hub index from a default URL if the primary fails.
- Updated documentation to reflect changes in preset handling and cscli availability.
- Refactored frontend tests to utilize a new test query client for better state management.
- Added a new integration script `crowdsec_integration.sh` for automated testing of the CrowdSec integration.
This commit is contained in:
GitHub Actions
2025-12-09 00:23:10 +00:00
parent 0acb46bc86
commit a3237fe32c
16 changed files with 412 additions and 56 deletions
@@ -2,11 +2,12 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MemoryRouter } from 'react-router-dom'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { QueryClientProvider } from '@tanstack/react-query'
import ImportCrowdSec from '../ImportCrowdSec'
import * as crowdsecApi from '../../api/crowdsec'
import * as backupsApi from '../../api/backups'
import { toast } from 'react-hot-toast'
import { createTestQueryClient } from '../../test/createTestQueryClient'
vi.mock('../../api/crowdsec')
vi.mock('../../api/backups')
@@ -27,7 +28,7 @@ describe('ImportCrowdSec', () => {
})
const renderPage = () => {
const qc = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } })
const qc = createTestQueryClient()
return render(
<QueryClientProvider client={qc}>
<MemoryRouter>
@@ -49,11 +50,12 @@ describe('ImportCrowdSec', () => {
const fileInput = screen.getByTestId('crowdsec-import-file') as HTMLInputElement
const file = new File(['config'], 'config.tar.gz', { type: 'application/gzip' })
const user = userEvent.setup()
await userEvent.upload(fileInput, file)
await user.upload(fileInput, file)
const importButton = screen.getByRole('button', { name: /Import/i })
await userEvent.click(importButton)
await user.click(importButton)
await waitFor(() => {
expect(backupsApi.createBackup).toHaveBeenCalled()