mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 04:36:48 +00:00
fix: serve compute JSON endpoints as application/json, build chipset list safely
compute_graph (text/javascript) and the machine type, disk bus, video model and domain capability views (text/html) return JSON; send it as application/json. create_instance_w1.html builds the chipset <option> elements with .val().text() instead of string concatenation.
This commit is contained in:
parent
d250915e17
commit
e76149c71a
3 changed files with 26 additions and 14 deletions
|
|
@ -106,12 +106,9 @@
|
|||
$("#select_chipset").find('option').remove();
|
||||
$("#select_archs").val(arch);
|
||||
$.each(data['machines'], function(i, item) {
|
||||
if (item == '{{ default_machine }}') {
|
||||
var selected = 'selected';
|
||||
}else{
|
||||
var selected = '';
|
||||
}
|
||||
$("#select_chipset").append('<option value="' + item + '"' + selected +'>' + item + '</option>');
|
||||
$("#select_chipset").append(
|
||||
$("<option>").val(item).text(item).prop("selected", item == '{{ default_machine }}')
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,20 @@ class JsonEndpointContentTypeTestCase(TestCase):
|
|||
self.client.get(reverse("ds_openstack_metadata", args=["latest"]))
|
||||
)
|
||||
|
||||
def test_compute_json_endpoints_are_json(self):
|
||||
urls = [
|
||||
reverse("compute_graph", args=[self.compute.id]),
|
||||
reverse("machines", args=[self.compute.id, "x86_64"]),
|
||||
reverse("buses", args=[self.compute.id, "x86_64", "q35", "disk"]),
|
||||
reverse("domcaps", args=[self.compute.id, "x86_64", "q35"]),
|
||||
]
|
||||
with patch("computes.views.ComputeManager") as mock_mgr:
|
||||
for method in ("compute_graph", "get_machine_types", "get_disk_buses", "get_dom_capabilities"):
|
||||
getattr(mock_mgr.return_value, method).return_value = "{}"
|
||||
for url in urls:
|
||||
with self.subTest(url=url):
|
||||
self.assertJson(self.client.get(url))
|
||||
|
||||
def test_vm_logs_is_json(self):
|
||||
self.assertJson(self.client.get(reverse("vm_logs", args=[self.instance.name])))
|
||||
|
||||
|
|
@ -106,6 +120,10 @@ class TemplateHtmlConcatenationTestCase(TestCase):
|
|||
self.assertNotIn("'<option value=' + item", src)
|
||||
self.assertNotIn('pool + "<span', src)
|
||||
|
||||
def test_create_wizard_chipset_list_does_not_concatenate_into_html(self):
|
||||
src = self._read("instances/templates/create_instance_w1.html")
|
||||
self.assertNotIn("""append('<option value="' + item""", src)
|
||||
|
||||
def test_create_wizard_volume_lists_do_not_concatenate_volume_names_into_html(self):
|
||||
src = self._read("instances/templates/create_instance_w2.html")
|
||||
self.assertNotIn("'<option value=' + item", src)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue