diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2018-01-10 20:10:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-10 20:10:40 +0100 |
commit | 03a7d9bbfafa10934f4d94216a3f174a5dcffab4 (patch) | |
tree | 809694d26021f582a2cf10730826654f9b31ea66 /core | |
parent | 4823ac969a1fc917e1efab4d2b84028d932cb56b (diff) | |
parent | 9c22e99331fe7261c575bc26e2381d78c189521d (diff) | |
download | nextcloud-server-03a7d9bbfafa10934f4d94216a3f174a5dcffab4.tar.gz nextcloud-server-03a7d9bbfafa10934f4d94216a3f174a5dcffab4.zip |
Merge pull request #7635 from Abijeet/bug-7106
Fixes password input being prompted every time.
Diffstat (limited to 'core')
-rw-r--r-- | core/js/js.js | 7 | ||||
-rw-r--r-- | core/js/tests/specs/coreSpec.js | 61 |
2 files changed, 66 insertions, 2 deletions
diff --git a/core/js/js.js b/core/js/js.js index f9a5f2b3381..872761c02bb 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1675,13 +1675,16 @@ function initCore() { OC.PasswordConfirmation = { callback: null, - + pageLoadTime: null, init: function() { $('.password-confirm-required').on('click', _.bind(this.requirePasswordConfirmation, this)); + this.pageLoadTime = moment.now(); }, requiresPasswordConfirmation: function() { - var timeSinceLogin = moment.now() - (nc_lastLogin * 1000); + var serverTimeDiff = this.pageLoadTime - (nc_pageLoad * 1000); + var timeSinceLogin = moment.now() - (serverTimeDiff + (nc_lastLogin * 1000)); + // if timeSinceLogin > 30 minutes and user backend allows password confirmation return (backendAllowsPasswordConfirmation && timeSinceLogin > 30 * 60 * 1000); }, diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index b6c617303cf..616e7509f7c 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -1539,4 +1539,65 @@ describe('Core base tests', function() { expect(snapperStub.close.calledTwice).toBe(true); }); }); + describe('Requires password confirmation', function () { + var stubMomentNow; + var stubJsPageLoadTime; + + afterEach(function () { + delete window.nc_pageLoad; + delete window.nc_lastLogin; + delete window.backendAllowsPasswordConfirmation; + + stubMomentNow.restore(); + stubJsPageLoadTime.restore(); + }); + + it('should not show the password confirmation dialog when server time is earlier than local time', function () { + // add server variables + window.nc_pageLoad = parseInt(new Date(2018, 0, 3, 1, 15, 0).getTime() / 1000); + window.nc_lastLogin = parseInt(new Date(2018, 0, 3, 1, 0, 0).getTime() / 1000); + window.backendAllowsPasswordConfirmation = true; + + stubJsPageLoadTime = sinon.stub(OC.PasswordConfirmation, 'pageLoadTime').value(new Date(2018, 0, 3, 12, 15, 0).getTime()); + stubMomentNow = sinon.stub(moment, 'now').returns(new Date(2018, 0, 3, 12, 20, 0).getTime()); + + expect(OC.PasswordConfirmation.requiresPasswordConfirmation()).toBeFalsy(); + }); + + it('should show the password confirmation dialog when server time is earlier than local time', function () { + // add server variables + window.nc_pageLoad = parseInt(new Date(2018, 0, 3, 1, 15, 0).getTime() / 1000); + window.nc_lastLogin = parseInt(new Date(2018, 0, 3, 1, 0, 0).getTime() / 1000); + window.backendAllowsPasswordConfirmation = true; + + stubJsPageLoadTime = sinon.stub(OC.PasswordConfirmation, 'pageLoadTime').value(new Date(2018, 0, 3, 12, 15, 0).getTime()); + stubMomentNow = sinon.stub(moment, 'now').returns(new Date(2018, 0, 3, 12, 31, 0).getTime()); + + expect(OC.PasswordConfirmation.requiresPasswordConfirmation()).toBeTruthy(); + }); + + it('should not show the password confirmation dialog when server time is later than local time', function () { + // add server variables + window.nc_pageLoad = parseInt(new Date(2018, 0, 3, 23, 15, 0).getTime() / 1000); + window.nc_lastLogin = parseInt(new Date(2018, 0, 3, 23, 0, 0).getTime() / 1000); + window.backendAllowsPasswordConfirmation = true; + + stubJsPageLoadTime = sinon.stub(OC.PasswordConfirmation, 'pageLoadTime').value(new Date(2018, 0, 3, 12, 15, 0).getTime()); + stubMomentNow = sinon.stub(moment, 'now').returns(new Date(2018, 0, 3, 12, 20, 0).getTime()); + + expect(OC.PasswordConfirmation.requiresPasswordConfirmation()).toBeFalsy(); + }); + + it('should show the password confirmation dialog when server time is later than local time', function () { + // add server variables + window.nc_pageLoad = parseInt(new Date(2018, 0, 3, 23, 15, 0).getTime() / 1000); + window.nc_lastLogin = parseInt(new Date(2018, 0, 3, 23, 0, 0).getTime() / 1000); + window.backendAllowsPasswordConfirmation = true; + + stubJsPageLoadTime = sinon.stub(OC.PasswordConfirmation, 'pageLoadTime').value(new Date(2018, 0, 3, 12, 15, 0).getTime()); + stubMomentNow = sinon.stub(moment, 'now').returns(new Date(2018, 0, 3, 12, 31, 0).getTime()); + + expect(OC.PasswordConfirmation.requiresPasswordConfirmation()).toBeTruthy(); + }); + }); }); |