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

Handle T message and prepare for adding -p option #80

Merged
merged 7 commits into from
Apr 28, 2024

Conversation

datadius
Copy link
Contributor

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.
image

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.

Copy link
Owner

@bramvdbogaerde bramvdbogaerde left a 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

client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
protocol.go Outdated Show resolved Hide resolved
protocol.go Outdated Show resolved Hide resolved
@datadius
Copy link
Contributor Author

datadius commented Apr 27, 2024

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.

@datadius
Copy link
Contributor Author

datadius commented Apr 28, 2024

Test failed because I updated the error message
Expected: scp: /input/no_such_file.txt: No such file or directory
Got: Failed to execute command with a warning or error: scp: /input/no_such_file.txt: No such file or directory

Should the test be updated, or should I just remove the extra text @bramvdbogaerde ?

The error comes from line 49 in protocol.

@bramvdbogaerde
Copy link
Owner

bramvdbogaerde commented Apr 28, 2024

I would remove the extra text lest someone is pattern matching on the original.

@datadius
Copy link
Contributor Author

I would remove the extra text lest someone is pattern matching on 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.

Copy link
Contributor Author

@datadius datadius left a 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"

@bramvdbogaerde bramvdbogaerde self-requested a review April 28, 2024 16:15
@bramvdbogaerde
Copy link
Owner

bramvdbogaerde commented Apr 28, 2024

changes are ready.

EDIT: Thought it would remove the "changes requested"

Yes I have to approve the changes manually. Looks good now, merging.

@bramvdbogaerde bramvdbogaerde merged commit db7cf4f into bramvdbogaerde:master Apr 28, 2024
1 check passed
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.

2 participants