diff --git a/awx/ui/package.json b/awx/ui/package.json index 97031fbffd..335d033aa5 100644 --- a/awx/ui/package.json +++ b/awx/ui/package.json @@ -33,6 +33,7 @@ }, "devDependencies": { "angular-mocks": "~1.6.6", + "archiver": "^2.1.1", "axios": "^0.16.2", "babel-core": "^6.26.0", "babel-istanbul": "^0.12.2", diff --git a/awx/ui/test/e2e/commands/pushFileToWorker.js b/awx/ui/test/e2e/commands/pushFileToWorker.js new file mode 100644 index 0000000000..191164f778 --- /dev/null +++ b/awx/ui/test/e2e/commands/pushFileToWorker.js @@ -0,0 +1,57 @@ +import { basename } from 'path'; +import { EventEmitter } from 'events'; +import { inherits } from 'util'; + +import archiver from 'archiver'; + +function pushFileToWorker (localFilePath, callback) { + const name = basename(localFilePath); + + const push = handler => { + const archive = archiver('zip'); + + const buffers = []; + + archive + .on('data', data => buffers.push(data)) + .on('error', err => { throw err; }) + .on('finish', () => { + const file = Buffer.concat(buffers).toString('base64'); + + this.api.session(session => { + const params = { + path: `/session/${session.sessionId}/file`, + method: 'POST', + data: { file }, + }; + + this.client.runProtocolAction(params, handler).send(); + }); + }); + + archive.file(localFilePath, { name }); + archive.finalize(); + }; + + push(({ status, value }) => { + if (status !== 0) { + throw new Error(value.message); + } + + if (typeof callback === 'function') { + callback.call(this, value); + } + + this.emit('complete'); + }); + + return this; +} + +function PushFileToWorker () { EventEmitter.call(this); } + +inherits(PushFileToWorker, EventEmitter); + +PushFileToWorker.prototype.command = pushFileToWorker; + +module.exports = PushFileToWorker; diff --git a/awx/ui/test/e2e/tests/test-credentials-add-edit-gce-file.js b/awx/ui/test/e2e/tests/test-credentials-add-edit-gce-file.js index 458b735630..cdf871c36a 100644 --- a/awx/ui/test/e2e/tests/test-credentials-add-edit-gce-file.js +++ b/awx/ui/test/e2e/tests/test-credentials-add-edit-gce-file.js @@ -64,7 +64,9 @@ module.exports = { const { details } = credentials.section.add.section; const { gce } = details.section; - gce.section.serviceAccountFile.setValue('form input[type="file"]', GCE_SERVICE_ACCOUNT_FILE); + client.pushFileToWorker(GCE_SERVICE_ACCOUNT_FILE, file => { + gce.section.serviceAccountFile.setValue('form input[type="file"]', file); + }); gce.expect.element('@email').not.enabled; gce.expect.element('@sshKeyData').not.enabled; @@ -100,7 +102,9 @@ module.exports = { const { details } = credentials.section.add.section; const { gce } = details.section; - gce.section.serviceAccountFile.setValue('form input[type="file"]', GCE_SERVICE_ACCOUNT_FILE_MISSING); + client.pushFileToWorker(GCE_SERVICE_ACCOUNT_FILE_MISSING, file => { + gce.section.serviceAccountFile.setValue('form input[type="file"]', file); + }); gce.expect.element('@email').not.enabled; gce.expect.element('@sshKeyData').not.enabled; @@ -142,7 +146,9 @@ module.exports = { const { details } = credentials.section.add.section; const { gce } = details.section; - gce.section.serviceAccountFile.setValue('form input[type="file"]', GCE_SERVICE_ACCOUNT_FILE_INVALID); + client.pushFileToWorker(GCE_SERVICE_ACCOUNT_FILE_INVALID, file => { + gce.section.serviceAccountFile.setValue('form input[type="file"]', file); + }); gce.expect.element('@email').not.enabled; gce.expect.element('@sshKeyData').not.enabled; @@ -184,7 +190,9 @@ module.exports = { const add = credentials.section.add.section.details; const edit = credentials.section.edit.section.details; - add.section.gce.section.serviceAccountFile.setValue('form input[type="file"]', GCE_SERVICE_ACCOUNT_FILE); + client.pushFileToWorker(GCE_SERVICE_ACCOUNT_FILE, file => { + add.section.gce.section.serviceAccountFile.setValue('form input[type="file"]', file); + }); add.section.gce.expect.element('@email').not.enabled; add.section.gce.expect.element('@sshKeyData').not.enabled; @@ -224,7 +232,9 @@ module.exports = { gce.section.project.expect.element('@error').not.present; gce.section.serviceAccountFile.expect.element('@error').not.present; - gce.section.serviceAccountFile.setValue('form input[type="file"]', GCE_SERVICE_ACCOUNT_FILE_ALT); + client.pushFileToWorker(GCE_SERVICE_ACCOUNT_FILE_ALT, file => { + gce.section.serviceAccountFile.setValue('form input[type="file"]', file); + }); gce.expect.element('@serviceAccountFile').enabled;