From 9bf97c60ee16815ecaf02a47a406b2ef61c98c3e Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Wed, 25 Nov 2015 00:28:22 -0800 Subject: [PATCH] Add selenium tests --- test/git_ssh_wrapper.sh | 5 +++ test/id_rsa | 27 ++++++++++++++++ test/id_rsa.pub | 1 + test/test.js | 72 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100755 test/git_ssh_wrapper.sh create mode 100644 test/id_rsa create mode 100644 test/id_rsa.pub diff --git a/test/git_ssh_wrapper.sh b/test/git_ssh_wrapper.sh new file mode 100755 index 0000000..c5e95d9 --- /dev/null +++ b/test/git_ssh_wrapper.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +ssh -o IdentitiesOnly=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${SCRIPT_DIR}/id_rsa "$@" diff --git a/test/id_rsa b/test/id_rsa new file mode 100644 index 0000000..7fbe791 --- /dev/null +++ b/test/id_rsa @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEA14L+HdwPXRHC2A+fyRv1FTsRE/OPl0Z0KnEigzIIdA65CzTy +l3m3ATNFI1o/Ies7RW6rsr9UHuLLufNVg1NwIBdns8sPE4pSZSjfdPnznifIIs7y +wL/vn2D3JEhpA8EOasSy0c+z+6X23evsLB3D81y7ICsBc16Q147WZ6D+QMUP+A4b +wlmEcy0hAoPx/jnnPlRDVOK1ZnBvuAaHBkcBh+sA272BhB6Kv13MBu0wctDjKw5w +cNmgVWbzBBtK1L8BZVMDKmKWZ2PKP4GkkpnAvkD0+4sdARe148faV8HHigAKKNN7 +vt+njs6nHuS4ksJL1E9cKGHdBJudJc3p24iI7QIDAQABAoIBABm5ojnQPek/KIIA +A3PPKYc6QMSf60EEgPNcA+GjRE0OQNpsnJSmS8kR5KvepvC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BrMLLvhE5niaGu4jQOa +ZVY6nZUQNCwgxJwnUkFnOyXDYjzjyxZOCAWPxghYbS+IEl1GzhZU +-----END RSA PRIVATE KEY----- diff --git a/test/id_rsa.pub b/test/id_rsa.pub new file mode 100644 index 0000000..013bb1f --- /dev/null +++ b/test/id_rsa.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXgv4d3A9dEcLYD5/JG/UVOxET84+XRnQqcSKDMgh0DrkLNPKXebcBM0UjWj8h6ztFbquyv1Qe4su581WDU3AgF2ezyw8TilJlKN90+fOeJ8gizvLAv++fYPckSGkDwQ5qxLLRz7P7pfbd6+wsHcPzXLsgKwFzXpDXjtZnoP5AxQ/4DhvCWYRzLSECg/H+Oec+VENU4rVmcG+4BocGRwGH6wDbvYGEHoq/XcwG7TBy0OMrDnBw2aBVZvMEG0rUvwFlUwMqYpZnY8o/gaSSmcC+QPT7ix0BF7Xjx9pXwceKAAoo03u+36eOzqce5LiSwkvUT1woYd0Em50lzenbiIjt girish@beast diff --git a/test/test.js b/test/test.js index 97e9bd7..b58c65b 100755 --- a/test/test.js +++ b/test/test.js @@ -12,20 +12,31 @@ var execSync = require('child_process').execSync, superagent = require('superagent'), webdriver = require('selenium-webdriver'); +var firefox = require('selenium-webdriver/firefox'); +var server, browser = new firefox.Driver(); +var by = require('selenium-webdriver').By, + until = require('selenium-webdriver').until; + process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; describe('Application life cycle test', function () { this.timeout(0); + var server, browser = new require('selenium-webdriver/firefox').Driver(); before(function () { var seleniumJar= require('selenium-server-standalone-jar'); var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer; - var server = new SeleniumServer(seleniumJar.path, { port: 4444 }); + server = new SeleniumServer(seleniumJar.path, { port: 4444 }); server.start(); }); + after(function () { + browser.quit(); + server.stop(); + }); + var LOCATION = 'test' + Date.now(); - var app; + var app, reponame = 'testrepo'; var username = process.env.USERNAME; var password = process.env.PASSWORD; @@ -54,6 +65,56 @@ describe('Application life cycle test', function () { }); }); + it('can login', function (done) { + browser.get('https://' + app.fqdn + '/user/login'); + browser.findElement(by.id('user_name')).sendKeys(username); + browser.findElement(by.id('password')).sendKeys(password); + browser.findElement(by.tagName('form')).submit(); + browser.wait(until.elementLocated(by.linkText('Dashboard')), 4000); + done(); + }); + + it('can add public key', function (done) { + browser.get('https://' + app.fqdn + '/user/settings/ssh'); + var publicKey = fs.readFileSync(__dirname + '/id_rsa.pub', 'utf8'); + + browser.findElement(by.xpath('//div[text()="Add Key"]')).click(); + browser.findElement(by.id('title')).sendKeys('testkey'); + browser.findElement(by.id('content')).sendKeys(publicKey); + browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')).click(); + browser.wait(until.elementLocated(by.xpath('p[contains(text(), "added successfully!")]')), 4000); + done(); + }); + + it('can create repo', function (done) { + browser.get('https://' + app.fqdn); + browser.findElement(by.linkText('New Repository')).click(); + browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "New Repository")]')), 4000); + browser.findElement(by.id('repo_name')).sendKeys(reponame); + browser.findElement(by.id('auto-init')).click(); + browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')).click(); + browser.wait(function () { + return browser.getCurrentUrl().then(function (url) { + return url === 'https://' + app.fqdn + '/' + username + '/' + reponame; + }); + }, 4000); + done(); + }); + + it('displays correct clone url', function (done) { + browser.get('https://' + app.fqdn + '/' + username + '/' + reponame); + browser.findElement(by.id('repo-clone-url')).getAttribute('value').then(function (cloneUrl) { + expect(cloneUrl).to.be('ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git'); + done(); + }); + }); + + it('can clone the url', function (done) { + execSync('git clone ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git /tmp/testrepo', { env: { GIT_SSH : __dirname + '/git_ssh_wrapper.sh' } }); + rimraf.sync('/tmp/testrepo'); + done(); + }); + it('backup app', function () { execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); }); @@ -62,8 +123,13 @@ describe('Application life cycle test', function () { execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); }); + it('can clone the url', function (done) { + execSync('git clone ssh://cloudron@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git /tmp/testrepo', { env: { GIT_SSH : __dirname + '/git_ssh_wrapper.sh' } }); + rimraf.sync('/tmp/testrepo'); + done(); + }); + it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); }); }); -