1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-10 12:16:49 +00:00

test: read the page scripts with lxml, not a tag regex

CodeQL flags the <script> regex (py/bad-tag-filter); the HTML parser finds the inline scripts as the new-VM dialog test does.
This commit is contained in:
catborise 2026-10-10 20:55:38 +03:00
parent a57290cdf2
commit 35fea424ee
2 changed files with 4 additions and 4 deletions

View file

@ -3,7 +3,6 @@ its compute; the next poll sends it back so that the rates are averages since
then, without waiting."""
import json
import re
import shutil
import subprocess
import unittest
@ -15,6 +14,7 @@ from django.contrib.auth import get_user_model
from django.core import signing
from django.test import TestCase
from django.urls import reverse
from lxml import html
from instances.models import Instance
from vrtManager.instance import USAGE_MAX_WINDOW
@ -140,7 +140,7 @@ class StatsScriptTestCase(TestDriverVM, TestCase):
return response.content.decode()
def test_the_next_poll_sends_the_previous_sample(self):
script = next(s for s in re.findall(r"<script>(.*?)</script>", self.page(), re.S) if "statsSample" in s)
script = next(s for s in html.fromstring(self.page()).xpath("//script[not(@src)]/text()") if "statsSample" in s)
js = """
const vm = require("vm");
const charts = [], requests = [], handlers = {};