a few bits tried to escape, but we caught them
This commit is contained in:
@@ -135,7 +135,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Generate Tag Name
|
- name: Generate Tag Name
|
||||||
id: tag
|
id: tag
|
||||||
run: echo "TAG=v$(date +'%Y%m%d%H%M%S')" >> $GITEA_ENV
|
run: echo "TAG=v$(date +'%Y%d%m%H%M%S')" >> $GITEA_ENV
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
env:
|
env:
|
||||||
@@ -180,6 +180,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
needs: [release]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -192,5 +193,5 @@ jobs:
|
|||||||
docker images --filter "reference=multiarch/qemu-user-static" -q | xargs -r docker rmi
|
docker images --filter "reference=multiarch/qemu-user-static" -q | xargs -r docker rmi
|
||||||
docker images --filter "reference=tonistiigi/binfmt" -q | xargs -r docker rmi
|
docker images --filter "reference=tonistiigi/binfmt" -q | xargs -r docker rmi
|
||||||
docker volume ls --filter "name=buildx" -q | xargs -r docker volume rm
|
docker volume ls --filter "name=buildx" -q | xargs -r docker volume rm
|
||||||
docker images --filter "reference=gitea/runner-images" -q | xargs -r docker rmi
|
#docker images --filter "reference=gitea/runner-images" -q | xargs -r docker rmi
|
||||||
docker volume ls --filter "name=act" -q | xargs -r docker volume rm
|
#docker volume ls --filter "name=act" -q | xargs -r docker volume rm
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
|
||||||
import pytest
|
import pytest
|
||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../app')))
|
from redis import from_url, ConnectionPool, Redis
|
||||||
from redis_config import setup_redis
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def app():
|
def app():
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from config import Config
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_object(Config)
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
REDIS_URL="redis://localhost:6379/0"
|
||||||
|
|
||||||
def test_setup_redis(app):
|
def test_setup_redis(app):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
redis_connection = setup_redis(app)
|
pool = ConnectionPool.from_url(REDIS_URL)
|
||||||
|
redis_connection = Redis(connection_pool=pool)
|
||||||
|
redis_connection.ping()
|
||||||
assert redis_connection is not None
|
assert redis_connection is not None
|
||||||
assert redis_connection.ping() is True
|
assert redis_connection.ping() is True
|
||||||
|
|||||||
@@ -4,28 +4,49 @@ import pytest
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_httpauth import HTTPBasicAuth
|
from flask_httpauth import HTTPBasicAuth
|
||||||
import base64
|
import base64
|
||||||
|
from redis import from_url, ConnectionPool, Redis
|
||||||
|
from flask_limiter import Limiter
|
||||||
|
from flask_limiter.util import get_remote_address
|
||||||
|
from unittest.mock import patch, Mock
|
||||||
|
|
||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../app')))
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../app')))
|
||||||
from config import Config
|
|
||||||
from routes import setup_routes
|
from routes import setup_routes
|
||||||
from redis_config import setup_redis
|
|
||||||
from limiter_config import setup_limiter
|
|
||||||
|
|
||||||
auth = HTTPBasicAuth()
|
auth = HTTPBasicAuth()
|
||||||
|
|
||||||
# Force configuration to use fallback values
|
# Force configuration to use fallback values
|
||||||
class TestConfig(Config):
|
|
||||||
|
class TestConfig():
|
||||||
SECRET_KEY = '28c93e98b2a87e47db16372bdb6e7593fb1addf9ccc10eae562827a7358cab3b'
|
SECRET_KEY = '28c93e98b2a87e47db16372bdb6e7593fb1addf9ccc10eae562827a7358cab3b'
|
||||||
|
|
||||||
# Adding LAPTOP_MAC environment variable
|
REDIS_URL="redis://localhost:6379/0"
|
||||||
os.environ['LAPTOP_MAC'] = '00:00:00:00:00:00'
|
RATE_LIMITS = ["200 per day", "50 per hour"]
|
||||||
os.environ['LAPTOP_IP'] = '192.168.0.0'
|
|
||||||
|
def setup_redis(app):
|
||||||
|
pool = ConnectionPool.from_url(REDIS_URL)
|
||||||
|
redis_connection = Redis(connection_pool=pool)
|
||||||
|
redis_connection.ping()
|
||||||
|
app.logger.info("Connected to Redis")
|
||||||
|
# Return the redis_connection to be used elsewhere
|
||||||
|
return redis_connection
|
||||||
|
|
||||||
|
def setup_limiter(app):
|
||||||
|
|
||||||
|
# Rate limiter setup
|
||||||
|
limiter = Limiter(
|
||||||
|
key_func=get_remote_address,
|
||||||
|
app=app,
|
||||||
|
storage_uri=REDIS_URL,
|
||||||
|
default_limits=RATE_LIMITS
|
||||||
|
)
|
||||||
|
|
||||||
|
return limiter
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def app():
|
def app():
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_object(TestConfig)
|
|
||||||
redis_connection = setup_redis(app)
|
redis_connection = setup_redis(app)
|
||||||
|
app.config.from_object(TestConfig)
|
||||||
setup_routes(setup_limiter(app), app, redis_connection)
|
setup_routes(setup_limiter(app), app, redis_connection)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
@@ -43,7 +64,26 @@ def auth_headers():
|
|||||||
}
|
}
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
|
def mock_subprocess_run(*args, **kwargs):
|
||||||
|
"""Mock function to simulate subprocess.run behavior."""
|
||||||
|
class MockCompletedProcess:
|
||||||
|
def __init__(self, returncode=0, stdout='', stderr=''):
|
||||||
|
self.returncode = returncode
|
||||||
|
self.stdout = stdout
|
||||||
|
self.stderr = stderr
|
||||||
|
|
||||||
|
if 'ping' in args[0]:
|
||||||
|
if '192.168.0.0' in args[0]:
|
||||||
|
# Simulate unreachable IP
|
||||||
|
return MockCompletedProcess(returncode=1, stderr='Unreachable')
|
||||||
|
else:
|
||||||
|
# Simulate reachable IP
|
||||||
|
return MockCompletedProcess(returncode=0, stdout='Ping successful')
|
||||||
|
return MockCompletedProcess()
|
||||||
|
|
||||||
def test_wol_valid_device(client, auth_headers):
|
def test_wol_valid_device(client, auth_headers):
|
||||||
|
with patch.dict(os.environ, {'LAPTOP_MAC': '00:00:00:00:00:00', 'LAPTOP_IP': '192.168.0.1'}):
|
||||||
|
with patch('subprocess.run', mock_subprocess_run):
|
||||||
response = client.get('/wol/laptop?key=28c93e98b2a87e47db16372bdb6e7593fb1addf9ccc10eae562827a7358cab3b', headers=auth_headers)
|
response = client.get('/wol/laptop?key=28c93e98b2a87e47db16372bdb6e7593fb1addf9ccc10eae562827a7358cab3b', headers=auth_headers)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user