Skip to content

Improve missing/malformed file handling in user-jwts #42309

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

Merged
merged 3 commits into from
Jun 21, 2022

Conversation

captainsafia
Copy link
Member

Closes #42306
Closes #42304

@captainsafia captainsafia requested a review from a team June 20, 2022 17:50
@captainsafia captainsafia requested a review from Pilchie as a code owner June 20, 2022 17:50
@ghost ghost added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Jun 20, 2022
@captainsafia captainsafia added old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-userjwts The `dotnet user-jwts` CLI tool and removed area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI labels Jun 20, 2022
@@ -123,7 +123,7 @@ public static void Register(ProjectCommandLineApplication app)
var name = nameOption.HasValue() ? nameOption.Value() : Environment.UserName;
optionsString += $"{Resources.JwtPrint_Name}: {name}{Environment.NewLine}";

var audience = audienceOption.HasValue() ? audienceOption.Values : DevJwtCliHelpers.GetAudienceCandidatesFromLaunchSettings(project).ToList();
var audience = audienceOption.HasValue() ? audienceOption.Values : DevJwtCliHelpers.GetAudienceCandidatesFromLaunchSettings(project)?.ToList();
optionsString += audienceOption.HasValue() ? $"{Resources.JwtPrint_Audiences}: {audience}{Environment.NewLine}" : string.Empty;
Copy link
Member

@BrennanConroy BrennanConroy Jun 20, 2022

Choose a reason for hiding this comment

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

Suggested change
optionsString += audienceOption.HasValue() ? $"{Resources.JwtPrint_Audiences}: {audience}{Environment.NewLine}" : string.Empty;
optionsString += audience is not null ? $"{Resources.JwtPrint_Audiences}: {audience}{Environment.NewLine}" : string.Empty;

This would then print the URL gotten from launchSettings which we weren't including before (bug creep 😆)

Copy link
Member Author

Choose a reason for hiding this comment

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

That was actually intentional. This was meant to only display options that were explicitly passed by the user, not ones we implicitly derived (e.g. username from Environment.UserName or urls from launchSettings).

@DamianEdwards
Copy link
Member

So does the tool correctly discover all URLs from the launchSettings.json file now? The IIS Express URL?

@captainsafia
Copy link
Member Author

So does the tool correctly discover all URLs from the launchSettings.json file now? The IIS Express URL?

Yes, as of 9ff265e.

}
applicationUrls.AddRange(kestrelUrls);
}

Copy link
Member

Choose a reason for hiding this comment

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

nit: else if

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that's the right call here. We want to populate audience from both IIS and Kestrel-based URLs here so we get a complete set of audiences by the end.

Copy link
Member

Choose a reason for hiding this comment

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

The reason I think it should be else if is because if the Kestrel check of profile.Value.TryGetProperty("commandName", out var commandName) passes then the IIS check won't pass for this specific profile. Again, it's a nit, not code we need to worry about performance for.

List<string> iisUrls = new();
if (iisExpress.TryGetProperty("applicationUrl", out var iisUrl))
{
iisUrls.Add(iisUrl.GetString());
Copy link
Member

Choose a reason for hiding this comment

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

can these urls also be ; separated?

Copy link
Member

Choose a reason for hiding this comment

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

I didn't think so, but we'd need to check with VS

Copy link
Member Author

@captainsafia captainsafia Jun 21, 2022

Choose a reason for hiding this comment

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

I tested it out. VS will throw if you have something like this:

"iisExpress": {
    "applicationUrl": "http://localhost:22686;http://localhost:22687",
    "sslPort": 44333
  }

@captainsafia captainsafia enabled auto-merge (squash) June 21, 2022 00:53
@captainsafia captainsafia merged commit 69d3755 into main Jun 21, 2022
@captainsafia captainsafia deleted the safia/jwt-tool-fixes branch June 21, 2022 02:26
@ghost ghost added this to the 7.0-preview6 milestone Jun 21, 2022
@amcasey amcasey added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-userjwts The `dotnet user-jwts` CLI tool old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
4 participants