Conversation
| * @param {string} base64Data - Base-64 encoded content of the file to be uploaded. | ||
| */ | ||
| async function pushFileToSimulator (device, remotePath, base64Data) { | ||
| if (_.isArray(base64Data)) { |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
I asume the encoding is binary/ascii here
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
is Buffer.from supposed to work before Node8? Or Babel takes care of this?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
I'll take care of it. But there are still many older versions in the wild
There was a problem hiding this comment.
usually people update server much more frequently than the client
|
Thanks @jlipps |
|
Looks good, though the file movement tests fail. For the other test, see #606 |
|
@jlipps Do you have time to finish this PR? |
|
@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
ddf6112 to
2181b1d
Compare
|
ok, fixes pushed. a couple things to note:
|
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'); |
There was a problem hiding this comment.
so how about adding base64-data patch here?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
@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.
* 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
* 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
* 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
* 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
* 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
* 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
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
pullFilewas getting executed by the ios-driver code 🤕