rabbitmq / rabbitmq-management

RabbitMQ Management UI and HTTP API
https://www.rabbitmq.com/management.html
Other
370 stars 165 forks source link

UI: Policy definition with empty value not sent to API #842

Closed a-st closed 4 years ago

a-st commented 4 years ago

When using the RabbitMQ management UI to add/update a user policy, only definition with a non-empty value are actually sent to the API.

When using the API directly, definitions with emtpy values are preserved and work as expected.

Steps to reproduce

  1. Login to management UI
  2. Navigate to Admin
  3. Select Policies from the navigation bar
  4. In Add / update a policy section enter/select following values
    Pattern: my-pattern
    Apply to: Exchanges and queues
    Priority: 
    Definition:
    dead-letter-exchange      =     <empty>            (String) 
    dead-letter-routing-key   =     my-routing-key     (String) 
  5. Click Add / update policy
  6. Check table in User policies section
  7. Entry for my-policy is missing the definition dead-letter-exchange with empty value

On the other hand, when using the HTTP API, e.g. with following cURL command, everything works as expected and entry for my-policy contains the definition dead-letter-exchange with empty value

curl 'http://localhost:15672/api/policies/%2F/DLQ' \
  -X 'PUT' \
  -H 'content-type: application/json' \
  --data-binary '{"vhost":"/","name":"my-policy","pattern":"my-pattern","apply-to":"all","definition":{"dead-letter-exchange":"", "dead-letter-routing-key":"my-routing-key"}}'

I've tried to investigate this issue on my own and it looks like following function is causing this issue as it removes every key that has no value https://github.com/rabbitmq/rabbitmq-management/blob/74fbfbe6fcb449b141245ebfd2e4f4e5935e5a46/priv/www/js/main.js#L1360

michaelklishin commented 4 years ago

This is by design. If your goal is to dead letter via the default exchange, use amq.default for exchange name.

rabbitmqadmin and Access Control guide mention this, perhaps it should be added to the DLX guide.

michaelklishin commented 4 years ago

Some basic tests and digging in the codebase suggest that the amq.default alias is not applied to DLX values, so setting up dead lettering to the default exchange via UI forms is not possible.

We will retain the form behavior as you really do not want to send blank fields in every other case. Aliasing would have to be extended.