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

fix(client): prefer CLI arguments, following OpenSSH behaviour #45

Merged
merged 8 commits into from
Dec 18, 2023

Conversation

TheoTechnicguy
Copy link
Contributor

This PR fixes issue #35 where the client preferred the values from the configuration file ~/.ssh/config instead of the CLI arguments. The new behaviour reflects the one used by OpenSSH, preferring the port from the CLI and the hostname from the configuration.

The client prefered using values from the config file. The expected
behaviour is to prefer vales from the CLI and fill the missing ones with
defaults in the configuration files.
This commit fixes 35 by prefering CLI over config.

fix 35
ed016ea fixed the config port being preferred over the CLI port, but
introduced a bug where the default was preferred over the config port.
This commit addresses this by setting the default port only after
checking config port availability.
Follow OpenSSH behaviour and prefer using the in configuration set
hostname over the one in the CLI.

fix: 35
@francoismichel
Copy link
Owner

The integration test suite might be a bit agressive sometimes, I'll run it locally later and let you know

@TheoTechnicguy
Copy link
Contributor Author

How do I run the tests? go test ./... says everything is OK.

@TheoTechnicguy
Copy link
Contributor Author

TheoTechnicguy commented Dec 17, 2023

In my opinion, the failures are not a result of code changes, as I get the same errors when running integration tests on the main branch.

asciicast

I'm not familiar with the Ginko test framework, so I don't know where the faults are coming from. I am willing to help resolve the failing tests with some guidance.
Furthermore, I find it interesting that macOS builds pass, but Linux do not. Do you happen to know the reason for this?

@francoismichel
Copy link
Owner

francoismichel commented Dec 17, 2023

Sorry for the delay, I am bit busy on week ends :-)

Sooo, it is a bit surprising, especially that I am not able to reproduce the fails on my own setup on several distros. It seems either the server in the integration tests crashes at some point. What is also weird is that I cannot reproduce the fails on the main branch when I rerun the Github action on it, but the error seems unrelated to your PR. We probably need a bit more logging on the server-side, and in the test suite, check that the server Consistently does not crash with an error, so that we can get the actual error if it crashes. I can try to add that additional checks on the test suite to debug that.

Concerning the MacOS build, it does not run the integration test suite because MacOS cannot run the server yet.

Thanks for the PR ad the help ! Let's continue to investigate.

@francoismichel
Copy link
Owner

francoismichel commented Dec 17, 2023

Allright, both the integration test suite and your PR seem fine, the problem is probably the github secrets that do not seem accessible in PRs from non-maintainers. These secrets are not real secrets so I'll remove these and generate all the stuff (mock certs and keys) in the CI script.
This has been fixed in #51, so I think if you rebase it should work.
Let's get back to the real topic of this PR, I'll do a review soon. :-)

@TheoTechnicguy
Copy link
Contributor Author

Thank you for investing the time looking into this. I have just merged with main. We'll see how GitHub likes the changes 😋

@francoismichel
Copy link
Owner

francoismichel commented Dec 17, 2023

Github seems to love it.
I'll do the PR review tomorrow.
Thanks again!

@TheoTechnicguy
Copy link
Contributor Author

Nice! Your changes seem to make GitHub happy, which makes me happy (^u^). Thanks again for investigating the problem. Please don't hesitate to ask for changes if needed.

if urlPort != "" {
if parsedPort, err := strconv.Atoi(urlPort); err != nil || parsedPort > 0xffff {
// use WithLevel(zerolog.FatalLevel) to log a fatal level, but let us handle
// programm termination. log.Fatal() exits with os.Exit(1).
Copy link

Choose a reason for hiding this comment

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

Suggested change
// programm termination. log.Fatal() exits with os.Exit(1).
// program termination. log.Fatal() exits with os.Exit(1).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch!

Copy link
Owner

@francoismichel francoismichel left a comment

Choose a reason for hiding this comment

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

Thank you for the PR !

Just a few comments but it's great. :-)

If you disagree with the comments we can iterate.

port, err = strconv.Atoi(urlPort)
if err != nil {
log.Error().Msgf("invalid port number: %s: %s", urlPort, err)
// *** Port selection ***
Copy link
Owner

Choose a reason for hiding this comment

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

Overall I am not a huge fan of the table. I think we can make it more concise. The error case when the port cannot be parsed seems obvious.
I think it is fine if we just say that the CLI port takes precedence over the config port when specified.

var port int
if urlPort != "" {
if parsedPort, err := strconv.Atoi(urlPort); err != nil || parsedPort > 0xffff {
// use WithLevel(zerolog.FatalLevel) to log a fatal level, but let us handle
Copy link
Owner

Choose a reason for hiding this comment

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

Would you mind inverting the two parts if this branch ? Putting the non-error case in the if part and the error case in the else part ? I think it makes it more readable because the default flow goes towards what we want to achieve. But maybe it is just me ? If you have good reasons to let it like that, let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will do. I think this is more a go habit, as most of my if statements are used to check for the absence of errors 😄

}
} else if configPort != -1 {
Copy link
Owner

Choose a reason for hiding this comment

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

Add the comment // no port specified in the CLI args ?

} else if configPort != -1 {
port = configPort
} else {
port = 443
Copy link
Owner

Choose a reason for hiding this comment

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

Add a comment, like // no explicit port from the CLI and no port specified in config ?

Copy link
Owner

@francoismichel francoismichel left a comment

Choose a reason for hiding this comment

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

Great ! If you could just remove the part when the code is reformatted it it would make it easier to review and make the final commit cleaner. :-)

Other than that, I am happy with your changes !

if transportErr.ErrorCode.IsCryptoError() {
if tty == nil {
log.Error().Msgf("insecure server cert in non-terminal session, aborting")
return -1
}
if _, ok = knownHosts[hostname]; ok {
log.Error().Msgf("The server certificate cannot be verified using the one installed in %s. " +
Copy link
Owner

Choose a reason for hiding this comment

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

I am okay to reformat the code in a standard manner but could we do that in another PR ? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch! That was not intended — you're absolutely right about keeping one topic per PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I don't want to monopolize your time, so I won't re-re-request a review at this time.

Copy link
Owner

Choose a reason for hiding this comment

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

You can request it anytime, don't worry.

Copy link
Owner

@francoismichel francoismichel left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@francoismichel francoismichel merged commit d868c6c into francoismichel:main Dec 18, 2023
7 checks passed
@TheoTechnicguy TheoTechnicguy deleted the iss35 branch December 18, 2023 21:58
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.

3 participants