Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests #346

Merged
merged 7 commits into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ example/auth0.js
.gitignore
coverage

.idea/
.idea/
7 changes: 4 additions & 3 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ <h2>Console:</h2>
$('.login-db').click(function (e) {
e.preventDefault();
webAuth.redirect.loginWithCredentials({
connection: 'tests',
connection: 'acme',
username: $('.login-username').val(),
password: $('.login-password').val(),
scope: 'openid'
Expand Down Expand Up @@ -276,7 +276,7 @@ <h2>Console:</h2>
$('.client-login-db').click(function (e) {
e.preventDefault();
webAuth.client.login({
realm: 'tests',
realm: 'acme',
username: $('.client-login-username').val(),
password: $('.client-login-password').val(),
scope: 'openid profile',
Expand Down Expand Up @@ -339,12 +339,13 @@ <h2>Console:</h2>
webAuth.renewAuth({
usePostMessage: true,
scope:'',
audience: 'https://auth0-tests-auth0js.auth0.com/userinfo',
audience: 'https://brucke.auth0.com/userinfo',
redirectURI: 'http://localhost:3000/example/callback.html'
},
htmlConsole.dumpCallback.bind(htmlConsole)
);
});
$(document.body).append($('<div class="loaded">LOADED</div>'));
</script>
</body>
</html>
69 changes: 69 additions & 0 deletions example/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html>
<head>
<title>Auth0.js Demo Examples</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="/auth0.js"></script>
</head>
<body class="container">

<input id="login-username" value="" />
<input id="login-password" type="password" value="" />
<input id="login-scope" value="" />
<input id="login-response-type" value="" />
<input type="button" class="login-redirect-usernamepassword" value="redirect usernamepassword" />
<input type="button" class="login-redirect-authorize" value="redirect authorize" />

<div id="err"></div>
<div id="result"></div>

<script type="text/javascript">

var webAuth = new auth0.WebAuth({
domain: 'auth0-tests-auth0js.auth0.com',
redirectUri: window.location.href,
clientID: '3GGMIEuBPZ28lb6NBDNARaEZisqFakAs',
leeway: 30
});

$('.login-redirect-usernamepassword').click(function (e) {
e.preventDefault();

webAuth.redirect.loginWithCredentials({
connection: 'tests',
username: $('#login-username').val(),
password: $('#login-password').val(),
scope: $('#login-scope').val(),
responseType: $('#login-response-type').val()
}, function (err) {
$('#err').html(JSON.stringify(err));
});
});

$('.login-redirect-authorize').click(function (e) {
e.preventDefault();

webAuth.authorize({
scope: $('#login-scope').val(),
responseType: $('#login-response-type').val()
});
});

webAuth.parseHash(function (err, result) {
if (err) {
$('#err').html(JSON.stringify(err));
$(document.body).append($('<div id="parsed"></div>'));
}

if (result) {
$('#result').html(JSON.stringify(result));
$(document.body).append($('<div id="parsed"></div>'));
}
});

$( document ).ready(function() {
$(document.body).append($('<div id="loaded"></div>'));
});
</script>
</body>
</html>
164 changes: 164 additions & 0 deletions integration/redirect_authorize.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
var expect = require('expect.js');
var selenium = require('./selenium');

describe('redirect authorize', function () {
this.timeout(9999999);

selenium.runTests((clientFactory, webdriver, browser) => {
var By = webdriver.By;
var until = webdriver.until;

it('[token] should result in a successful transaction ' + browser, function () {
var driver = clientFactory();

driver.get('https://auth0.github.io/auth0.js/example/test.html');
driver.wait(until.elementLocated(By.id('loaded')), 10000);
driver.findElement(By.id('login-response-type')).sendKeys('token');
driver.findElement(By.className('login-redirect-authorize')).click();
driver.wait(until.elementLocated(By.id('hlploaded')), 30000);
driver.findElement(By.id('email')).sendKeys('johnfoo@gmail.com');
driver.findElement(By.id('password')).sendKeys('1234');
driver.findElement(By.id('upLogin')).click();
driver.wait(until.elementLocated(By.id('parsed')), 10000);

driver.findElement(By.id('err')).getText().then(function(value) {
console.log('ERR:', value ? value : '-empty-');
expect(value).to.equal('');
});
driver.findElement(By.id('result')).getText().then(function(value) {
console.log('RESULT:', value);
expect(value).to.not.equal('');

var response = JSON.parse(value);

expect(response.accessToken).to.be.ok();
expect(response.idToken).to.not.be.ok();
expect(response.tokenType).to.be.ok();
expect(response.expiresIn).to.be.ok();
});

return driver.quit();
});

it('[code] should result in a successful transaction ' + browser, function () {
var driver = clientFactory();

driver.get('https://auth0.github.io/auth0.js/example/test.html');
driver.wait(until.elementLocated(By.id('loaded')), 10000);
driver.findElement(By.id('login-response-type')).sendKeys('code');
driver.findElement(By.className('login-redirect-authorize')).click();
driver.wait(until.elementLocated(By.id('hlploaded')), 30000);
driver.findElement(By.id('email')).sendKeys('johnfoo@gmail.com');
driver.findElement(By.id('password')).sendKeys('1234');
driver.findElement(By.id('upLogin')).click();
driver.wait(until.elementLocated(By.id('loaded')), 10000);

driver.getCurrentUrl().then(function(url) {
console.log('RESULT URL:', url);
expect(url).to.contain('code=');
});

return driver.quit();
});

it('[token openid] should result in a successful transaction ' + browser, function () {
var driver = clientFactory();

driver.get('https://auth0.github.io/auth0.js/example/test.html');
driver.wait(until.elementLocated(By.id('loaded')), 10000);
driver.findElement(By.id('login-scope')).sendKeys('openid');
driver.findElement(By.id('login-response-type')).sendKeys('token');
driver.findElement(By.className('login-redirect-authorize')).click();
driver.wait(until.elementLocated(By.id('hlploaded')), 30000);
driver.findElement(By.id('email')).sendKeys('johnfoo@gmail.com');
driver.findElement(By.id('password')).sendKeys('1234');
driver.findElement(By.id('upLogin')).click();
driver.wait(until.elementLocated(By.id('parsed')), 10000);

driver.findElement(By.id('err')).getText().then(function(value) {
console.log('ERR:', value ? value : '-empty-');
expect(value).to.equal('');
});

driver.findElement(By.id('result')).getText().then(function(value) {
console.log('RESULT:', value);
expect(value).to.not.equal('');

var response = JSON.parse(value);

expect(response.accessToken).to.be.ok();
expect(response.idToken).to.be.ok();
expect(response.tokenType).to.be.ok();
expect(response.expiresIn).to.be.ok();
});

return driver.quit();
});

it('[id_token] should result in a successful transaction ' + browser, function () {
var driver = clientFactory();

driver.get('https://auth0.github.io/auth0.js/example/test.html');
driver.wait(until.elementLocated(By.id('loaded')), 10000);
driver.findElement(By.id('login-response-type')).sendKeys('id_token');
driver.findElement(By.className('login-redirect-authorize')).click();
driver.wait(until.elementLocated(By.id('hlploaded')), 30000);
driver.findElement(By.id('email')).sendKeys('johnfoo@gmail.com');
driver.findElement(By.id('password')).sendKeys('1234');
driver.findElement(By.id('upLogin')).click();
driver.wait(until.elementLocated(By.id('parsed')), 10000);

driver.findElement(By.id('err')).getText().then(function(value) {
console.log('ERR:', value ? value : '-empty-');
expect(value).to.equal('');
});

driver.findElement(By.id('result')).getText().then(function(value) {
console.log('RESULT:', value);
expect(value).to.not.equal('');

var response = JSON.parse(value);

expect(response.accessToken).to.not.be.ok();
expect(response.idToken).to.be.ok();
expect(response.tokenType).to.not.be.ok();
expect(response.expiresIn).to.not.be.ok();
});

return driver.quit();
});

it('[token id_token] should result in a successful transaction ' + browser, function () {
var driver = clientFactory();

driver.get('https://auth0.github.io/auth0.js/example/test.html');
driver.wait(until.elementLocated(By.id('loaded')), 10000);
driver.findElement(By.id('login-response-type')).sendKeys('token id_token');
driver.findElement(By.className('login-redirect-authorize')).click();
driver.wait(until.elementLocated(By.id('hlploaded')), 30000);
driver.findElement(By.id('email')).sendKeys('johnfoo@gmail.com');
driver.findElement(By.id('password')).sendKeys('1234');
driver.findElement(By.id('upLogin')).click();
driver.wait(until.elementLocated(By.id('parsed')), 10000);

driver.findElement(By.id('err')).getText().then(function(value) {
console.log('ERR:', value ? value : '-empty-');
expect(value).to.equal('');
});

driver.findElement(By.id('result')).getText().then(function(value) {
console.log('RESULT:', value);
expect(value).to.not.equal('');

var response = JSON.parse(value);

expect(response.accessToken).to.be.ok();
expect(response.idToken).to.be.ok();
expect(response.tokenType).to.be.ok();
expect(response.expiresIn).to.be.ok();
});

return driver.quit();
});
})
});
35 changes: 35 additions & 0 deletions integration/redirect_usernamepassword.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var expect = require('expect.js');
var selenium = require('./selenium');

describe('redirect usernamepassword', function () {
this.timeout(9999999);

selenium.runTests((clientFactory, webdriver, browser) => {
var By = webdriver.By;
var until = webdriver.until;

it('should result in a successful transaction ' + browser, function () {
var driver = clientFactory();

driver.get('https://auth0.github.io/auth0.js/example/test.html');
driver.wait(until.elementLocated(By.id('loaded')), 10000);
driver.findElement(By.id('login-response-type')).sendKeys('token');
driver.findElement(By.id('login-scope')).sendKeys('openid');
driver.findElement(By.id('login-username')).sendKeys('johnfoo@gmail.com');
driver.findElement(By.id('login-password')).sendKeys('1234');
driver.findElement(By.className('login-redirect-usernamepassword')).click();
driver.wait(until.elementLocated(By.id('parsed')), 10000);

driver.findElement(By.id('err')).getText().then(function(value) {
console.log('ERR:', value ? value : '-empty-');
expect(value).to.equal('');
});

driver.findElement(By.id('result')).getText().then(function(value) {
expect(value).to.not.equal('');
});

return driver.quit();
});
})
});
65 changes: 65 additions & 0 deletions integration/selenium.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
var webdriver = require('selenium-webdriver');

var username = process.env.SAUCELABS_USER;
var accessKey = process.env.SAUCELABS_KEY;

var capabilities = [
{
'browserName': 'chrome',
'platform': 'Windows 10',
'version': '55.0'
},
{
'browserName': 'chrome',
'platform': 'Windows 10',
'version': 'beta'
},
{
'browserName': 'firefox',
'platform': 'Windows 10',
'version': '50.0'
},
{
'browserName': 'firefox',
'platform': 'Windows 10',
'version': 'beta'
},
{
'browserName': 'internet explorer',
'platform': 'Windows 7',
'version': '11.0'
},
{
'browserName': 'internet explorer',
'platform': 'Windows 7',
'version': '10.0'
},
// {
// 'browserName': 'MicrosoftEdge',
// 'platform': 'Windows 10',
// 'version': '13.10586'
// },
{
'browserName': 'safari',
'platform': 'macOS 10.12',
'version': '10.0'
}
];

module.exports = {
runTests: (tests) => {
capabilities.forEach((capability) => {
var browser = capability.browserName + ' ' + capability.version + ' ' + capability.platform;

tests(() => {
return new webdriver.Builder()
.withCapabilities(capability)
.usingServer("http://" + username + ":" + accessKey + "@ondemand.saucelabs.com:80/wd/hub")
.build();
},
webdriver,
browser,
capability);
});
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"start": "gulp dev",
"build": "gulp build",
"test": "mocha test/**/*.test.js",
"test:integration": "mocha-parallel-tests --max-parallel 2 integration/**/*.test.js",
"test:watch": "mocha --watch -R min test/**/*.test.js",
"test:coverage": "istanbul cover _mocha -R test/**/*",
"test:ci": "istanbul cover _mocha --report lcovonly -R test/**/* && codecov",
Expand Down Expand Up @@ -48,6 +49,8 @@
"istanbul": "^0.4.5",
"jsdoc-to-markdown": "^2.0.1",
"mocha": "^3.2.0",
"mocha-parallel-tests": "^1.2.5",
"selenium-webdriver": "^3.0.1",
"semver": "^5.3.0",
"sinon": "^1.17.6",
"smart-banner-webpack-plugin": "^2.0.0",
Expand Down
Loading