nagyesta / lowkey-vault

Lowkey Vault is a small test double for Azure Key Vault. Developer feedback needed, please vote here: https://github.com/nagyesta/lowkey-vault/discussions/272
MIT License
53 stars 5 forks source link

URLs should be case-insensitive #1158

Closed tomachristian closed 23 hours ago

tomachristian commented 1 day ago

Describe the bug

Using the official KeyVault .NET library for working with LowKey Vault, I noticed that the unwrapKey and wrapKey endpoints were not working with the library. Investigating this further I noticed that Lowkey Vault is using lower-case paths for its controller mappings... and that they are case-sensitive, so the requests from the official .NET library do not work, because those use unwrapKey instead of unwrapkey.

Workaround

For anyone still wanting to use this, you can create a DelegatingHandler that you place in the processing pipeline that will lowercase the path that the .NET official library uses. You can get the gist of it from here

private sealed class BugFixHandler : DelegatingHandler
{
    protected override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        if (request.RequestUri is not null && request.RequestUri.AbsolutePath.EndsWith("Key"))
        {
            var builder = new UriBuilder(request.RequestUri);

            // We need to lowercase only the 'Key' suffix at the end
            builder.Path = builder.Path[..^3] + "key";

            request.RequestUri = builder.Uri;
        }

        return base.Send(request, cancellationToken);
    }
}

This will not work for all endpoints, you need to tailor the workaround for your own needs.

nagyesta commented 1 day ago

Hi @tomachristian , thank you for giving Lowkey Vault a try and thank you for reporting this issue! As I have seen, you are right, the official .Net client does not appear to implement the official HTTP API in a case-sensitive manner.

I will take a look, find all other cases where this might be an issue and fix them together as soon as possible.

tomachristian commented 1 day ago

Thank you! Awesome work on this project! Really appreciate it!

nagyesta commented 1 day ago

Thank you for your feedback! I am glad it is useful! Fix this issue, please try it with v2.5.6 and let me know whether it solved your problem!

Thank you in advance!

tomachristian commented 23 hours ago

I can confirm that the latest version no longer has the problem. Thank you!

nagyesta commented 23 hours ago

Thank you!