diff --git a/resources/frontend_client/app/admin/people/components/AdminPeople.react.js b/resources/frontend_client/app/admin/people/components/AdminPeople.react.js index 668d4a6d4d9cd829fbd1246c03da375994060b1c..5d950b16360670477138912a97084114de3aa01c 100644 --- a/resources/frontend_client/app/admin/people/components/AdminPeople.react.js +++ b/resources/frontend_client/app/admin/people/components/AdminPeople.react.js @@ -108,7 +108,7 @@ export default class AdminPeople extends Component { } else { // generate a password - const password = MetabaseUtils.generatePassword(); + const password = MetabaseUtils.generatePassword(14, MetabaseSettings.get('password_complexity')); // trigger the reset this.props.dispatch(resetPasswordManually(user, password)); diff --git a/resources/frontend_client/test/unit/lib/utils.spec.js b/resources/frontend_client/test/unit/lib/utils.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..44bfab2f99d58642b4cdbc24b79ea5134a06fe1e --- /dev/null +++ b/resources/frontend_client/test/unit/lib/utils.spec.js @@ -0,0 +1,57 @@ +'use strict'; +/*eslint-env jasmine */ + +import MetabaseUtils from 'metabase/lib/utils'; + + +describe('utils', () => { + describe('generatePassword', () => { + it('defaults to length 14 passwords', () => { + expect( + MetabaseUtils.generatePassword().length + ).toBe( + 14 + ); + }); + + it('creates passwords for the length we specify', () => { + expect( + MetabaseUtils.generatePassword(25).length + ).toBe( + 25 + ); + }); + + it('can enforce ', () => { + expect( + (MetabaseUtils.generatePassword(14, {digit: 2}).match(/([\d])/g).length >= 2) + ).toBe( + true + ); + }); + + it('can enforce digit requirements', () => { + expect( + (MetabaseUtils.generatePassword(14, {digit: 2}).match(/([\d])/g).length >= 2) + ).toBe( + true + ); + }); + + it('can enforce uppercase requirements', () => { + expect( + (MetabaseUtils.generatePassword(14, {uppercase: 2}).match(/([A-Z])/g).length >= 2) + ).toBe( + true + ); + }); + + it('can enforce special character requirements', () => { + expect( + (MetabaseUtils.generatePassword(14, {special: 2}).match(/([\?\-])/g).length >= 2) + ).toBe( + true + ); + }); + }); +});