feat(servers): generate rcon_password on server create
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2a440dae45
commit
465a103c3a
2 changed files with 22 additions and 0 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
import secrets
|
||||||
|
|
||||||
from flask import Blueprint, Response, current_app, jsonify, redirect, request
|
from flask import Blueprint, Response, current_app, jsonify, redirect, request
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
@ -90,6 +92,7 @@ def create_server() -> Response:
|
||||||
desired_state="stopped",
|
desired_state="stopped",
|
||||||
actual_state="unknown",
|
actual_state="unknown",
|
||||||
last_error="",
|
last_error="",
|
||||||
|
rcon_password=secrets.token_urlsafe(32),
|
||||||
)
|
)
|
||||||
db.add(server)
|
db.add(server)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -427,6 +427,25 @@ def test_lifecycle_form_creates_queued_job(user_client_with_blueprints) -> None:
|
||||||
assert response.headers["Location"] == f"/servers/{server_id}"
|
assert response.headers["Location"] == f"/servers/{server_id}"
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_server_generates_rcon_password(user_client_with_blueprints) -> None:
|
||||||
|
from sqlalchemy import select
|
||||||
|
|
||||||
|
from l4d2web.models import Server
|
||||||
|
|
||||||
|
client, data = user_client_with_blueprints
|
||||||
|
res = client.post(
|
||||||
|
"/servers",
|
||||||
|
data={"name": "fresh", "blueprint_id": str(data["blueprint_id"])},
|
||||||
|
headers={"X-CSRF-Token": "test-token"},
|
||||||
|
)
|
||||||
|
assert res.status_code in (200, 201, 302)
|
||||||
|
|
||||||
|
with session_scope() as db:
|
||||||
|
row = db.scalar(select(Server).where(Server.name == "fresh"))
|
||||||
|
assert row is not None
|
||||||
|
assert len(row.rcon_password) >= 32
|
||||||
|
|
||||||
|
|
||||||
def test_reset_operation_enqueues_job_and_stops_desired_state(user_client_with_blueprints) -> None:
|
def test_reset_operation_enqueues_job_and_stops_desired_state(user_client_with_blueprints) -> None:
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue