EasyNetQ.Management.Client icon indicating copy to clipboard operation
EasyNetQ.Management.Client copied to clipboard

ChangeUserPasswordAsync throws ArgumentException when called

Open runegulbrandsen opened this issue 5 years ago • 3 comments

When you try to update the password for an existing user that doesn't have any tags, an ArgumentException is thrown because it tries to add an empty tag.

Exception:

System.ArgumentException: tag is null or empty
   at EasyNetQ.Management.Client.Model.UserInfo.AddTag(String tag)
   at EasyNetQ.Management.Client.ManagementClient.ChangeUserPasswordAsync(String userName, String newPassword, CancellationToken cancellationToken)

The reason is that the following code doesn't remove empty entries:

https://github.com/EasyNetQ/EasyNetQ.Management.Client/blob/05d539354b6eea8c83c8dcf1133d86f5ec1619d4/Source/EasyNetQ.Management.Client/ManagementClient.cs#L603

runegulbrandsen avatar May 28 '20 07:05 runegulbrandsen

This is a kind of critical, because you can't add tags that isn't one of the allowed ones when creating a user, and I don't want any of those system tags on the user.

runegulbrandsen avatar May 28 '20 07:05 runegulbrandsen

I have the same issue, I can create users with empty or custom tags on RabbitMQ Management UI but I can't do it using this library. Is there a chance that this will be changed in near future?

CagatayCanK avatar May 17 '21 21:05 CagatayCanK

I have met this problem too. Fortunatelly all pieces are public so i was able to reimplement method by myself as workaround.

private async Task<User> ChangeUserPasswordAsync(string userName, string newPassword, CancellationToken cancellationToken = default(CancellationToken))
{
   var user = await Client.GetUserAsync(userName, cancellationToken).ConfigureAwait(false);

   var tags = user.Tags.Split(',');
   var userInfo = new UserInfo(userName, newPassword);
   foreach (var tag in tags)
   {
       if (!string.IsNullOrEmpty(tag.Trim()))
       {
           userInfo.AddTag(tag.Trim());
       }
   }

   return await Client.CreateUserAsync(userInfo, cancellationToken).ConfigureAwait(false);
}
`

maximaf avatar Aug 24 '21 11:08 maximaf

https://www.nuget.org/packages/EasyNetQ.Management.Client/2.0.0-beta2

Pliner avatar Dec 11 '22 21:12 Pliner