Repository: openwisp/openwisp-controller (language: python)

Issue:
[bug] Private Key in Wireguard server preview is not shown
Create/edit a Wireguard VPN server, hit preview.

**Expected result**: private key is shown.

**Actual result**: private key is not shown.

![Screenshot from 2024-06-11 12-03-35](https://github.com/openwisp/openwisp-controller/assets/841044/c8707a7f-d64c-4d66-bb60-86487c4eb668)



Discussion / hints:

Fix patch:
diff --git a/openwisp_controller/config/static/config/js/preview.js b/openwisp_controller/config/static/config/js/preview.js
index 0f421c1a1..07a2371ac 100644
--- a/openwisp_controller/config/static/config/js/preview.js
+++ b/openwisp_controller/config/static/config/js/preview.js
@@ -7,7 +7,7 @@ django.jQuery(function ($) {
     var openPreview = function () {
         var selectors = 'input[type=text], input[type=hidden], select, textarea',
             fields = $(selectors, '#content-main form').not('#id_config_jsoneditor *'),
-            $id = $('#id_id'),
+            $id = $('#id_uuid'),
             data = {},
             loadingOverlay = $('#loading-overlay');
         loadingOverlay.show();


Test patch:
diff --git a/openwisp_controller/config/tests/test_selenium.py b/openwisp_controller/config/tests/test_selenium.py
index ec360392b..c096724d9 100644
--- a/openwisp_controller/config/tests/test_selenium.py
+++ b/openwisp_controller/config/tests/test_selenium.py
@@ -298,6 +298,26 @@ def test_vpn_edit(self):
             el = self.web_driver.find_element(by=By.CLASS_NAME, value='field-cert')
             self.assertFalse(el.is_displayed())
 
+        with self.subTest('PrivateKey is shown in configuration preview'):
+            self.web_driver.find_element(
+                by=By.CSS_SELECTOR, value='.previewlink'
+            ).click()
+            WebDriverWait(self.web_driver, 2).until(
+                EC.visibility_of_element_located(
+                    (By.CSS_SELECTOR, '.djnjc-preformatted')
+                )
+            )
+            self.assertIn(
+                f'PrivateKey = {vpn.private_key}',
+                self.web_driver.find_element(
+                    by=By.CSS_SELECTOR, value='.djnjc-preformatted'
+                ).text,
+            )
+        # Close the configuration preview
+        self.web_driver.find_element(
+            by=By.CSS_SELECTOR, value='.djnjc-overlay a.close'
+        ).click()
+
         with self.subTest('Changing VPN backend should hide webhook and authtoken'):
             backend = Select(self.web_driver.find_element(by=By.ID, value='id_backend'))
             backend.select_by_visible_text('OpenVPN')