Skip to content
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

Read new wwwauth[] input from Git 2.41 #1288

Merged
merged 3 commits into from
Jun 12, 2023

Conversation

mjcheetham
Copy link
Collaborator

Add the new wwwauth[] credential property to the input arguments surfaced to providers and commands. This optional property is available as of Git 2.41.

Git v2.41 Release Notes
=======================

UI, Workflows & Features

 * Allow information carried on the WWW-Authenticate header to be
   passed to the credential helpers.

https://lore.kernel.org/git/xmqqleh3a3wm.fsf@gitster.g/

This new property may contain multiple values, as identified by a trailing [] on the property name. Extend our Dictionary/Stream(Reader|Writer) methods to allow for these multi-valued properties and add a convenience property to the InputArguments to get wwwauth[].

Add support for reading and writing multi-dictionaries in Git's
credential helper I/O format. Multi-dictionaries differ from normal
dictionaries by being key:value relation 1:N.

Git prepends "[]" to the end of keys that should be treated as lists or
having mutliple values. An empty value in the list has the effect of
cleaning/resetting the values in the list so far.

The first multiple-valued key is expected to be 'wwwauth[]' from this
patch series:

https://lore.kernel.org/git/pull.1352.v11.git.1677518420.gitgitgadget@gmail.com/
Add the new `wwwauth[]` credential property to the input arguments
surfaced to providers and commands.
Copy link
Contributor

@ldennington ldennington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! The tests made what you did super clear and easy to follow. Nice work! ⭐

@@ -207,6 +402,20 @@ private static string WriteStringStream(IDictionary<string, string> input, Actio
return output.ToString();
}

private static void AssertDictionary(string expectedValue, string key, IDictionary<string, string> dict)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to be unused - do we want to keep it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth keeping. We should maybe be using it in some of the existing tests!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'm fine with that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a new commit on top that now uses the AssertDictionary helper method.

@@ -215,13 +216,25 @@ public void Flush()
{
bool isSecretEntry = !(secretKeys is null) &&
secretKeys.Contains(entry.Key, keyComparer ?? EqualityComparer<TKey>.Default);
if (isSecretEntry && !this.IsSecretTracingEnabled)

void WriteSecretLine(object value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware you could do this. Interesting!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the use of local functions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!


// Transform input from 1:1 to 1:n and store as readonly
_dict = new ReadOnlyDictionary<string, IList<string>>(
dict.ToDictionary(x => x.Key, x => (IList<string>)new[] { x.Value })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elegant!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helps reduce churn. This constructor is now only called from test set up code.

@mjcheetham mjcheetham merged commit 1b13045 into git-ecosystem:main Jun 12, 2023
@mjcheetham mjcheetham deleted the wwwauth branch June 12, 2023 23:23
@mjcheetham mjcheetham self-assigned this Jun 15, 2023
@mjcheetham mjcheetham mentioned this pull request Jun 26, 2023
mjcheetham added a commit that referenced this pull request Jun 26, 2023
**Changes:**

- Use in-proc methods for getting OS version number (#1240, #1264)
- Update System.CommandLine (#1265)
- Suppress GUI from command-line argument (#1267)
- Add github (login|logout|list) commands (#1267)
- cURL Cookie file support (#1251)
- Update target framework on Mac/Linux to .NET 7 (#1274, #1282)
- Replace JSON.NET with System.Text.Json (#1274)
- Preserve exact redirect URI formatting in OAuth requests (#1281)
- Use IP localhost redirect for GitHub (#1286)
- Use WWW-Authenticate headers from Git for Azure Repos authority
(#1288)
- Better GitHub Enterprise Managed User (EMU) account support (#1190)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants