eslint: add no-shadow

This commit is contained in:
Girish Ramakrishnan
2026-02-18 08:18:37 +01:00
parent 4d3e9dc49b
commit 4ed6fbbd74
40 changed files with 250 additions and 249 deletions
+2 -2
View File
@@ -242,8 +242,8 @@ describe('backup cleaner', function () {
await backupSites.setSchedule(site, '00 00 23 * * *', auditSource);
});
async function cleanupBackups(site) {
const taskId = await backupSites.startCleanupTask(site, auditSource);
async function cleanupBackups(targetSite) {
const taskId = await backupSites.startCleanupTask(targetSite, auditSource);
console.log('started task', taskId);
+15 -15
View File
@@ -70,18 +70,18 @@ describe('backups', function () {
});
it('can get backup site', async function () {
const backupSite = await backupSites.get(defaultBackupSite.id);
expect(backupSite.provider).to.be('filesystem');
expect(backupSite.config.backupDir).to.be.ok(); // the test sets this to some tmp location
expect(backupSite.format).to.be('tgz');
expect(backupSite.encryption).to.be(null);
expect(backupSite.contents).to.be(null);
expect(backupSite.enableForUpdates).to.be(true);
const result = await backupSites.get(defaultBackupSite.id);
expect(result.provider).to.be('filesystem');
expect(result.config.backupDir).to.be.ok(); // the test sets this to some tmp location
expect(result.format).to.be('tgz');
expect(result.encryption).to.be(null);
expect(result.contents).to.be(null);
expect(result.enableForUpdates).to.be(true);
});
it('cannot get random backup site', async function () {
const backupSite = await backupSites.get('random');
expect(backupSite).to.be(null);
const result = await backupSites.get('random');
expect(result).to.be(null);
});
it('can set backup config', async function () {
@@ -100,8 +100,8 @@ describe('backups', function () {
it('can set valid schedule', async function () {
for (const pattern of [ '00 * * * * *', constants.CRON_PATTERN_NEVER ]) {
await backupSites.setSchedule(defaultBackupSite, pattern, auditSource);
const backupSite = await backupSites.get(defaultBackupSite.id);
expect(backupSite.schedule).to.be(pattern);
const result = await backupSites.get(defaultBackupSite.id);
expect(result.schedule).to.be(pattern);
}
});
@@ -113,15 +113,15 @@ describe('backups', function () {
it('can set valid retention', async function () {
for (const retention of [ { keepWithinSecs: 1 }, { keepYearly: 3 }, { keepMonthly: 14 } ]) {
await backupSites.setRetention(defaultBackupSite, retention, auditSource);
const backupSite = await backupSites.get(defaultBackupSite.id);
expect(backupSite.retention).to.eql(retention);
const result = await backupSites.get(defaultBackupSite.id);
expect(result.retention).to.eql(retention);
}
});
it('cannot disable for update', async function () {
await backupSites.setEnabledForUpdates(defaultBackupSite, false, auditSource);
const backupSite = await backupSites.get(defaultBackupSite.id);
expect(backupSite.enableForUpdates).to.eql(false);
const result = await backupSites.get(defaultBackupSite.id);
expect(result.enableForUpdates).to.eql(false);
});
it('can delete all the backup sites', async function () {
+6 -6
View File
@@ -51,17 +51,17 @@ async function ldapSearch(dn, opts, auth) {
bindAuth(function (error) {
if (error) return done(error);
client.search(dn, opts, function (error, result) {
if (error) return done(error);
client.search(dn, opts, function (searchError, searchResult) {
if (searchError) return done(searchError);
const entries = [];
result.on('searchEntry', function (entry) { entries.push(entry.object); });
searchResult.on('searchEntry', function (entry) { entries.push(entry.object); });
result.on('error', done);
searchResult.on('error', done);
result.on('end', function (result) {
if (result.status !== 0) return done(new Error(`Unexpected status: ${result.status}`));
searchResult.on('end', function (endResult) {
if (endResult.status !== 0) return done(new Error(`Unexpected status: ${endResult.status}`));
done(null, entries);
});
});
+2 -2
View File
@@ -131,9 +131,9 @@ describe('Eventlog', function () {
await eventlog._clear();
for (const e of [ eventlog.ACTION_USER_LOGIN, eventlog.ACTION_USER_LOGIN_GHOST, eventlog.ACTION_USER_LOGOUT, eventlog.ACTION_USER_LOGIN ]) {
const eventId = await eventlog.add(e, { ip: '1.2.3.4' }, { appId: 'thatapp' });
const loopEventId = await eventlog.add(e, { ip: '1.2.3.4' }, { appId: 'thatapp' });
await notifications._add(notifications.TYPE_APP_UPDATED, 'title', 'some message', { eventId });
await notifications._add(notifications.TYPE_APP_UPDATED, 'title', 'some message', { eventId: loopEventId });
}
await timers.setTimeout(3000);
+5 -5
View File
@@ -43,12 +43,12 @@ class LdapServer {
this.#provider = provider;
}
setUsers(users) {
this.#users = users;
setUsers(userList) {
this.#users = userList;
}
setGroups(groups) {
this.#groups = groups;
setGroups(groupList) {
this.#groups = groupList;
}
setProvider(provider) {
@@ -187,7 +187,7 @@ class LdapServer {
const commonName = req.dn.rdns[0].attrs[attributeName].value;
if (!commonName) return next(new ldap.NoSuchObjectError('Missing CN'));
const u = this.#users.find(function (u) { return u.username === commonName; });
const u = this.#users.find(function (candidate) { return candidate.username === commonName; });
if (!u) return next(new ldap.NoSuchObjectError('No such user'));
if (req.credentials !== LDAP_SHARED_PASSWORD) return next(new ldap.InvalidCredentialsError('Bad password'));
+2 -2
View File
@@ -50,8 +50,8 @@ async function ldapSearch(dn, opts) {
result.on('error', done);
result.on('end', function (result) {
if (result.status !== 0) return done(new Error(`Unexpected status: ${result.status}`));
result.on('end', function (endResult) {
if (endResult.status !== 0) return done(new Error(`Unexpected status: ${endResult.status}`));
done(null, entries);
});
});
+7 -7
View File
@@ -97,10 +97,10 @@ describe('Storage', function () {
it('can download file', async function () {
const sourceFile = path.join(gBackupConfig.backupDir, gBackupConfig.prefix, '/uploadtest/test.txt');
const [error, stream] = await safe(filesystem.download(gBackupConfig, 'uploadtest/test.txt'));
const [error, downloadStream] = await safe(filesystem.download(gBackupConfig, 'uploadtest/test.txt'));
expect(error).to.be(null);
expect(stream).to.be.an('object');
const data = await consumers.buffer(stream);
expect(downloadStream).to.be.an('object');
const data = await consumers.buffer(downloadStream);
expect(fs.readFileSync(sourceFile)).to.eql(data); // buffer compare
});
@@ -314,8 +314,8 @@ describe('Storage', function () {
}
file(key) { // already has prefix
// console.log('gcs file object:', key);
function getFullWritablePath(key) {
const fullPath = path.join(bucketPathNoPrefix, key);
function getFullWritablePath(keyPath) {
const fullPath = path.join(bucketPathNoPrefix, keyPath);
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
return fullPath;
}
@@ -390,9 +390,9 @@ describe('Storage', function () {
it('can download file', async function () {
const sourceKey = 'uploadtest/test.txt';
const [error, stream] = await safe(gcs.download(backupConfig, sourceKey));
const [error, downloadStream] = await safe(gcs.download(backupConfig, sourceKey));
expect(error).to.be(null);
expect(stream).to.be.an('object');
expect(downloadStream).to.be.an('object');
});
it('list dir lists contents of source dir', async function () {
+13 -13
View File
@@ -82,42 +82,42 @@ describe('task', function () {
});
it('can run valid task - success', async function () {
const taskId = await tasks.add(tasks._TASK_IDENTITY, [ 'ping' ]);
const successTaskId = await tasks.add(tasks._TASK_IDENTITY, [ 'ping' ]);
const [error, result] = await safe(tasks.startTask(taskId, {}));
const [error, result] = await safe(tasks.startTask(successTaskId, {}));
if (error) throw error;
expect(result).to.equal('ping');
});
it('can run valid task - error', async function () {
const taskId = await tasks.add(tasks._TASK_ERROR, [ 'ping' ]);
const errorTaskId = await tasks.add(tasks._TASK_ERROR, [ 'ping' ]);
const [error, result] = await safe(tasks.startTask(taskId, {}));
const [error, result] = await safe(tasks.startTask(errorTaskId, {}));
if (!error) throw new Error('expecting task to fail');
expect(error.message).to.be('Task crashed. Failed for arg: ping');
expect(result).to.not.be.ok();
});
it('can get logs of crash', async function () {
const taskId = await tasks.add(tasks._TASK_CRASH, [ 'ping' ]);
const crashTaskId = await tasks.add(tasks._TASK_CRASH, [ 'ping' ]);
const [error, result] = await safe(tasks.startTask(taskId, {}));
const [error, result] = await safe(tasks.startTask(crashTaskId, {}));
if (!error) throw new Error('expecting task to crash');
expect(error.message).to.contain(`Task ${taskId} crashed`);
expect(error.message).to.contain(`Task ${crashTaskId} crashed`);
expect(result).to.not.be.ok();
const logs = fs.readFileSync(`${paths.TASKS_LOG_DIR}/${taskId}.log`, 'utf8');
const logs = fs.readFileSync(`${paths.TASKS_LOG_DIR}/${crashTaskId}.log`, 'utf8');
expect(logs).to.contain('Crashing for arg: ping');
});
it('can stop task', async function () {
const taskId = await tasks.add(tasks._TASK_SLEEP, [ 10000 ]);
const sleepTaskId = await tasks.add(tasks._TASK_SLEEP, [ 10000 ]);
setTimeout(async function () {
await tasks.stopTask(taskId);
await tasks.stopTask(sleepTaskId);
}, 2000);
const [error, result] = await safe(tasks.startTask(taskId, {}));
const [error, result] = await safe(tasks.startTask(sleepTaskId, {}));
if (!error) throw new Error('expecting task to stop');
expect(error.message).to.contain('stopped');
expect(error.code).to.be(tasks.ESTOPPED);
@@ -125,9 +125,9 @@ describe('task', function () {
});
it('task timesout', async function () {
const taskId = await tasks.add(tasks._TASK_SLEEP, [ 10000 ]);
const timeoutTaskId = await tasks.add(tasks._TASK_SLEEP, [ 10000 ]);
const [error, result] = await safe(tasks.startTask(taskId, { timeout: 2000 }));
const [error, result] = await safe(tasks.startTask(timeoutTaskId, { timeout: 2000 }));
if (!error) throw new Error('expecting task to timeout');
expect(error.code).to.be(tasks.ETIMEOUT);
expect(error.message).to.contain('timed out');
+37 -37
View File
@@ -42,50 +42,50 @@ describe('User', function () {
describe('add', function () {
it('fails due to short password', async function () {
const user = Object.assign({}, admin, { password: 'Fo$%23' });
const [error] = await safe(users.add(user.email, user, auditSource));
const testUser = Object.assign({}, admin, { password: 'Fo$%23' });
const [error] = await safe(users.add(testUser.email, testUser, auditSource));
expect(error.reason).to.equal(BoxError.BAD_FIELD);
});
it('fails due to reserved username', async function () {
const user = Object.assign({}, admin, { username: 'admin' });
const [error] = await safe(users.add(user.email, user, auditSource));
const testUser = Object.assign({}, admin, { username: 'admin' });
const [error] = await safe(users.add(testUser.email, testUser, auditSource));
expect(error.reason).to.equal(BoxError.BAD_FIELD);
});
it('fails due to invalid username', async function () {
const user = Object.assign({}, admin, { username: 'moo+daemon' });
const [error] = await safe(users.add(user.email, user, auditSource));
const testUser = Object.assign({}, admin, { username: 'moo+daemon' });
const [error] = await safe(users.add(testUser.email, testUser, auditSource));
expect(error.reason).to.equal(BoxError.BAD_FIELD);
});
it('fails due to empty username', async function () {
const user = Object.assign({}, admin, { username: '' });
const [error] = await safe(users.add(user.email, user, auditSource));
const testUser = Object.assign({}, admin, { username: '' });
const [error] = await safe(users.add(testUser.email, testUser, auditSource));
expect(error.reason).to.equal(BoxError.BAD_FIELD);
});
it('fails due to long username', async function () {
const user = Object.assign({}, admin, { username: new Array(257).fill('Z').join('') });
const [error] = await safe(users.add(user.email, user, auditSource));
const testUser = Object.assign({}, admin, { username: new Array(257).fill('Z').join('') });
const [error] = await safe(users.add(testUser.email, testUser, auditSource));
expect(error.reason).to.equal(BoxError.BAD_FIELD);
});
it('fails due to reserved app pattern', async function () {
const user = Object.assign({}, admin, { username: 'maybe.app' });
const [error] = await safe(users.add(user.email, user, auditSource));
const testUser = Object.assign({}, admin, { username: 'maybe.app' });
const [error] = await safe(users.add(testUser.email, testUser, auditSource));
expect(error.reason).to.equal(BoxError.BAD_FIELD);
});
it('fails because password is empty', async function () {
const user = Object.assign({}, admin, { password: '' });
const [error] = await safe(users.add(user.email, user, auditSource));
const testUser = Object.assign({}, admin, { password: '' });
const [error] = await safe(users.add(testUser.email, testUser, auditSource));
expect(error.reason).to.equal(BoxError.BAD_FIELD);
});
it('fails because fallbackEmail is not an email', async function () {
const user = Object.assign({}, admin, { fallbackEmail: 'notanemail' });
const [error] = await safe(users.add(user.email, user, auditSource));
const testUser = Object.assign({}, admin, { fallbackEmail: 'notanemail' });
const [error] = await safe(users.add(testUser.email, testUser, auditSource));
expect(error.reason).to.equal(BoxError.BAD_FIELD);
});
@@ -207,8 +207,8 @@ describe('User', function () {
before(createOwner);
it('fails due to unknown userid', async function () {
const user = Object.assign({}, admin, { id: 'random' });
const [error] = await safe(users.update(user, { displayName: 'full name' }, auditSource));
const unknownUser = Object.assign({}, admin, { id: 'random' });
const [error] = await safe(users.update(unknownUser, { displayName: 'full name' }, auditSource));
expect(error.reason).to.equal(BoxError.NOT_FOUND);
});
@@ -234,9 +234,9 @@ describe('User', function () {
it('can update the user', async function () {
await users.update(admin, { email: 'some@thing.com', displayName: 'Heiter' }, auditSource);
const user = await users.get(admin.id);
expect(user.email).to.equal('some@thing.com');
expect(user.displayName).to.equal('Heiter');
const updatedUser = await users.get(admin.id);
expect(updatedUser.email).to.equal('some@thing.com');
expect(updatedUser.displayName).to.equal('Heiter');
});
});
@@ -427,19 +427,19 @@ describe('User', function () {
});
it('verify succeeds with relaxed 2fa', async function () {
const user = await users.verifyWithUsername(admin.username, admin.password, users.AP_WEBADMIN, { skipTotpCheck: true });
expect(user.id).to.be(admin.id);
const verifiedUser = await users.verifyWithUsername(admin.username, admin.password, users.AP_WEBADMIN, { skipTotpCheck: true });
expect(verifiedUser.id).to.be(admin.id);
});
it('verify succeeds with relaxed 2fa but incorrect totp (totp is ignored)', async function () {
const user = await users.verifyWithUsername(admin.username, admin.password, users.AP_WEBADMIN, { totpToken: 'schlecht', skipTotpCheck: true });
expect(user.id).to.be(admin.id);
const verifiedUser = await users.verifyWithUsername(admin.username, admin.password, users.AP_WEBADMIN, { totpToken: 'schlecht', skipTotpCheck: true });
expect(verifiedUser.id).to.be(admin.id);
});
it('verify succeeds with valid 2fa', async function () {
const totpToken = speakeasy.totp({ secret: twofa.secret, encoding: 'base32' });
const user = await users.verifyWithUsername(admin.username, admin.password, users.AP_WEBADMIN, { totpToken });
expect(user.id).to.be(admin.id);
const verifiedUser = await users.verifyWithUsername(admin.username, admin.password, users.AP_WEBADMIN, { totpToken });
expect(verifiedUser.id).to.be(admin.id);
});
});
@@ -496,8 +496,8 @@ describe('User', function () {
before(createOwner);
it('fails due to unknown user', async function () {
const user = Object.assign({}, admin, { id: 'doesnotexist' });
const [error] = await safe(users.setPassword(user, 'newpassword', auditSource));
const unknownUser = Object.assign({}, admin, { id: 'doesnotexist' });
const [error] = await safe(users.setPassword(unknownUser, 'newpassword', auditSource));
expect(error.reason).to.be(BoxError.NOT_FOUND);
});
@@ -606,7 +606,7 @@ describe('User', function () {
describe('invite', function () {
before(createOwner);
let user;
let invitedUser;
it('get link fails as alreayd been used', async function () {
const [error] = await safe(users.getInviteLink(admin, auditSource));
@@ -615,11 +615,11 @@ describe('User', function () {
it('can get link', async function () {
const userId = await users.add('some@mail.com', { username: 'someoneinvited', displayName: 'some one', password: 'unsafe1234' }, auditSource);
user = await users.get(userId);
invitedUser = await users.get(userId);
const inviteLink = await users.getInviteLink(user, auditSource);
const inviteLink = await users.getInviteLink(invitedUser, auditSource);
expect(inviteLink).to.be.a('string');
expect(inviteLink).to.contain(user.inviteToken);
expect(inviteLink).to.contain(invitedUser.inviteToken);
});
it('cannot send mail for already active user', async function () {
@@ -628,13 +628,13 @@ describe('User', function () {
});
it('cannot send mail with empty receipient', async function () {
const [error] = await safe(users.sendInviteEmail(user, '', auditSource));
const [error] = await safe(users.sendInviteEmail(invitedUser, '', auditSource));
expect(error.reason).to.be(BoxError.BAD_FIELD);
});
it('can send mail', async function () {
await clearMailQueue();
await users.sendInviteEmail(user, 'custom@mail.com', auditSource);
await users.sendInviteEmail(invitedUser, 'custom@mail.com', auditSource);
const emails = await checkMails(1);
expect(emails[0].to).to.equal('custom@mail.com');
});
@@ -644,8 +644,8 @@ describe('User', function () {
before(createOwner);
it('fails for unknown user', async function () {
const user = Object.assign({}, admin, { id: 'doesnotexist' });
const [error] = await safe(users.del(user, auditSource));
const unknownUser = Object.assign({}, admin, { id: 'doesnotexist' });
const [error] = await safe(users.del(unknownUser, auditSource));
expect(error.reason).to.be(BoxError.NOT_FOUND);
});