-
Notifications
You must be signed in to change notification settings - Fork 90
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
Handle T message and prepare for adding -p option #80
Handle T message and prepare for adding -p option #80
Conversation
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.
Most of the code looks pretty good, thanks for your contribution. I left some minor comments that you might want to look at.
Regards,
Bram
I understand if the changes I introduced in this last commit are too big 😅 As you will see, now the CopyFromRemotePassThru method is a lot cleaner and I ended up moving quite a bit too ParseResponse. Everything is handled through errors instead of the methods previously in Response. I ended up removing Response because it wasn't needed anymore. It should be very easy to add -p in the current state. |
Test failed because I updated the error message Should the test be updated, or should I just remove the extra text @bramvdbogaerde ? The error comes from line 49 in protocol. |
I would remove the extra text lest someone is pattern matching on the original. |
The test should pass now, I removed the bit I added. I could work on the tests in another pull request. I will have to update the tests anyways once the -p is in there. |
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.
changes are ready.
EDIT:
Thought it would remove the "changes requested"
Yes I have to approve the changes manually. Looks good now, merging. |
In protocol.go I added a new field to the Response struct, indicating the type of Protocol. I believe this will prepare us to handle also -d in the future, but for the moment, the goal is to prepare for -p requests.
When parsing the message, I also make sure that the protocol is being followed, as SCP doesn't allow any other messages besides the ones starting with C, T, D.
I also added some new methods to check which type of protocol it is and if it is following the protocol. Of course if we get any directory response, it will throw an error saying it doesn't follow protocol, but that would a problem with a custom server sending this information because we don't have methods requesting that yet.
Finally, I added a method for parsing the time components. The length of the number is always from 0:10, so it should throw an error if that is not the case.
In client.go, I modified the client so when we get time information, then we make sure it doesn't impact the flow. What I encountered with a custom ssh server is that, even though I sent only -f, I would receive the time and that would cause an EOF error, as I was asking for more to read than there was on the server.
In this current form, then the time is stored in an object and it will throw an error only if the custom server sends an malformed T message, but then again, there are issues in the custom ssh server.
I prepared the FilesInfo object to use that later on as output for our -p request. For now it's "dead code" as it's not used, but I didn't want to stuff too much in the pull request.
I have tested on a custom ssh server, with the localhost OpenSSH server and using the tests in the repository.