nats-io / nats.py

Python3 client for NATS

Home Page:https://nats-io.github.io/nats.py/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nats client not respecting the username and password provided in server string if server has "no_auth_user" configured

anthonyjacques20 opened this issue · comments

What version were you using?

nats-server: v2.9.21
Using commit caaf42818eb80e180e40ae2225b49b9c47fd8b1d which shows 2.3.1

What environment was the server running in?

Mac M1

Is this defect reproducible?

Yes, I wrote a test that shows the failure (and I'm working on an pull request for this):

class NoAuthUserClientTest(NoAuthUserServerTestCase):
    @async_test
    async def test_connect_user_from_server(self):
        fut = asyncio.Future()

        async def err_cb(e):
            if not fut.done():
                fut.set_result(e)

        nc = await nats.connect(
            "nats://bar:bar@127.0.0.1:4555",
            error_cb=err_cb,
        )
        sub = await nc.subscribe("foo")
        await nc.flush()
        await asyncio.sleep(0)
        await nc.publish("foo", b'hello')
        await asyncio.wait_for(fut, 2)
        err = fut.result()
        assert str(
            err
        ) == 'nats: permissions violation for subscription to "foo"'

        nc2 = await nats.connect("nats://127.0.0.1:4555", )

        async def cb(msg):
            await msg.respond(b'pong')

        sub2 = await nc2.subscribe("foo", cb=cb)
        await nc2.flush()
        resp = await nc2.request("foo", b'ping')
        assert resp.data == b'pong'

        await nc2.close()
        await nc.close()

Given the capability you are leveraging, describe your expectation?

I expect that if I provide a server with the username and password in it (such as nats://bar:bar@127.0.0.1:4555), that the nats client will connect using username bar and password bar

Given the expectation, what is the defect you are observing?

The nats client is not connecting using the passed in username and password.