question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Permissions Violation for Publish does not throw an exception

See original GitHub issue

Steps to repro:

  1. Create a user that has these permissions: CLIENT = { publish = { allow: [“sub.>”]} subscribe = “sub.>” }

users = [ {user: client, password: ccc, permissions: $CLIENT} ]

Run the following xUnit test and observe no exception is thrown

[Theory]
       [InlineData("client", "ccc", "BAD!", true)]
       public void PublishPermission(string userName, string password, string subject, bool pass)
       {

           ConnectionFactory cf = new ConnectionFactory();

           var options = ConnectionFactory.GetDefaultOptions();
           options.User = userName;
           options.Password = password;

           using (var connection = cf.CreateConnection(options))
           {

           
               connection.Publish(subject, Encoding.UTF8.GetBytes("Hello"));

               var error = connection.LastError;

           }

       }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ColinSullivan1commented, Dec 22, 2021

This is a race condition between processing the error and closing the connection and Publish is non-blocking w/r/t publish errors. If the client detects the closed connection first, it’ll handle things as if the the connection was closed. If the client processes the error first, you’ll get an async error notification if an async error handler is set and LastError would be set.

For this test, if you put a sleep or Flush() after the publish to allow the test time to process the error message, you should see LastEx set.

I don’t believe the server will close the connection on a publish error, I suspect the connection is being closed by dispose when falling out of the using block.

0reactions
Drew40Bcommented, Dec 24, 2021

I am evaluating how nats client handles permission / publish errors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NATS ErrAuthorization error hidden by STAN ErrTimeout
Start up a NATS Streaming server with nats configuration with a user that doesn't have permission to publish to a channel.
Read more >
NATS-How to set the subscribe and publish permission ...
A publish to a stream only requires permission to the actual subject of the message, in this case test . What appears to...
Read more >
How to set the subscribe and publish permission when ...
Hi! I would set auth permission, but it seems different when using request-reply mode. Here is my setting: values.yaml. users: -user: test
Read more >
Exception Throwing - Framework Design Guidelines
✔️ DO document all exceptions thrown by publicly callable members because of a violation of the member contract (rather than a system failure) ......
Read more >
Troubleshoot permission and security issues - ASP.NET
This article describes how to troubleshoot common permissions and security-related issues in ASP.NET.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found