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

Avoid NRE in ImportRemoteInstanceController.import() #12330

Merged
merged 2 commits into from
Sep 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ public async Task<IActionResult> Import(ImportViewModel model)

var remoteClient = remoteClientList.RemoteClients.FirstOrDefault(x => x.ClientName == model.ClientName);

if (remoteClient == null)
{
return StatusCode((int)HttpStatusCode.BadRequest, "The remote client was not provided");
Copy link
Member

Choose a reason for hiding this comment

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

Just for info the following does the same, yes better to not do it here for consistency with other lines of code below, but maybe a good canditate for a separate PR ;)

            return BadRequest("The remote client was not provided");

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 will try to check the entire code to see if we have such thing .. thanks

Copy link
Member Author

Choose a reason for hiding this comment

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

}

var apiKey = Encoding.UTF8.GetString(_dataProtector.Unprotect(remoteClient.ProtectedApiKey));

if (remoteClient == null || model.ApiKey != apiKey || model.ClientName != remoteClient.ClientName)
if (model.ApiKey != apiKey || model.ClientName != remoteClient.ClientName)
{
return StatusCode((int)HttpStatusCode.BadRequest, "The Api Key was not recognized");
}
Expand Down