-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WPS: added key byte cache to the auth policy #22277
Conversation
sdk/webpubsub/Azure.Messaging.WebPubSub/src/WebPubSubAuthenticationPolicy.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider adding a test or two for validation of the behavior?
public KeyBytesCache(string key) | ||
{ | ||
Key = key; | ||
KeyBytes = Encoding.UTF8.GetBytes(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KeyBytes = Encoding.UTF8.GetBytes(key); | |
KeyBytes = string.IsNullOrEmpty(key) | |
? Array.Empty<byte>() | |
: Encoding.UTF8.GetBytes(key); |
Probably a tiny efficiency, but should we consider avoiding GetBytes
when the string is empty? It looks like there's no special case for it and it'll do some stack allocations that we can avoid. (ref) Maybe a factory method for an empty instance, instead?
We will be adding test before GA but it's a non trivial workitem. The problem is that this component is inherently difficult to test. There are not APIs to observe changes to the service. I was also thinking about unit testing this policy with fake messages. I need to talk to Pavel about adding fake Transport/Request/Response for that. He wanted to do something like that in Azure.Core, i.e. add test only Request/Response. |
cc: @jkotas
At some point we might want to cache the whole token, but that is a bit more tricky as the JWT audience changes from call to call (it's the absolute URI).