-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add device endpoints to push/pull files and pull directory. #96
Conversation
{ | ||
return MissingParameter("path"); | ||
} | ||
if (!System.IO.File.Exists(request.Path)) { |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
if (!System.IO.File.Exists(request.Path)) { | ||
return FileNotFound(request.Path); | ||
} | ||
var data = await System.IO.File.ReadAllBytesAsync(request.Path); |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
{ | ||
return MissingParameter("path"); | ||
} | ||
if (!Directory.Exists(request.Path)) |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
I am wondering whether this should be implemented in FlaUI.WebDriver directly, or instead in an NPM wrapper library that provides it as Appium driver. For example, https://github.com/appium/appium-windows-driver/blob/master/lib/commands/file-movement.js implements this in the Appium driver, not in the |
If we decide to implement this functionality here (see previous comment), the README should be extended as well to document which Appium commands are implemented. |
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.
Thank you for your contribution. I have added some questions and minor suggestions.
|
||
|
||
[Test] | ||
public void PushFile_FileExist_FileIsOverwritten() |
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.
public void PushFile_FileExist_FileIsOverwritten() | |
public void PushFile_FileExists_FileIsOverwritten() |
} | ||
|
||
[Test] | ||
public void PullFolder_FolderDoesNotExists_ErrorRaised() |
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.
public void PullFolder_FolderDoesNotExists_ErrorRaised() | |
public void PullFolder_FolderDoesNotExist_ErrorRaised() |
{ | ||
driver.PushFile(Path.Join(dir, i.ToString()), $"{i} data"); | ||
} | ||
var zipBytes = driver.PullFolder(dir); |
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.
Please use newlines to separate arrange/act/assert parts of the test. In this case, surround PullFolder
with newlines and remove other newlines. See also other tests.
var zipBytes = driver.PullFolder(dir); | |
var zipBytes = driver.PullFolder(dir); | |
{ | ||
public class PullFileRequest | ||
{ | ||
public string? Path { get; set; } |
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.
Instead of doing request validation ourselves, wouldn't it be simpler to make the models do that?
public string? Path { get; set; } | |
public string Path { get; set; } |
public string? Path { get; set; } | ||
public string? Data { get; set; } |
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.
public string? Path { get; set; } | |
public string? Data { get; set; } | |
public string Path { get; set; } | |
public string Data { get; set; } |
return MissingParameter("path"); | ||
} | ||
var parent = Path.GetDirectoryName(request.Path)!; | ||
if (!Directory.Exists(parent)) |
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.
To add a little bit of security, we could use a "feature flag" mechanism such as appium-windows-driver to only allow this endpoint if it has been enabled, see https://github.com/appium/appium-windows-driver/blob/master/lib/commands/file-movement.js#L18
Interesting, i didn't realize that the Appium server layer added features. I was avoiding running the Appium wrapper because we need to jump through some hoops to get things to run in our Windows test environment, so I wanted to avoid having to configure node.js there. We get more features though so it could be worth the extra work. I will close for now. Thanks. |
implementation of endpoints can be found here: https://github.com/appium/appium/blob/e8886ae0d276ac4f97a1bdb88998fc30fbd936fa/packages/base-driver/lib/protocol/routes.js#L648
They don't have modern documentation for this but there is some old documentation found here:
https://appium.readthedocs.io/en/latest/en/commands/device/files/push-file/
https://appium.readthedocs.io/en/latest/en/commands/device/files/pull-file/
https://appium.readthedocs.io/en/latest/en/commands/device/files/pull-folder/