mirror of
https://github.com/lightbroker/llmsecops-research.git
synced 2026-02-12 14:42:48 +00:00
fix garak config paths
This commit is contained in:
49
.github/scripts/test_api.sh
vendored
49
.github/scripts/test_api.sh
vendored
@@ -1,18 +1,47 @@
|
||||
#!/bin/bash
|
||||
# Local-only usage: ./test_api.sh --local
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
cd $GITHUB_WORKSPACE
|
||||
# Parse command line arguments
|
||||
LOCAL=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--local)
|
||||
LOCAL=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$LOCAL" = false ]; then
|
||||
cd $GITHUB_WORKSPACE
|
||||
fi
|
||||
|
||||
echo "Making API request..."
|
||||
curl -X POST -i http://localhost:9999/api/conversations \
|
||||
-d '{ "prompt": "describe a random planet in our solar system in 10 words or less" }' \
|
||||
-H "Content-Type: application/json" > logs/test_request.log 2>&1
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Test API request failed"
|
||||
cat logs/test_request.log
|
||||
# Wait for server to start and verify it's running
|
||||
max_retries=30
|
||||
retry_count=0
|
||||
server_ready=false
|
||||
|
||||
while [ $retry_count -lt $max_retries ] && [ "$server_ready" = false ]; do
|
||||
echo "Waiting for server to start (attempt $retry_count/$max_retries)..."
|
||||
if curl -s -o /dev/null -w "%{http_code}" localhost:9999 > /dev/null 2>&1; then
|
||||
server_ready=true
|
||||
echo "Server is running"
|
||||
else
|
||||
sleep 2
|
||||
retry_count=$((retry_count + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$server_ready" = false ]; then
|
||||
echo "::error::Server failed to start after $max_retries attempts"
|
||||
exit 1
|
||||
else
|
||||
echo "Test API request succeeded"
|
||||
cat logs/test_request.log
|
||||
fi
|
||||
41
.github/workflows/llmsecops-cicd.yml
vendored
41
.github/workflows/llmsecops-cicd.yml
vendored
@@ -15,49 +15,18 @@ jobs:
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: 'set up Garak'
|
||||
run: |
|
||||
pip install garak
|
||||
continue-on-error: false
|
||||
|
||||
- name: 'start HTTP server'
|
||||
- name: 'start and test HTTP server'
|
||||
id: start_server
|
||||
run: |
|
||||
nohup ./run.sh > server.log 2>&1 &
|
||||
server_pid=$!
|
||||
# echo "Server PID: $server_pid"
|
||||
# echo "server_pid=$server_pid" >> $GITHUB_ENV
|
||||
echo "Server PID: $server_pid"
|
||||
echo "server_pid=$server_pid" >> $GITHUB_ENV
|
||||
${{ github.workspace }}/.github/scripts/test_api.sh
|
||||
|
||||
# # Wait for server to start and verify it's running
|
||||
# max_retries=30
|
||||
# retry_count=0
|
||||
# server_ready=false
|
||||
|
||||
# while [ $retry_count -lt $max_retries ] && [ "$server_ready" = false ]; do
|
||||
# echo "Waiting for server to start (attempt $retry_count/$max_retries)..."
|
||||
# if curl -s -o /dev/null -w "%{http_code}" localhost:9999 > /dev/null 2>&1; then
|
||||
# server_ready=true
|
||||
# echo "Server is running"
|
||||
# else
|
||||
# sleep 2
|
||||
# retry_count=$((retry_count + 1))
|
||||
# fi
|
||||
# done
|
||||
|
||||
# if [ "$server_ready" = false ]; then
|
||||
# echo "::error::Server failed to start after $max_retries attempts"
|
||||
# echo "=== Server Log (last 50 lines) ==="
|
||||
# tail -n 50 server.log || true
|
||||
# exit 1
|
||||
# fi
|
||||
|
||||
- name: 'Test server with curl and run garak'
|
||||
- name: 'run garak tests'
|
||||
id: run_tests
|
||||
run: |
|
||||
# Test curl with detailed error reporting
|
||||
curl_output=$(curl -X POST -i localhost:9999/api/conversations -d '{ "prompt": "describe a random planet in our solar system in 10 words or less" }' --connect-timeout 10 -v 2>&1) || true
|
||||
echo "$curl_output"
|
||||
|
||||
garak -v \
|
||||
--config ${{ github.workspace }}/tests/security/garak.config.yml \
|
||||
--generator_option_file ${{ github.workspace }}/tests/security/garak.rest.llm-rag.json \
|
||||
|
||||
3
run.sh
3
run.sh
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Local-only usage: ./script.sh --local
|
||||
# Local-only usage: ./run.sh --local
|
||||
|
||||
# Parse command line arguments
|
||||
LOCAL=false
|
||||
|
||||
@@ -14,6 +14,7 @@ class HttpApiController:
|
||||
|
||||
def register_routes(self):
|
||||
"""Register all API routes"""
|
||||
self.routes[('GET', '/')] = self.health_check
|
||||
self.routes[('POST', '/api/conversations')] = self.handle_conversations
|
||||
self.routes[('POST', '/api/rag_conversations')] = self.handle_conversations_with_rag
|
||||
|
||||
@@ -40,6 +41,12 @@ class HttpApiController:
|
||||
response_body = json.dumps({'response': str(data)}).encode('utf-8')
|
||||
return response_body
|
||||
|
||||
def health_check(self, env, start_response):
|
||||
response_body = self.format_response({ "success": True })
|
||||
response_headers = [('Content-Type', 'application/json'), ('Content-Length', str(len(response_body)))]
|
||||
start_response('200 OK', response_headers)
|
||||
return [response_body]
|
||||
|
||||
def handle_conversations(self, env, start_response):
|
||||
"""Handle POST requests to /api/conversations"""
|
||||
try:
|
||||
@@ -110,9 +117,6 @@ class HttpApiController:
|
||||
method = env.get('REQUEST_METHOD').upper()
|
||||
path = env.get('PATH_INFO')
|
||||
|
||||
if method != 'POST':
|
||||
return self.__http_415_notsupported(env, start_response)
|
||||
|
||||
try:
|
||||
handler = self.routes.get((method, path), self.__http_200_ok)
|
||||
return handler(env, start_response)
|
||||
|
||||
Reference in New Issue
Block a user