Skip to content

move file movement commands#605

Closed
jlipps wants to merge 3 commits intomasterfrom
jlipps-pushFile-fix
Closed

move file movement commands#605
jlipps wants to merge 3 commits intomasterfrom
jlipps-pushFile-fix

Conversation

@jlipps
Copy link
Copy Markdown
Member

@jlipps jlipps commented Jan 16, 2018

before, the ios commands were overriding pushFile and pullFile
these commands really belong in file-movement anyway
also, fix up the incorrect use of tempDir
also, fix up the fact that some clients send in weird byte arrays instead of strings, silly java

so much stuff was broken in here! @mykola-mokhnach we must not have tests for this, because pullFile was getting executed by the ios-driver code 🤕

* @param {string} base64Data - Base-64 encoded content of the file to be uploaded.
*/
async function pushFileToSimulator (device, remotePath, base64Data) {
if (_.isArray(base64Data)) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hard to tell what changed in the copy, this is where some of the new code is

if (_.isArray(base64Data)) {
// some clients (ahem) java, send a byte array encoding utf8 characters
// instead of a string, which would be infinitely better!
base64Data = Buffer.from(base64Data).toString('utf8');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I asume the encoding is binary/ascii here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

according to the code used in the java client, the client sends a byte stream of bytes, each byte is a utf8 char, which is part of a base64 string. so to get the b64-encoded string we need to decode utf8 bytes. silly java client!

// instead of a string, which would be infinitely better!
base64Data = Buffer.from(base64Data).toString('utf8');
}
const buf = Buffer.from(base64Data, 'base64');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is Buffer.from supposed to work before Node8? Or Babel takes care of this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah, it's supported from node 5

* @param {string} base64Data - Base-64 encoded content of the file to be uploaded.
*/
async function pushFileToRealDevice (device, remotePath, base64Data) {
await verifyIFusePresence();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we do the same base64 transformation here? perhaps, the transformation itself might be moved to appium-support, since it might be useful for Android as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah, yes we should. i mean really what we should do is fix the client, because it should be sending a string. i just needed something i could fix faster than the java client :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'll take care of it. But there are still many older versions in the wild

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

usually people update server much more frequently than the client

@mykola-mokhnach
Copy link
Copy Markdown
Contributor

Thanks @jlipps

@imurchie
Copy link
Copy Markdown
Contributor

Looks good, though the file movement tests fail.

For the other test, see #606

@mykola-mokhnach
Copy link
Copy Markdown
Contributor

@jlipps Do you have time to finish this PR?

@jlipps
Copy link
Copy Markdown
Member Author

jlipps commented Jan 23, 2018

@mykola-mokhnach yeah i'll take a look at the failed tests

before, the ios commands were overriding pushFile and pullFile
these commands really belong in file-movement anyway
also, fix up the incorrect use of tempDir
also, fix up the fact that some clients send in weird byte arrays instead of strings, silly java
@jlipps jlipps force-pushed the jlipps-pushFile-fix branch from ddf6112 to 2181b1d Compare January 23, 2018 23:27
@jlipps
Copy link
Copy Markdown
Member Author

jlipps commented Jan 23, 2018

ok, fixes pushed. a couple things to note:

  1. there are some screen recording unit tests failing, seems unrelated
  2. this is the first time this package will export the pushFile and pullFile commands that are now being tested. they have a different API than ios-driver's, so this should be technically considered a breaking change
  3. pullFolder has not been rewritten according to the new style, so it retains ios-driver's API, which is probably confusing that it would work differently. @mykola-mokhnach want to add pullFolder support on this branch?

@mykola-mokhnach
Copy link
Copy Markdown
Contributor

pullFolder has not been rewritten according to the new style, so it retains ios-driver's API, which is probably confusing that it would work differently. @mykola-mokhnach want to add pullFolder support on this branch?

Maybe later when I have time. I don't see this API endpoint is used often.

log.debug(`The destination folder '${path.dirname(dstPath)}' does not exist. Creating...`);
await fs.mkdir(path.dirname(dstPath));
}
await fs.writeFile(dstPath, new Buffer(base64Data, 'base64').toString('binary'), 'binary');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so how about adding base64-data patch here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

perhaps, it makes sense to fix it on higher level, inside pushFile call, so then both methods (for a real device and Simulator) will get the fixed data

it('should be able to fetch the Address book', async function () {
let file = 'Library/AddressBook/AddressBook.sqlitedb';
let stringData = await pullFileAsString(file);
let file = '../../../../../Library/AddressBook/AddressBook.sqlitedb';
Copy link
Copy Markdown
Contributor

@mykola-mokhnach mykola-mokhnach Jan 24, 2018

Choose a reason for hiding this comment

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

@jlipps I think you've just found a nice security hole there, which allows to read/write any file on the server. The push/pull methods should contain a security verification, which confirms that absolute path is a subpath of the corresponding container.

mykola-mokhnach pushed a commit that referenced this pull request Feb 6, 2018
* move file movement commands before, the ios commands were overriding pushFile and pullFile these commands really belong in file-movement anyway also, fix up the incorrect use of tempDir also, fix up the fact that some clients send in weird byte arrays instead of strings, silly java

* clean up debug code

* fix up file movement tests

* Add path verification

* Use mkdirp instead of mkdir
@imurchie imurchie deleted the jlipps-pushFile-fix branch July 23, 2018 13:15
dpgraham pushed a commit to dpgraham/appium that referenced this pull request Oct 1, 2018
* move file movement commands before, the ios commands were overriding pushFile and pullFile these commands really belong in file-movement anyway also, fix up the incorrect use of tempDir also, fix up the fact that some clients send in weird byte arrays instead of strings, silly java

* clean up debug code

* fix up file movement tests

* Add path verification

* Use mkdirp instead of mkdir
dpgraham pushed a commit to dpgraham/appium that referenced this pull request Nov 7, 2018
* move file movement commands before, the ios commands were overriding pushFile and pullFile these commands really belong in file-movement anyway also, fix up the incorrect use of tempDir also, fix up the fact that some clients send in weird byte arrays instead of strings, silly java

* clean up debug code

* fix up file movement tests

* Add path verification

* Use mkdirp instead of mkdir
dpgraham pushed a commit to dpgraham/appium-monorepo that referenced this pull request Mar 2, 2019
* move file movement commands before, the ios commands were overriding pushFile and pullFile these commands really belong in file-movement anyway also, fix up the incorrect use of tempDir also, fix up the fact that some clients send in weird byte arrays instead of strings, silly java

* clean up debug code

* fix up file movement tests

* Add path verification

* Use mkdirp instead of mkdir
dpgraham pushed a commit to dpgraham/appium-ios that referenced this pull request Sep 9, 2020
* move file movement commands before, the ios commands were overriding pushFile and pullFile these commands really belong in file-movement anyway also, fix up the incorrect use of tempDir also, fix up the fact that some clients send in weird byte arrays instead of strings, silly java

* clean up debug code

* fix up file movement tests

* Add path verification

* Use mkdirp instead of mkdir
khanayan123 pushed a commit to khanayan123/appium-xcuitest-driver that referenced this pull request May 10, 2021
* move file movement commands before, the ios commands were overriding pushFile and pullFile these commands really belong in file-movement anyway also, fix up the incorrect use of tempDir also, fix up the fact that some clients send in weird byte arrays instead of strings, silly java

* clean up debug code

* fix up file movement tests

* Add path verification

* Use mkdirp instead of mkdir
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