Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Correa committed Oct 17, 2017
1 parent aa5b33a commit 38c1cd2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 159 deletions.
2 changes: 1 addition & 1 deletion lib/patchRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { promisify } from 'bluebird';
import { ManagementClient } from 'auth0';
import generateRule from '../rules/link';

const RULE_NAME = 'account-linking';
const RULE_NAME = 'auth0-account-link-extension';
const readFileAsync = promisify(readFile);

/**
Expand Down
41 changes: 21 additions & 20 deletions sample-app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@ const strategy = new Auth0Strategy(
domain: process.env.AUTH0_DOMAIN,
clientID: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
callbackURL: process.env.AUTH0_CALLBACK_URL || 'http://localhost:3000/callback'
callbackURL:
process.env.AUTH0_CALLBACK_URL || 'http://localhost:3000/callback'
},
((accessToken, refreshToken, extraParams, profile, done) =>
function(accessToken, refreshToken, extraParams, profile, done) {
// accessToken is the token to call Auth0 API (not needed in the most cases)
// extraParams.id_token has the JSON Web Token
// profile has all the information from the user
done(null, profile)
)
return done(null, profile);
}
);

passport.use(strategy);

// you can use this section to keep a smaller payload
passport.serializeUser((user, done) => {
passport.serializeUser(function(user, done) {
done(null, user);
});

passport.deserializeUser((user, done) => {
passport.deserializeUser(function(user, done) {
done(null, user);
});

Expand All @@ -49,7 +50,7 @@ app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
Expand All @@ -68,20 +69,20 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use(flash());

// Handle auth failure error messages
app.use((req, res, next) => {
if (req && req.query && req.query.error) {
req.flash('error', req.query.error);
}
if (req && req.query && req.query.error_description) {
req.flash('error_description', req.query.error_description);
}
next();
app.use(function(req, res, next) {
if (req && req.query && req.query.error) {
req.flash("error", req.query.error);
}
if (req && req.query && req.query.error_description) {
req.flash("error_description", req.query.error_description);
}
next();
});

// Check logged in
app.use((req, res, next) => {
app.use(function(req, res, next) {
res.locals.loggedIn = false;
if (req.session.passport && typeof req.session.passport.user !== 'undefined') {
if (req.session.passport && typeof req.session.passport.user != 'undefined') {
res.locals.loggedIn = true;
}
next();
Expand All @@ -91,7 +92,7 @@ app.use('/', routes);
app.use('/user', user);

// catch 404 and forward to error handler
app.use((req, res, next) => {
app.use(function(req, res, next) {
const err = new Error('Not Found');
err.status = 404;
next(err);
Expand All @@ -102,7 +103,7 @@ app.use((req, res, next) => {
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use((err, req, res, next) => {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
Expand All @@ -113,7 +114,7 @@ if (app.get('env') === 'development') {

// production error handler
// no stacktraces leaked to user
app.use((err, req, res, next) => {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
Expand Down
1 change: 0 additions & 1 deletion sample-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"express": "^4.14.1",
"express-session": "^1.11.3",
"morgan": "^1.8.1",
"nconf": "^0.8.5",
"passport": "^0.3.0",
"passport-auth0": "^0.6.0",
"pug": "~2.0.0-beta11",
Expand Down
114 changes: 3 additions & 111 deletions sample-app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ amdefine@>=0.0.4:
version "1.0.1"
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"

ansi-regex@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"

[email protected]:
version "1.1.1"
resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2"
Expand All @@ -64,10 +60,6 @@ [email protected], assert-plus@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525"

async@^1.4.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
Expand Down Expand Up @@ -127,10 +119,6 @@ camelcase@^1.0.2:
version "1.2.1"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39"

camelcase@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-2.1.1.tgz#7c1d16d679a1bbe59ca02cacecfb011e201f5a1f"

caseless@~0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
Expand Down Expand Up @@ -163,22 +151,10 @@ cliui@^2.1.0:
right-align "^0.1.1"
wordwrap "0.0.2"

cliui@^3.0.3:
version "3.2.0"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-3.2.0.tgz#120601537a916d29940f934da3b48d585a39213d"
dependencies:
string-width "^1.0.1"
strip-ansi "^3.0.1"
wrap-ansi "^2.0.0"

co@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"

code-point-at@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"

combined-stream@^1.0.5, combined-stream@~1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009"
Expand Down Expand Up @@ -255,7 +231,7 @@ [email protected], debug@^2.6.1:
dependencies:
ms "2.0.0"

decamelize@^1.0.0, decamelize@^1.1.1:
decamelize@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"

Expand Down Expand Up @@ -316,8 +292,8 @@ express-session@^1.11.3:
utils-merge "1.0.1"

express@^4.14.1:
version "4.16.1"
resolved "https://registry.yarnpkg.com/express/-/express-4.16.1.tgz#6b33b560183c9b253b7b62144df33a4654ac9ed0"
version "4.16.2"
resolved "https://registry.yarnpkg.com/express/-/express-4.16.2.tgz#e35c6dfe2d64b7dca0a5cd4f21781be3299e076c"
dependencies:
accepts "~1.3.4"
array-flatten "1.1.1"
Expand Down Expand Up @@ -463,14 +439,6 @@ [email protected]:
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"

ini@^1.3.0:
version "1.3.4"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e"

invert-kv@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6"

[email protected]:
version "1.5.2"
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.5.2.tgz#d4b505bde9946987ccf0fc58d9010ff9607e3fa0"
Expand All @@ -493,12 +461,6 @@ is-expression@^3.0.0:
acorn "~4.0.2"
object-assign "^4.0.1"

is-fullwidth-code-point@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz#ef9e31386f031a7f0d643af82fde50c457ef00cb"
dependencies:
number-is-nan "^1.0.0"

is-promise@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa"
Expand Down Expand Up @@ -573,12 +535,6 @@ lazy-cache@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"

lcid@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lcid/-/lcid-1.0.0.tgz#308accafa0bc483a3867b4b6f2b9506251d1b835"
dependencies:
invert-kv "^1.0.0"

longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
Expand Down Expand Up @@ -623,23 +579,10 @@ [email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"

nconf@^0.8.5:
version "0.8.5"
resolved "https://registry.yarnpkg.com/nconf/-/nconf-0.8.5.tgz#f2941e1561952fa906bbb32328cf88d4c635e794"
dependencies:
async "^1.4.0"
ini "^1.3.0"
secure-keys "^1.0.0"
yargs "^3.19.0"

[email protected]:
version "0.6.1"
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"

number-is-nan@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"

oauth-sign@~0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43"
Expand All @@ -662,12 +605,6 @@ on-headers@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/on-headers/-/on-headers-1.0.1.tgz#928f5d0f470d49342651ea6794b0857c100693f7"

os-locale@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-1.4.0.tgz#20f9f17ae29ed345e8bde583b13d2009803c14d9"
dependencies:
lcid "^1.0.0"

parseurl@~1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.2.tgz#fc289d4ed8993119460c156253262cdc8de65bf3"
Expand Down Expand Up @@ -909,10 +846,6 @@ [email protected], safe-buffer@^5.0.1, safe-buffer@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"

secure-keys@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/secure-keys/-/secure-keys-1.0.0.tgz#f0c82d98a3b139a8776a8808050b824431087fca"

[email protected]:
version "0.16.1"
resolved "https://registry.yarnpkg.com/send/-/send-0.16.1.tgz#a70e1ca21d1382c11d0d9f6231deb281080d7ab3"
Expand Down Expand Up @@ -992,24 +925,10 @@ sshpk@^1.7.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"

string-width@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"
dependencies:
code-point-at "^1.0.0"
is-fullwidth-code-point "^1.0.0"
strip-ansi "^3.0.0"

stringstream@~0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878"

strip-ansi@^3.0.0, strip-ansi@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"
dependencies:
ansi-regex "^2.0.0"

[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/token-stream/-/token-stream-0.0.1.tgz#ceeefc717a76c4316f126d0b9dbaa55d7e7df01a"
Expand Down Expand Up @@ -1092,10 +1011,6 @@ [email protected]:
version "0.1.0"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d"

window-size@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.4.tgz#f8e1aa1ee5a53ec5bf151ffa09742a6ad7697876"

with@^5.0.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/with/-/with-5.1.1.tgz#fa4daa92daf32c4ea94ed453c81f04686b575dfe"
Expand All @@ -1107,33 +1022,10 @@ [email protected]:
version "0.0.2"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f"

wrap-ansi@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"
dependencies:
string-width "^1.0.1"
strip-ansi "^3.0.1"

xtend@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"

y18n@^3.2.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41"

yargs@^3.19.0:
version "3.32.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.32.0.tgz#03088e9ebf9e756b69751611d2a5ef591482c995"
dependencies:
camelcase "^2.0.1"
cliui "^3.0.3"
decamelize "^1.1.1"
os-locale "^1.4.0"
string-width "^1.0.1"
window-size "^0.1.4"
y18n "^3.2.0"

yargs@~3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"
Expand Down
32 changes: 6 additions & 26 deletions test/puppeteer/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,12 @@ describe('Account linking tests', () => {

it('detects repeated email and links account', async () => {
await createUsers();

await page.waitForSelector('#link');
await page.click('#link');

await wait(1);

await page.waitForSelector('input[name="email"]');
await page.click('input[name="email"]');
await page.type(testEmail);

await wait(1);

await page.click('input[name="password"]');
await page.type(testPassword);

await wait(1);

await page.waitForSelector('.auth0-lock-submit');
await page.click('.auth0-lock-submit');

await wait(1);

await page.type(testEmail);

await page.click('.auth0-lock-submit');

await wait(1);

await page.waitForNavigation();


expect(await usersWithSameEmailCount(testEmail)).equal(1);
expect(await page.url()).equal(app`/user`);
});
Expand All @@ -65,6 +42,9 @@ describe('Account linking tests', () => {

await page.evaluate(() => document.querySelector('#skip').click());

await page.waitForNavigation();
await page.click('#allow');

await page.waitForNavigation();
expect(await usersWithSameEmailCount(testEmail)).equal(2);
expect(await page.url()).equal(app`/user`);
Expand Down

0 comments on commit 38c1cd2

Please sign in to comment.