|
| 1 | +# Test GitLab CI configuration for Socket Security Dashboard integration |
| 2 | +# Rename to .gitlab-ci.yml to activate, or create a test pipeline in GitLab UI |
| 3 | + |
| 4 | +stages: |
| 5 | + - test |
| 6 | + - security |
| 7 | + |
| 8 | +# Test 1: Install from branch and generate report |
| 9 | +socket_security_test: |
| 10 | + stage: security |
| 11 | + image: python:3.11 |
| 12 | + before_script: |
| 13 | + - pip install --upgrade pip |
| 14 | + # Install directly from the git branch |
| 15 | + - pip install git+https://github.com/SocketDev/socket-python-cli.git@mucha-dev-gitlab-security-output |
| 16 | + script: |
| 17 | + - echo "Testing GitLab Security Dashboard integration..." |
| 18 | + - socketcli --version |
| 19 | + - socketcli --help | grep "gitlab-security" |
| 20 | + - | |
| 21 | + socketcli \ |
| 22 | + --api-token $SOCKET_API_TOKEN \ |
| 23 | + --repo socket-python-cli \ |
| 24 | + --target-path . \ |
| 25 | + --enable-gitlab-security \ |
| 26 | + --gitlab-security-file gl-dependency-scanning-report.json |
| 27 | + - echo "Verifying report was generated..." |
| 28 | + - ls -lh gl-dependency-scanning-report.json |
| 29 | + - echo "Report contents preview:" |
| 30 | + - cat gl-dependency-scanning-report.json | head -50 |
| 31 | + artifacts: |
| 32 | + reports: |
| 33 | + dependency_scanning: gl-dependency-scanning-report.json |
| 34 | + paths: |
| 35 | + - gl-dependency-scanning-report.json |
| 36 | + expire_in: 1 week |
| 37 | + only: |
| 38 | + - branches |
| 39 | + allow_failure: false |
| 40 | + |
| 41 | +# Test 2: Validate report schema |
| 42 | +validate_gitlab_report: |
| 43 | + stage: test |
| 44 | + image: python:3.11 |
| 45 | + dependencies: |
| 46 | + - socket_security_test |
| 47 | + script: |
| 48 | + - echo "Validating GitLab Security report structure..." |
| 49 | + - | |
| 50 | + python3 << 'VALIDATE' |
| 51 | + import json |
| 52 | + import sys |
| 53 | +
|
| 54 | + with open('gl-dependency-scanning-report.json') as f: |
| 55 | + report = json.load(f) |
| 56 | +
|
| 57 | + # Validate required fields |
| 58 | + assert 'version' in report, "Missing 'version' field" |
| 59 | + assert 'scan' in report, "Missing 'scan' field" |
| 60 | + assert 'vulnerabilities' in report, "Missing 'vulnerabilities' field" |
| 61 | +
|
| 62 | + # Validate scan structure |
| 63 | + scan = report['scan'] |
| 64 | + assert scan['type'] == 'dependency_scanning', f"Invalid scan type: {scan['type']}" |
| 65 | + assert 'analyzer' in scan, "Missing 'analyzer' in scan" |
| 66 | + assert 'scanner' in scan, "Missing 'scanner' in scan" |
| 67 | + assert scan['analyzer']['id'] == 'socket-security', "Invalid analyzer ID" |
| 68 | + assert scan['scanner']['id'] == 'socket-cli', "Invalid scanner ID" |
| 69 | +
|
| 70 | + print(f"✓ Report structure is valid") |
| 71 | + print(f"✓ Schema version: {report['version']}") |
| 72 | + print(f"✓ Scan type: {scan['type']}") |
| 73 | + print(f"✓ Vulnerabilities found: {len(report['vulnerabilities'])}") |
| 74 | +
|
| 75 | + if report['vulnerabilities']: |
| 76 | + print(f"\nFirst 3 vulnerabilities:") |
| 77 | + for i, vuln in enumerate(report['vulnerabilities'][:3], 1): |
| 78 | + print(f" {i}. {vuln['severity']}: {vuln['name']}") |
| 79 | + print(f" Package: {vuln['location']['dependency']['package']['name']}@{vuln['location']['dependency']['version']}") |
| 80 | +
|
| 81 | + print("\n✅ GitLab report validation successful!") |
| 82 | + VALIDATE |
| 83 | + only: |
| 84 | + - branches |
| 85 | + |
| 86 | +# Test 3: Multiple formats simultaneously |
| 87 | +test_multiple_formats: |
| 88 | + stage: security |
| 89 | + image: python:3.11 |
| 90 | + before_script: |
| 91 | + - pip install git+https://github.com/SocketDev/socket-python-cli.git@mucha-dev-gitlab-security-output |
| 92 | + script: |
| 93 | + - echo "Testing multiple output formats..." |
| 94 | + - | |
| 95 | + socketcli \ |
| 96 | + --api-token $SOCKET_API_TOKEN \ |
| 97 | + --repo socket-python-cli \ |
| 98 | + --target-path . \ |
| 99 | + --enable-json \ |
| 100 | + --enable-gitlab-security \ |
| 101 | + --gitlab-security-file reports/gitlab-security.json > json-output.txt 2>&1 |
| 102 | + - echo "Verifying both formats were generated..." |
| 103 | + - ls -lh reports/gitlab-security.json |
| 104 | + - grep -q "vulnerabilities" reports/gitlab-security.json && echo "✓ GitLab report contains vulnerabilities field" |
| 105 | + - grep -q "scan_failed" json-output.txt && echo "✓ JSON output was generated" |
| 106 | + artifacts: |
| 107 | + paths: |
| 108 | + - reports/gitlab-security.json |
| 109 | + - json-output.txt |
| 110 | + expire_in: 1 day |
| 111 | + only: |
| 112 | + - branches |
| 113 | + allow_failure: true |
0 commit comments