Skip to content

Commit

Permalink
Merge branch 'master' of github.com:auth0/lock into scroll-global-loc…
Browse files Browse the repository at this point in the history
…k-message-into-view

# Conflicts:
#	README.md
#	src/core/index.js
  • Loading branch information
midler committed Jun 13, 2017
2 parents f7cbf8c + 9351ab2 commit 9dae1ec
Show file tree
Hide file tree
Showing 23 changed files with 246 additions and 82 deletions.
87 changes: 43 additions & 44 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,60 @@
"use strict";
'use strict';

const path = require("path");
const fs = require("fs");
const pkg = require("./package");
const webpack = require("webpack");
const webpackConfig = require("./webpack.config.js");
const UnminifiedWebpackPlugin = require("unminified-webpack-plugin");
const path = require('path');
const fs = require('fs');
const pkg = require('./package');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
const UnminifiedWebpackPlugin = require('unminified-webpack-plugin');

module.exports = function (grunt) {

const pkg_info = grunt.file.readJSON("package.json");
module.exports = function(grunt) {
const pkg_info = grunt.file.readJSON('package.json');

grunt.initConfig({
pkg: pkg_info,
clean: {
build: ["build/"],
dev: ["build/"],
dist: ["lib/"]
build: ['build/'],
dev: ['build/'],
dist: ['lib/']
},
babel: {
dist: {
files: [
{
expand: true,
cwd: "src",
src: ["**/*.js", "**/*.jsx"],
dest: "lib",
cwd: 'src',
src: ['**/*.js', '**/*.jsx'],
dest: 'lib',
ext: '.js'
}
]
}
},
env: {
build: {
NODE_ENV: "production"
NODE_ENV: 'production'
}
},
exec: {
touch_index: "touch src/index.js"
touch_index: 'touch src/index.js'
},
webpack: {
options: webpackConfig,
build: {
devtool: "source-map",
devtool: 'source-map',
output: {
path: path.join(__dirname, "build"),
path: path.join(__dirname, 'build'),
filename: 'lock.min.js'
},
watch: false,
devtool: 'source-map',
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.AggressiveMergingPlugin(),
Expand All @@ -74,63 +72,64 @@ module.exports = function (grunt) {
]
}
},
"webpack-dev-server": {
'webpack-dev-server': {
options: {
webpack: webpackConfig,
publicPath: "/build/"
publicPath: '/build/'
},
dev: {
hot: true,
port: 3000,
https: true,
webpack: {
devtool: "eval"
devtool: 'eval'
}
},
design: {
webpack: {
entry: './support/design/index.js',
output: {
path: path.join(__dirname, "build"),
path: path.join(__dirname, 'build'),
filename: 'lock.design.js'
},
devtool: "eval"
devtool: 'eval'
}
}
},
"i18n": {
i18n: {
build: {
files: [
{
expand: true,
cwd: "lib/i18n",
src: "**/*.js",
dest: "build",
cwd: 'lib/i18n',
src: '**/*.js',
dest: 'build',
ext: '.js'
}
]
}
}
});

grunt.loadNpmTasks("grunt-babel");
grunt.loadNpmTasks("grunt-webpack");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-env");
grunt.loadNpmTasks("grunt-exec");
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-exec');

grunt.registerTask("build", ["clean:build", "env:build", "webpack:build", "i18n:build"]);
grunt.registerTask("dist", ["clean:dist", "babel:dist"]);
grunt.registerTask("prepare_dev", ["clean:dev"]);
grunt.registerTask("dev", ["prepare_dev", "webpack-dev-server:dev"]);
grunt.registerTask("design", ["prepare_dev", "webpack-dev-server:design"]);
grunt.registerMultiTask("i18n", "Prepares i18n files to be hosted in CDN", function () {
grunt.registerTask('build', ['clean:build', 'env:build', 'webpack:build', 'i18n:build']);
grunt.registerTask('dist', ['clean:dist', 'babel:dist']);
grunt.registerTask('prepare_dev', ['clean:dev']);
grunt.registerTask('dev', ['prepare_dev', 'webpack-dev-server:dev']);
grunt.registerTask('design', ['prepare_dev', 'webpack-dev-server:design']);
grunt.registerMultiTask('i18n', 'Prepares i18n files to be hosted in CDN', function() {
var languages = {};
var Auth0 = {
registerLanguageDictionary: function (lang, dict) {
registerLanguageDictionary: function(lang, dict) {
languages[lang] = dict;
}
};
this.files.forEach(function (file) {
this.files.forEach(function(file) {
var filename = file.src[0];
var lang = path.basename(filename, '.js');
var dict = require('./' + filename).default || require('./' + filename);
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ The appearance of the widget and the mechanics of authentication can be customiz
- **flashMessage {Object}**: Shows an `error` or `success` flash message when Lock is shown.
+ **type {String}**: The message type, it should be `error` or `success`.
+ **text {String}**: The text to show.
- **allowAutocomplete {Boolean}**: Determines whether or not the the email or username inputs will allow autocomplete (`<input autocomplete />`). Defaults to `false`.
- **scrollGlobalMessagesIntoView {Boolean}**: Determines whether or not a globalMessage should be scrolled into the user's viewport. Defaults to `false`.

#### Theming options
Expand Down Expand Up @@ -464,8 +465,6 @@ This project is licensed under the MIT license. See the [LICENSE](LICENSE) file
[circleci-url]: https://circleci.com/gh/auth0/lock/tree/master
[npm-image]: https://img.shields.io/npm/v/auth0-lock.svg?style=flat-square
[npm-url]: https://npmjs.org/package/auth0-lock
[david-image]: http://img.shields.io/david/auth0/lock.svg?style=flat-square
[david-url]: https://david-dm.org/auth0/lock
[license-image]: http://img.shields.io/npm/l/auth0-lock.svg?style=flat-square
[license-url]: #license
[downloads-image]: http://img.shields.io/npm/dm/auth0-lock.svg?style=flat-square
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"zuul-ngrok": "4.0.0"
},
"dependencies": {
"auth0-js": "~8.6.0",
"auth0-js": "~8.7.0",
"blueimp-md5": "2.3.1",
"fbjs": "^0.3.1",
"idtoken-verifier": "^1.0.1",
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/core/web_api/__snapshots__/p2_api.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Object {
}
`;

exports[`Auth0APIClient logIn with credentials should fail when in popup mode 1`] = `"Cross origin login is not supported in popup mode"`;

exports[`Auth0APIClient logIn with social/enterprise (without username and email) should call authorize when redirect===true 1`] = `
Object {
"nonce": undefined,
Expand Down
21 changes: 21 additions & 0 deletions src/__tests__/core/web_api/helper.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import expect from 'expect.js';
import { webAuthOverrides } from 'core/web_api/helper';

describe('webAuthOverrides', () => {
it('should return overrides if any field is compatible with WebAuth', function() {
expect(webAuthOverrides({ __tenant: 'tenant1', __token_issuer: 'issuer1' })).to.eql({
__tenant: 'tenant1',
__token_issuer: 'issuer1'
});
});

it('should omit overrides that are not compatible with WebAuth', function() {
expect(
webAuthOverrides({ __tenant: 'tenant1', __token_issuer: 'issuer1', backgroundColor: 'blue' })
).to.eql({ __tenant: 'tenant1', __token_issuer: 'issuer1' });
});

it('should return null if no fields are compatible with WebAuth', function() {
expect(webAuthOverrides({ backgroundColor: 'blue' })).to.not.be.ok();
});
});
14 changes: 14 additions & 0 deletions src/__tests__/core/web_api/legacy_api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ describe('Auth0LegacyAPIClient', () => {
jest.resetModules();
});

describe('with overwrites', () => {
it('should configure WebAuth with the proper overrides', () => {
const client = getClient({
overrides: {
__tenant: 'tenant1',
__token_issuer: 'issuer1'
}
});
const mock = getAuth0ClientMock();
const { overrides } = mock.WebAuth.mock.calls[0][0];
expect(overrides).toEqual({ __tenant: 'tenant1', __token_issuer: 'issuer1' });
});
});

describe('logIn', () => {
const assertCallWithCallback = (mock, callbackFunction) => {
expect(mock.calls.length).toBe(1);
Expand Down
27 changes: 25 additions & 2 deletions src/__tests__/core/web_api/p2_api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ describe('Auth0APIClient', () => {
beforeEach(() => {
jest.resetModules();
});
describe('init', () => {
describe('with overwrites', () => {
it('should configure WebAuth with the proper overrides', () => {
const client = getClient({
overrides: {
__tenant: 'tenant1',
__token_issuer: 'issuer1'
}
});
const mock = getAuth0ClientMock();
const { overrides } = mock.WebAuth.mock.calls[0][0];
expect(overrides).toEqual({ __tenant: 'tenant1', __token_issuer: 'issuer1' });
});
});
});
describe('logIn', () => {
const assertCallWithCallback = (mock, callbackFunction) => {
expect(mock.calls.length).toBe(1);
Expand Down Expand Up @@ -51,12 +66,20 @@ describe('Auth0APIClient', () => {
});
});
describe('with credentials', () => {
it('should fail when in popup mode', () => {
const client = getClient({
redirect: false
});
expect(() => client.logIn({ username: 'foo' }, {})).toThrowErrorMatchingSnapshot();
});
it('should call client.login', () => {
const client = getClient();
const client = getClient({
redirect: true
});
const callback = jest.fn();
client.logIn({ username: 'foo' }, {}, callback);
const mock = getAuth0ClientMock();
const loginMock = mock.WebAuth.mock.instances[0].client.login.mock;
const loginMock = mock.WebAuth.mock.instances[0].login.mock;
assertCallWithCallback(loginMock, callback);
});
});
Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/field/__snapshots__/email_pane.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Array [
exports[`EmailPane renders correctly 1`] = `
<div
data-__type="email_input"
data-autoComplete={false}
data-invalidHint="invalidErrorHint"
data-isValid={false}
data-onChange={[Function]}
Expand All @@ -24,6 +25,7 @@ exports[`EmailPane renders correctly 1`] = `
exports[`EmailPane sets \`blankErrorHint\` when username is empty 1`] = `
<div
data-__type="email_input"
data-autoComplete={false}
data-invalidHint="blankErrorHint"
data-isValid={false}
data-onChange={[Function]}
Expand All @@ -32,9 +34,22 @@ exports[`EmailPane sets \`blankErrorHint\` when username is empty 1`] = `
/>
`;

exports[`EmailPane sets autoComplete to true when \`allowAutocomplete\` is true 1`] = `
<div
data-__type="email_input"
data-autoComplete={true}
data-invalidHint="invalidErrorHint"
data-isValid={false}
data-onChange={[Function]}
data-placeholder="placeholder"
data-value="[email protected]"
/>
`;

exports[`EmailPane sets isValid as true when \`isFieldVisiblyInvalid\` is false 1`] = `
<div
data-__type="email_input"
data-autoComplete={false}
data-invalidHint="invalidErrorHint"
data-isValid={true}
data-onChange={[Function]}
Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/field/__snapshots__/username_pane.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Array [
exports[`UsernamePane renders correctly 1`] = `
<div
data-__type="username_input"
data-autoComplete={false}
data-invalidHint="invalidErrorHint"
data-isValid={false}
data-onChange={[Function]}
Expand All @@ -26,6 +27,7 @@ exports[`UsernamePane renders correctly 1`] = `
exports[`UsernamePane sets \`blankErrorHint\` when username is empty 1`] = `
<div
data-__type="username_input"
data-autoComplete={false}
data-invalidHint="blankErrorHint"
data-isValid={false}
data-onChange={[Function]}
Expand All @@ -37,6 +39,7 @@ exports[`UsernamePane sets \`blankErrorHint\` when username is empty 1`] = `
exports[`UsernamePane sets \`usernameFormatErrorHint\` when usernameLooksLikeEmail() returns false and \`validateFormat\` is true 1`] = `
<div
data-__type="username_input"
data-autoComplete={false}
data-invalidHint="usernameFormatErrorHint,min,max"
data-isValid={false}
data-onChange={[Function]}
Expand All @@ -45,9 +48,22 @@ exports[`UsernamePane sets \`usernameFormatErrorHint\` when usernameLooksLikeEma
/>
`;

exports[`UsernamePane sets autoComplete to true when \`allowAutocomplete\` is true 1`] = `
<div
data-__type="username_input"
data-autoComplete={true}
data-invalidHint="invalidErrorHint"
data-isValid={false}
data-onChange={[Function]}
data-placeholder="placeholder"
data-value="username"
/>
`;

exports[`UsernamePane sets isValid as true when \`isFieldVisiblyInvalid\` is false 1`] = `
<div
data-__type="username_input"
data-autoComplete={false}
data-invalidHint="invalidErrorHint"
data-isValid={true}
data-onChange={[Function]}
Expand Down
Loading

0 comments on commit 9dae1ec

Please sign in to comment.