dunglas / mercure

🪽 An open, easy, fast, reliable and battery-efficient solution for real-time communications
https://mercure.rocks
GNU Affero General Public License v3.0
3.91k stars 291 forks source link

Filtering subscriptions by topic doesn't work #833

Open itodor opened 10 months ago

itodor commented 10 months ago

I am trying to use as minimal example as possible, I just spinned out of the box docker-compose proposed file on my localhost from official link https://mercure.rocks/docs/hub/install (the only difference is I disabled HTTPS so i run on normal :80).

I made dummy client who connects to 3 topics just for testing purposes, all the same user payload, topics are named (1,2,3), I know they should be URI formatted but for testing purposes I wanted to simplify as much as possible. So when I do the following call it confirms that this client is listening on 3 topics:

➜  ~ curl 'http://localhost/.well-known/mercure/subscriptions' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdLCJzdWJzY3JpYmUiOlsiKiJdLCJwYXlsb2FkIjp7InVzZXIiOiIxMTExMTEifX19.09mOg1RCswaUDqdMOQ54FjZQqKtbFq1wgMxfD-5tA98'

I get:

{
  "@context": "https://mercure.rocks/",
  "id": "/.well-known/mercure/subscriptions",
  "type": "Subscriptions",
  "lastEventID": "urn:uuid:0ec53206-0d81-43b1-8f9f-e682963f27a5",
  "subscriptions": [
    {
      "id": "/.well-known/mercure/subscriptions/1/urn%3Auuid%3Abf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "type": "Subscription",
      "subscriber": "urn:uuid:bf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "topic": "1",
      "active": true,
      "payload": {
        "user": "333333"
      }
    },
    {
      "id": "/.well-known/mercure/subscriptions/2/urn%3Auuid%3Abf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "type": "Subscription",
      "subscriber": "urn:uuid:bf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "topic": "2",
      "active": true,
      "payload": {
        "user": "333333"
      }
    },
    {
      "id": "/.well-known/mercure/subscriptions/3/urn%3Auuid%3Abf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "type": "Subscription",
      "subscriber": "urn:uuid:bf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "topic": "3",
      "active": true,
      "payload": {
        "user": "333333"
      }
    }
  ]
}%

Everything as expected, but now I want to filter by topics, so I just want it to show me subscriptions that are connected to the topic 2:

➜  ~ curl 'http://localhost/.well-known/mercure/subscriptions/2' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdLCJzdWJzY3JpYmUiOlsiKiJdLCJwYXlsb2FkIjp7InVzZXIiOiIxMTExMTEifX19.09mOg1RCswaUDqdMOQ54FjZQqKtbFq1wgMxfD-5tA98'

I get:

{
  "@context": "https://mercure.rocks/",
  "id": "/.well-known/mercure/subscriptions/2",
  "type": "Subscriptions",
  "lastEventID": "urn:uuid:0ec53206-0d81-43b1-8f9f-e682963f27a5",
  "subscriptions": [
    {
      "id": "/.well-known/mercure/subscriptions/1/urn%3Auuid%3Abf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "type": "Subscription",
      "subscriber": "urn:uuid:bf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "topic": "1",
      "active": true,
      "payload": {
        "user": "333333"
      }
    },
    {
      "id": "/.well-known/mercure/subscriptions/2/urn%3Auuid%3Abf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "type": "Subscription",
      "subscriber": "urn:uuid:bf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "topic": "2",
      "active": true,
      "payload": {
        "user": "333333"
      }
    },
    {
      "id": "/.well-known/mercure/subscriptions/3/urn%3Auuid%3Abf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "type": "Subscription",
      "subscriber": "urn:uuid:bf7ef475-b1b8-4f3e-a2ae-b89b94184465",
      "topic": "3",
      "active": true,
      "payload": {
        "user": "333333"
      }
    }
  ]
}%

I am still getting all 3 subscriptions even though I just want the 2nd one with topic 2.

Interestingly enough, its not that it doesn't work at all, for example, in examples before I was playing with 3 users, so when I would query for all the subscriptions, I would get obviously all subscriptions, but when I filtered for topic X, I would get only subscriptions that are connected to topic X BUT also I would get all their other subscriptions as well which I don't want.

Is this the way its supposed to work and I have to do filtering manually on my side or am I missing something?

frizquierdo commented 10 months ago

The issue it's reported here. With cookie authorization also happen.