Configuration form should report invalid json in values that need to contain json
As per a report from a user, if you take say a VP test and make the presentation_definition invalid json using the form, then switching to the json tab or submitting the form etc results in the value being sent to the server as a string rather than as json (which then results in an error when the test is run) - e.g. this has a presentation_definition with a missing comma:
https://demo.certification.openid.net/log-detail.html?log=vmh4ua92S9Suno9
We need a type field in the json, as was mentioned in #411 and commit 6aa805e26d15dea6a85dedd013468ed9140235fc.
Below is the rough form this could take, but we need to catch the exception, show it to the user, and prevent the tab switch or form submission or whatever called `updateJSONFromFormElements()` proceeding.
```
diff --git a/src/main/resources/static/schedule-test.html b/src/main/resources/static/schedule-test.html
index 730f111c5..f84269045 100644
--- a/src/main/resources/static/schedule-test.html
+++ b/src/main/resources/static/schedule-test.html
@@ -377,7 +377,7 @@ integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqrupt
<div class="input-group-text">
<span class="bi bi-info-circle-fill" data-bs-toggle="tooltip" data-bs-placement="bottom" title="presentation_definition to use in authorization request"></span>
</div>
- <textarea class="form-control config-form-element" data-json-target="client.presentation_definition"></textarea>
+ <textarea class="form-control config-form-element" data-json-target="client.presentation_definition" data-json-type="jsonobject"></textarea>
</div>
</div>
</div>
@@ -1743,7 +1743,7 @@ integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqrupt
function updateJSONFromFormElements() {
document.getElementById('formInput').querySelectorAll('.config-form-element')?.forEach(function(element) {
if (element.classList.contains('config-form-element')) {
- populateJSON(element.dataset.jsonTarget, element.value);
+ populateJSON(element.dataset.jsonTarget, element.value, element.dataset.jsonType);
}
});
@@ -1816,7 +1816,7 @@ integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqrupt
*
*/
- function populateJSON(key, val) {
+ function populateJSON(key, val, type) {
// preserve valid json objects and arrays as json values; store everything else as a string
// This has an odd side effect that (say) a jwks that is invalid json (e.g. extra or missing comma) is
// inserted as a string
@@ -1836,6 +1836,9 @@ integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqrupt
FAPI_UI.prop(FAPI_UI.testJSON, key, val);
}
} catch (e) { // a string
+ if (type === "jsonobject") {
+ throw e;
+ }
FAPI_UI.prop(FAPI_UI.testJSON, key, val);
}
```
issue