1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
/*!
* Piwik - free/libre analytics platform
*
* Screenshot integration tests.
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
describe("TwoFactorAuth", function () {
this.timeout(0);
this.fixture = "Piwik\\Plugins\\TwoFactorAuth\\tests\\Fixtures\\TwoFactorFixture";
var generalParams = 'idSite=1&period=day&date=2010-01-03',
userSettings = '?module=UsersManager&action=userSettings&' + generalParams,
logoutUrl = '?module=Login&action=logout&period=day&date=yesterday';
function selectModalButton(page, button)
{
page.click('.modal.open .modal-footer a:contains('+button+')');
}
function loginUser(page, username, doAuth)
{
// make sure to log out previous session
page.load(logoutUrl);
if (typeof doAuth === 'undefined') {
doAuth = true;
}
var logMeUrl = '?module=Login&action=logme&login=' + username + '&password=240161a241087c28d92d8d7ff3b6186b';
if (doAuth) {
logMeUrl += '&authCode=123456'; // we make sure in test config this code always works
}
page.wait(1000);
page.load(logMeUrl);
}
function requireTwoFa() {
testEnvironment.requireTwoFa = 1;
testEnvironment.save();
}
function fakeCorrectAuthCode() {
testEnvironment.fakeCorrectAuthCode = 1;
testEnvironment.save();
}
before(function () {
testEnvironment.pluginsToLoad = ['TwoFactorAuth'];
testEnvironment.queryParamOverride = { date: '2018-03-04' };
testEnvironment.save();
});
beforeEach(function () {
testEnvironment.testUseMockAuth = 0;
testEnvironment.restoreRecoveryCodes = 1;
testEnvironment.save();
});
afterEach(function () {
delete testEnvironment.requireTwoFa;
delete testEnvironment.restoreRecoveryCodes;
delete testEnvironment.fakeCorrectAuthCode;
testEnvironment.testUseMockAuth = 1;
testEnvironment.save();
});
function confirmPassword(page)
{
page.wait(1000);
page.sendKeys('.confirmPasswordForm #login_form_password', '123abcDk3_l3');
page.click('.confirmPasswordForm #login_form_submit');
}
function captureScreen(done, screenshotName, test, selector) {
if (!selector) {
selector = '.loginSection,#content,#notificationContainer';
}
expect.screenshot(screenshotName).to.be.captureSelector(selector, test, done);
}
function captureUserSettings(done, screenshotName, test, selector) {
captureScreen(done, screenshotName, test, '.userSettings2FA');
}
function captureModal(done, screenshotName, test, selector) {
captureScreen(done, screenshotName, test, '.modal.open');
}
it('a user with 2fa can open the widgetized view by token without needing to verify', function (done) {
captureScreen(done, 'widgetized_no_verify', function (page) {
page.load('?module=Widgetize&action=iframe&moduleToWidgetize=Actions&actionToWidgetize=getPageUrls&date=2018-03-04&token_auth=c4ca4238a0b923820dcc509a6f75849b&' + generalParams);
});
});
it('when logging in through logme and not providing auth code it should show auth code screen', function (done) {
captureScreen(done, 'logme_not_verified', function (page) {
loginUser(page, 'with2FA', false);
});
});
it('when logging in and providing wrong code an error is shown', function (done) {
captureScreen(done, 'logme_not_verified_wrong_code', function (page) {
page.sendKeys('.loginTwoFaForm #login_form_authcode', '555555');
page.click('.loginTwoFaForm #login_form_submit');
});
});
it('when logging in through logme and verifying screen it works to access ui', function (done) {
captureScreen(done, 'logme_verified', function (page) {
page.sendKeys('.loginTwoFaForm #login_form_authcode', '123456');
page.click('.loginTwoFaForm #login_form_submit');
});
});
it('should show user settings when two-fa enabled', function (done) {
captureUserSettings(done, 'usersettings_twofa_enabled', function (page) {
loginUser(page, 'with2FA');
page.load(userSettings);
});
});
it('should be possible to show recovery codes step1 authentication', function (done) {
captureScreen(done, 'show_recovery_codes_step1', function (page) {
page.click('.showRecoveryCodesLink');
});
});
it('should be possible to show recovery codes step2 done', function (done) {
captureScreen(done, 'show_recovery_codes_step2', function (page) {
confirmPassword(page);
});
});
it('should show user settings when two-fa enabled', function (done) {
captureUserSettings(done, 'usersettings_twofa_enabled_required', function (page) {
requireTwoFa();
page.load(userSettings);
});
});
it('should be possible to disable two factor', function (done) {
captureModal(done, 'usersettings_twofa_disable_step1', function (page) {
loginUser(page, 'with2FADisable');
page.load(userSettings);
page.click('.disable2FaLink');
});
});
it('should be possible to disable two factor step 2 confirmed', function (done) {
captureScreen(done, 'usersettings_twofa_disable_step2', function (page) {
selectModalButton(page, 'Yes');
});
});
it('should be possible to disable two factor step 3 verified', function (done) {
captureUserSettings(done, 'usersettings_twofa_disable_step3', function (page) {
confirmPassword(page);
});
});
it('should show setup screen - step 1', function (done) {
captureScreen(done, 'twofa_setup_step1', function (page) {
loginUser(page, 'without2FA');
page.load(userSettings);
page.click('.enable2FaLink');
confirmPassword(page);
});
});
it('should move to second step in setup - step 2', function (done) {
captureScreen(done, 'twofa_setup_step2', function (page) {
page.click('.setupTwoFactorAuthentication .backupRecoveryCode:first');
page.click('.setupTwoFactorAuthentication .goToStep2');
page.evaluate(function () {
$('#qrcode').hide();
});
});
});
it('should move to third step in setup - step 3', function (done) {
captureScreen(done, 'twofa_setup_step3', function (page) {
page.click('.setupTwoFactorAuthentication .goToStep3');
});
});
it('should move to third step in setup - step 4 confirm', function (done) {
captureScreen(done, 'twofa_setup_step4', function (page) {
fakeCorrectAuthCode();
page.sendKeys('.setupConfirmAuthCodeForm input[type=text]', '123458');
page.evaluate(function () {
$('.setupConfirmAuthCodeForm input[type=text]').change();
});
page.evaluate(function () {
$('.setupConfirmAuthCodeForm .confirmAuthCode').click();
});
});
});
it('should force user to setup 2fa when not set up yet but enforced', function (done) {
captureScreen(done, 'twofa_forced_step1', function (page) {
requireTwoFa();
loginUser(page, 'no2FA', false);
});
});
it('should force user to setup 2fa when not set up yet but enforced step 2', function (done) {
captureScreen(done, 'twofa_forced_step2', function (page) {
page.click('.setupTwoFactorAuthentication .backupRecoveryCode:first');
page.click('.setupTwoFactorAuthentication .goToStep2');
});
});
it('should force user to setup 2fa when not set up yet but enforced step 3', function (done) {
captureScreen(done, 'twofa_forced_step3', function (page) {
page.click('.setupTwoFactorAuthentication .goToStep3');
});
});
it('should force user to setup 2fa when not set up yet but enforced confirm code', function (done) {
captureScreen(done, 'twofa_forced_step4', function (page) {
requireTwoFa();
fakeCorrectAuthCode();
page.sendKeys('.setupConfirmAuthCodeForm input[type=text]', '123458');
page.evaluate(function () {
$('.setupConfirmAuthCodeForm input[type=text]').change();
});
page.evaluate(function () {
$('.setupConfirmAuthCodeForm .confirmAuthCode').click();
});
});
});
});
|