diff --git a/installer/frontend/ui-tests/commands/setFileField.js b/installer/frontend/ui-tests/commands/setFileField.js new file mode 100644 index 0000000000..2fc57b10d0 --- /dev/null +++ b/installer/frontend/ui-tests/commands/setFileField.js @@ -0,0 +1,9 @@ +const fs = require('fs'); + +exports.command = function (selector, text) { + this.expect.element(selector).to.be.present; + + // eslint-disable-next-line no-sync + fs.writeFileSync(this.globals.tmpUploadPath, text); + return this.setValue(selector, this.globals.tmpUploadPath); +}; diff --git a/installer/frontend/ui-tests/commands/testFileTextCombo.js b/installer/frontend/ui-tests/commands/testFileTextCombo.js new file mode 100644 index 0000000000..99482c1f91 --- /dev/null +++ b/installer/frontend/ui-tests/commands/testFileTextCombo.js @@ -0,0 +1,20 @@ +exports.command = function (fileSelector, textSelector, validText, invalidText, invalidMsg) { + this + .setField(textSelector, 'abc') + .expectValidationErrorContains(invalidMsg) + .setFileField(fileSelector, validText) + .expectNoValidationError() + .expect.element(textSelector).to.have.value.that.equals(validText); + + this + .setFileField(fileSelector, invalidText) + .expectValidationErrorContains(invalidMsg) + .expect.element(textSelector).to.have.value.that.equals(invalidText); + + this + .setFileField(fileSelector, validText) + .expectNoValidationError() + .expect.element(textSelector).to.have.value.that.equals(validText); + + return this; +}; diff --git a/installer/frontend/ui-tests/globals.js b/installer/frontend/ui-tests/globals.js index 2c745b58db..731961ed8d 100644 --- a/installer/frontend/ui-tests/globals.js +++ b/installer/frontend/ui-tests/globals.js @@ -1,4 +1,5 @@ const chromedriver = require('chromedriver'); +const path = require('path'); module.exports = { default: { @@ -14,4 +15,6 @@ module.exports = { chromedriver.stop(); done(); }, + + tmpUploadPath: path.join(path.resolve(__dirname), 'tmp-upload-test'), }; diff --git a/installer/frontend/ui-tests/pages/clusterInfoPage.js b/installer/frontend/ui-tests/pages/clusterInfoPage.js index fbb74a54f4..ffbee56e4e 100644 --- a/installer/frontend/ui-tests/pages/clusterInfoPage.js +++ b/installer/frontend/ui-tests/pages/clusterInfoPage.js @@ -1,20 +1,8 @@ const _ = require('lodash'); const fs = require('fs'); -const path = require('path'); const clusterInfoPageCommands = { test (json, platform) { - const parentDir = path.resolve(__dirname, '..'); - const licensePath = path.join(parentDir, 'tectonic-license.txt'); - const configPath = path.join(parentDir, 'config.json'); - - /* eslint-disable no-sync */ - const tectonic_license = fs.readFileSync(process.env.TF_VAR_tectonic_license_path, 'utf8'); - const pull_secret = fs.readFileSync(process.env.TF_VAR_tectonic_pull_secret_path, 'utf8'); - fs.writeFileSync(licensePath, tectonic_license); - fs.writeFileSync(configPath, pull_secret); - /* eslint-enable no-sync */ - this.setField('@name', 'a%$#b'); if (platform === 'aws-tf') { this.expectValidationErrorContains('must be a valid AWS Stack Name'); @@ -26,8 +14,10 @@ const clusterInfoPageCommands = { this.setField('@name', json.clusterName); this.expectNoValidationError(); - this.setValue('@licenseUpload', licensePath); - this.setValue('@pullSecretUpload', configPath); + /* eslint-disable no-sync */ + this.setFileField('@licenseUpload', fs.readFileSync(process.env.TF_VAR_tectonic_license_path, 'utf8')); + this.setFileField('@pullSecretUpload', fs.readFileSync(process.env.TF_VAR_tectonic_pull_secret_path, 'utf8')); + /* eslint-enable no-sync */ if (platform === 'aws-tf' && !_.isEmpty(json.awsTags)) { this diff --git a/installer/frontend/ui-tests/pages/matchboxCredentialsPage.js b/installer/frontend/ui-tests/pages/matchboxCredentialsPage.js index 0ecc80cb24..2ecb698e4f 100644 --- a/installer/frontend/ui-tests/pages/matchboxCredentialsPage.js +++ b/installer/frontend/ui-tests/pages/matchboxCredentialsPage.js @@ -1,49 +1,30 @@ -const fs = require('fs'); -const path = require('path'); - const pageCommands = { test (json) { - const parentDir = path.resolve(__dirname, '..'); - const caCertPath = path.join(parentDir, 'ca-cert.txt'); - const clientCertPath = path.join(parentDir, 'client-cert.txt'); - const clientKeyPath = path.join(parentDir, 'client-key.txt'); - - /* eslint-disable no-sync */ - fs.writeFileSync(caCertPath, json.matchboxCA); - fs.writeFileSync(clientCertPath, json.matchboxClientCert); - fs.writeFileSync(clientKeyPath, json.matchboxClientKey); - /* eslint-enable no-sync */ - - this - .setValue('@caCert', clientKeyPath) - .expectValidationErrorContains('Invalid certificate') - .setValue('@caCert', caCertPath) - .expectNoValidationError() - .setValue('@clientCert', clientKeyPath) - .expectValidationErrorContains('Invalid certificate') - .setValue('@clientCert', clientCertPath) - .expectNoValidationError() - .setValue('@clientKey', caCertPath) - .expectValidationErrorContains('Invalid private key') - .setValue('@clientKey', clientKeyPath) - .expectNoValidationError(); + this.testFileTextCombo( + 'input[type=file]#matchboxCA', + 'textarea#matchboxCA', + json.matchboxCA, + json.matchboxClientKey, + 'Invalid certificate' + ); + this.testFileTextCombo( + 'input[type=file]#matchboxClientCert', + 'textarea#matchboxClientCert', + json.matchboxClientCert, + json.matchboxClientKey, + 'Invalid certificate' + ); + this.testFileTextCombo( + 'input[type=file]#matchboxClientKey', + 'textarea#matchboxClientKey', + json.matchboxClientKey, + json.matchboxCA, + 'Invalid private key' + ); }, }; module.exports = { commands: [pageCommands], - elements: { - caCert: { - selector: '(//*[text()="Upload"]/input[@type="file"])[1]', - locateStrategy: 'xpath', - }, - clientCert: { - selector: '(//*[text()="Upload"]/input[@type="file"])[2]', - locateStrategy: 'xpath', - }, - clientKey: { - selector: '(//*[text()="Upload"]/input[@type="file"])[3]', - locateStrategy: 'xpath', - }, - }, + elements: {}, }; diff --git a/installer/frontend/ui-tests/pages/sshKeysPage.js b/installer/frontend/ui-tests/pages/sshKeysPage.js index f1165de114..88f010de8b 100644 --- a/installer/frontend/ui-tests/pages/sshKeysPage.js +++ b/installer/frontend/ui-tests/pages/sshKeysPage.js @@ -1,29 +1,16 @@ -const fs = require('fs'); -const path = require('path'); - const pageCommands = { test (json) { - const parentDir = path.resolve(__dirname, '..'); - const sshKeyPath = path.join(parentDir, 'ssh-keys.txt'); - - /* eslint-disable no-sync */ - fs.writeFileSync(sshKeyPath, json.sshAuthorizedKey); - - this - .setField('@key', 'abc') - .expectValidationErrorContains('Invalid SSH pubkey') - .setValue('@upload', sshKeyPath) - .expectNoValidationError(); + this.testFileTextCombo( + 'input[type=file]#sshAuthorizedKey', + 'textarea#sshAuthorizedKey', + json.sshAuthorizedKey, + 'abc', + 'Invalid SSH pubkey' + ); }, }; module.exports = { commands: [pageCommands], - elements: { - key: 'textarea#sshAuthorizedKey', - upload: { - selector: '(//*[text()="Upload"]/input[@type="file"])', - locateStrategy: 'xpath', - }, - }, + elements: {}, }; diff --git a/installer/frontend/ui-tests/tests/aws.js b/installer/frontend/ui-tests/tests/aws.js index e57b4f3424..9964010369 100644 --- a/installer/frontend/ui-tests/tests/aws.js +++ b/installer/frontend/ui-tests/tests/aws.js @@ -1,3 +1,5 @@ +const fs = require('fs'); + const log = require('../utils/log'); const wizard = require('../utils/wizard'); const tfvarsUtil = require('../utils/terraformTfvars'); @@ -42,6 +44,7 @@ const toExport = { }, after (client) { + fs.unlink(client.globals.tmpUploadPath); client.getLog('browser', log.logger); client.end(); }, diff --git a/installer/frontend/ui-tests/tests/metal.js b/installer/frontend/ui-tests/tests/metal.js index 122a44c155..57f92a5d3c 100644 --- a/installer/frontend/ui-tests/tests/metal.js +++ b/installer/frontend/ui-tests/tests/metal.js @@ -1,3 +1,5 @@ +const fs = require('fs'); + const log = require('../utils/log'); const wizard = require('../utils/wizard'); const tfvarsUtil = require('../utils/terraformTfvars'); @@ -46,6 +48,7 @@ const toExport = { }, after (client) { + fs.unlink(client.globals.tmpUploadPath); client.getLog('browser', log.logger); client.end(); },