Emulator returns malformed XML for root document and 403 for all other requests
After pulling the latest emulator from github and running the install with the defaults the emulator comes up but only responds to a request for the root of the server successfully. All other requests return 403.
https://127.0.0.1:5000/redfish/v1/ returns INFO:werkzeug:127.0.0.1 - - [16/May/2024 16:30:23] "GET /redfish/v1/ HTTP/1.1" 200 - from the server
The response is garbled according to browsers -
XML Parsing Error: not well-formed Location: https://127.0.0.1:5000/redfish/v1/ Line Number 1, Column 1: {"@odata.id":"/redfish/v1","@odata.type":"#ServiceRoot.v1_15_0.ServiceRoot","Chassis":{"@odata.id":"/redfish/v1/Chassis"},"Fabrics":{"@odata.id":"/redfish/v1/Fabrics"},"Id":"RootService","Links":{"Sessions":{"@odata.id":"/redfish/v1/SessionService/Sessions"}},"Managers":{"@odata.id":"/redfish/v1/Managers"},"Name":"Root Service","RedfishVersion":"1.18.0","Registries":{"@odata.id":"/redfish/v1/Registries"},"SessionService":{"@odata.id":"/redfish/v1/SessionService"},"Storage":{"@odata.id":"/redfish/v1/Storage"},"UUID":"92384634-2938-2342-8820-489239905423"} ^
cURL seems OK - $ curl -k https://localhost:5000/redfish/v1/ { "@odata.type": "#ServiceRoot.v1_15_0.ServiceRoot", "Id": "RootService", "Name": "Root Service", "RedfishVersion": "1.18.0", "UUID": "92384634-2938-2342-8820-489239905423", "Chassis": { "@odata.id": "/redfish/v1/Chassis" }, "Fabrics": { "@odata.id": "/redfish/v1/Fabrics" }, "Managers": { "@odata.id": "/redfish/v1/Managers" }, "SessionService": { "@odata.id": "/redfish/v1/SessionService" }, "Registries": { "@odata.id": "/redfish/v1/Registries" }, "Storage": { "@odata.id": "/redfish/v1/Storage" }, "Links": { "Sessions": { "@odata.id": "/redfish/v1/SessionService/Sessions" } }, "@odata.id": "/redfish/v1" }
All other requests return 403 for example - https://127.0.0.1:5000/redfish/v1/Storage returns Missing Header INFO:werkzeug:127.0.0.1 - - [16/May/2024 16:30:31] "GET /redfish/v1/Storage HTTP/1.1" 403 - from the server
Have I missed a setup step or some other configuration process?
I assume you mean malformed JSON, not XML, right?
As far as the "missing header" message, that's expected. See https://github.com/SNIA/Swordfish-API-Emulator/issues/123#issuecomment-1944426087 for an explanation.
The curl output looks fine, so it seems like the browser may doing something unexpected with the output.
I can reproduce the browser error message (using Brave). But viewing source and pasting the content into a JSON validator tool, the content is valid. It looks like the server is not responding with with a Content-type: application/json header, so the browser is trying to interpret the content as HTML.
FWIW, I do think it would be good if the Swordfish emulator kept the nice default root HTML page and JSON browser (browse.html) that the Redfish emulator serves. But the Swordfish emulator redirects to HTTPS and looks for an auth session for all pages except those mentioned in the linked comment above.
I agree that the formatting errors are mostly cosmetic. The 403 errors from every request in the tree except the root doc seem to be a real problem though. Have I missed something when making those requests?
Basically, just browsing the object tree in a browser is not supported. You need to be able to pass authentication information to each request. So you will need to use curl or something like Postman to be able to explore rather than the nice browser interface that the Redfish emulator provides.
I haven't looked in to it at all, but it would be nice to have the browse.html landing page that can take some credentials, then provide an easy way to browse through the Swordfish tree. But that will require a code change to support something like that, and I think the primary use case of the emulator is more targeted to the programmatic access versus the human friendly browsing.
Another option - add a flag to emulator.py to be able to turn off the authentication requirement.
Disabling authentication solves the 403 problem.
I updated the emulator-config.json rather than figure out what flag flask needs to disable authentication.
My emulator-config.json is now
{ "MODE": "Local", "HTTPS": "Disable", "TRAYS": [], "STATIC": "Disable", "SPEC": "Redfish", "MOCKUPFOLDERS": ["Mockups"], "AUTHENTICATION": "**Disable**", "CERTIFICATE": ["server.crt", "server.key"] }