-
Notifications
You must be signed in to change notification settings - Fork 22
Add client assertion authentication #145
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
base: main
Are you sure you want to change the base?
Changes from all commits
28257f6
7e4e9f5
18ed587
d0dc695
5cb3521
d92adbd
2bc6f7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,6 +128,24 @@ internal static async Task<bool> InitAsync(IAnsiConsole ansiConsole, IConfigurat | |
| return false; | ||
| } | ||
|
|
||
| if (config.ClientAssertion) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does the right thing in not sending assertion users into The catch is that it now skips the check entirely, so for Could we do the presence check here instead of returning |
||
| { | ||
| try | ||
| { | ||
| await EnvironmentInfo.GetClientAssertionAsync(); | ||
| return true; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| if (ex is InvalidOperationException) | ||
| { | ||
| ansiConsole.MarkupLine(ex.Message); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs
|
||
| } | ||
| logger.LogCritical(ex, "Failed to get client assertion."); | ||
|
dongle-the-gadget marked this conversation as resolved.
|
||
| } | ||
| return false; | ||
| } | ||
|
|
||
| var secret = credentialManager.ReadCredential(config.ClientId.Value.ToString()); | ||
| if (string.IsNullOrEmpty(config.CertificateFilePath) | ||
| && string.IsNullOrEmpty(config.CertificateThumbprint) | ||
|
|
||
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.
Thanks for adding this. Worth knowing its reach though —
FakeStoreAPIFactoryis mocked inBaseCommandLineTest.cs:194, so this covers the flag making it into the config but never actually resolves an assertion.If you feel like it, a few direct tests on
GetClientAssertionAsyncwould cover the parts most likely to break: neither variable set, both set, and the file case trimming its trailing newline. Not a blocker.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.
I'm not particularly sure how to approach this. AFAIK
Environment.GetEnvironmentVariableisn't mockable directly?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.
You're right that
Environment.GetEnvironmentVariableisn't mockable — but I don't think you need to mock it. Setting the real variable in the test works here, becauseUsings.cs:8already has[assembly: DoNotParallelize], so tests won't stomp on each other.Clear the variables in both
[TestInitialize]and[TestCleanup]— init matters as much as cleanup, since whoever runs the suite may already have them set in their shell:Then four straightforward cases: neither set throws, both set throws, the variable is returned as-is, and a file with a trailing newline comes back trimmed. I sketched these out and they pass. Still not a blocker if you'd rather leave it.