fix: guard profile auth and logout
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const profileHtml = fs.readFileSync(path.join(__dirname, '..', 'profile.html'), 'utf8');
|
||||
const profileCommon = fs.readFileSync(path.join(__dirname, '..', 'public', 'js', 'profile-common.js'), 'utf8');
|
||||
|
||||
assert.match(profileHtml, /data-logout-confirm/);
|
||||
assert.match(profileHtml, /<a class="btn primary magnetic" href="index\.html" data-logout-confirm>/);
|
||||
assert.match(profileHtml, /<span>退出登录<\/span><b>返回首页<\/b>/);
|
||||
assert.match(profileCommon, /function performLogout\(targetUrl\)/);
|
||||
assert.match(profileCommon, /api\.logout\(\)/);
|
||||
assert.match(profileCommon, /targetUrl \|\| 'index\.html'/);
|
||||
|
||||
console.log('profile logout structure tests passed');
|
||||
@@ -61,6 +61,22 @@ function run() {
|
||||
districtCode: undefined
|
||||
});
|
||||
|
||||
assert.strictEqual(ProfilePages.shouldRedirectToHome({
|
||||
getToken: () => ''
|
||||
}), true);
|
||||
assert.strictEqual(ProfilePages.shouldRedirectToHome({
|
||||
getToken: () => 'token-x'
|
||||
}), false);
|
||||
assert.strictEqual(ProfilePages.shouldRedirectToHome({
|
||||
getToken: () => 'token-x'
|
||||
}, { status: 401 }), true);
|
||||
assert.strictEqual(ProfilePages.shouldRedirectToHome({
|
||||
getToken: () => 'token-x'
|
||||
}, { code: 401 }), true);
|
||||
assert.strictEqual(ProfilePages.shouldRedirectToHome({
|
||||
getToken: () => 'token-x'
|
||||
}, { status: 500 }), false);
|
||||
|
||||
console.log('profile-pages tests passed');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user