Skip to content

Commit 07c0d08

Browse files
Add TestPyPI validation script
New script: tests/test_testpypi.sh - Tests published version from TestPyPI (not local code) - Takes version as argument: ./tests/test_testpypi.sh 0.1.0 - Creates clean venv and installs from TestPyPI - Runs 4 validation tests: 1. Import backend classes 2. Check sigma-cli integration 3. Convert test Sigma rule 4. Validate JSON output structure - Auto cleanup on exit Usage: ./tests/test_testpypi.sh 0.1.0 This validates TestPyPI release before promoting to production PyPI.
1 parent 2ad3537 commit 07c0d08

1 file changed

Lines changed: 160 additions & 0 deletions

File tree

tests/test_testpypi.sh

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#!/bin/bash
2+
# Test script for TestPyPI published version
3+
# This tests the package published to TestPyPI, not local code
4+
set -e
5+
6+
echo "=========================================="
7+
echo "Testing pySigma-backend-sumologic from TestPyPI"
8+
echo "=========================================="
9+
echo ""
10+
11+
# Check if version argument provided
12+
if [ -z "$1" ]; then
13+
echo "Usage: $0 <version>"
14+
echo "Example: $0 0.1.0"
15+
echo ""
16+
echo "This will test version 0.1.0 from TestPyPI"
17+
exit 1
18+
fi
19+
20+
VERSION="$1"
21+
22+
echo "Version to test: $VERSION"
23+
echo ""
24+
25+
# Create temp directory and venv
26+
TEMP_DIR=$(mktemp -d)
27+
cd "$TEMP_DIR"
28+
29+
echo "📁 Created test environment: $TEMP_DIR"
30+
echo ""
31+
32+
# Cleanup function
33+
cleanup() {
34+
echo ""
35+
echo "🧹 Cleaning up..."
36+
cd /
37+
rm -rf "$TEMP_DIR"
38+
echo "✅ Cleanup complete"
39+
}
40+
trap cleanup EXIT
41+
42+
# Create virtual environment
43+
echo "🐍 Creating virtual environment..."
44+
python3 -m venv venv
45+
source venv/bin/activate
46+
echo "✅ Virtual environment created"
47+
echo ""
48+
49+
# Install from TestPyPI
50+
echo "📦 Installing pysigma-backend-sumologic==$VERSION from TestPyPI..."
51+
echo " (Dependencies will be installed from production PyPI)"
52+
pip install --index-url https://test.pypi.org/simple/ \
53+
--extra-index-url https://pypi.org/simple/ \
54+
pysigma-backend-sumologic==$VERSION
55+
56+
if [ $? -ne 0 ]; then
57+
echo "❌ FAIL: Installation failed"
58+
exit 1
59+
fi
60+
echo "✅ Package installed successfully"
61+
echo ""
62+
63+
# Test 1: Import backend classes
64+
echo "🧪 Test 1: Import backend classes..."
65+
python -c "
66+
from sigma.backends.sumologic import SumoLogicCSEBackend, SumoLogicCSERuleBackend
67+
from sigma.pipelines.sumologic import sumologic_cse_pipeline
68+
print('✅ All classes imported successfully')
69+
print(' - SumoLogicCSEBackend')
70+
print(' - SumoLogicCSERuleBackend')
71+
print(' - sumologic_cse_pipeline')
72+
"
73+
74+
if [ $? -ne 0 ]; then
75+
echo "❌ FAIL: Import test failed"
76+
exit 1
77+
fi
78+
echo ""
79+
80+
# Test 2: Check sigma-cli integration
81+
echo "🧪 Test 2: Check sigma-cli availability..."
82+
pip install sigma-cli > /dev/null 2>&1
83+
echo "✅ sigma-cli installed"
84+
echo ""
85+
86+
# Test 3: Create and convert a test rule
87+
echo "🧪 Test 3: Convert a test Sigma rule..."
88+
cat > test_rule.yml << 'EOF'
89+
title: Test Rule for Package Validation
90+
id: 12345678-1234-1234-1234-123456789abc
91+
status: test
92+
description: Simple test rule to validate backend functionality
93+
logsource:
94+
category: process_creation
95+
product: windows
96+
detection:
97+
selection:
98+
CommandLine|contains: 'test.exe'
99+
condition: selection
100+
level: medium
101+
EOF
102+
103+
echo " Created test rule: test_rule.yml"
104+
echo ""
105+
106+
echo " Converting with backend..."
107+
sigma convert -t sumologic-cse-rule -p sumologic_cse test_rule.yml > output.json
108+
109+
if [ $? -ne 0 ]; then
110+
echo "❌ FAIL: Conversion failed"
111+
exit 1
112+
fi
113+
114+
echo "✅ Conversion successful"
115+
echo ""
116+
117+
# Test 4: Validate conversion output
118+
echo "🧪 Test 4: Validate conversion output..."
119+
python -c "
120+
import json
121+
import sys
122+
123+
with open('output.json') as f:
124+
data = json.load(f)
125+
126+
# Check required fields in CSE rule
127+
required_fields = ['name', 'expression', 'enabled']
128+
missing_fields = [field for field in required_fields if field not in data]
129+
130+
if missing_fields:
131+
print(f'❌ FAIL: Missing required fields: {missing_fields}')
132+
sys.exit(1)
133+
134+
print('✅ Output validation passed')
135+
print(f' Rule name: {data[\"name\"]}')
136+
print(f' Expression: {data[\"expression\"][:60]}...')
137+
print(f' Enabled: {data[\"enabled\"]}')
138+
"
139+
140+
if [ $? -ne 0 ]; then
141+
exit 1
142+
fi
143+
echo ""
144+
145+
# Success summary
146+
echo "=========================================="
147+
echo "✅ ALL TESTS PASSED!"
148+
echo "=========================================="
149+
echo ""
150+
echo "Summary:"
151+
echo " ✅ Package installed from TestPyPI"
152+
echo " ✅ Backend classes imported successfully"
153+
echo " ✅ sigma-cli integration works"
154+
echo " ✅ Rule conversion successful"
155+
echo " ✅ Output validation passed"
156+
echo ""
157+
echo "Version $VERSION on TestPyPI is ready for production!"
158+
echo ""
159+
160+
deactivate

0 commit comments

Comments
 (0)