mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Server tests pass again: four faults the repaired test build found, fixed.
- A password sign-in refused by policy (PASSWORD_LOGIN_ENABLED=false, forgot password off, LDAP's password-login guard) was counted by the lockout as a wrong password, which threw its own 403 "Incorrect password" over the policy's error: the person was told the wrong thing, and enough attempts locked the account because of a setting. Policy refusals are no guesses now (loginFailureDecision.js). - Auto-archive fetched its boards without their members, so boardActorId found nobody and every auto-archive was recorded as no user. - Every upload got two "added" rows in the card history: the upload hook's and the content index's. The index writes its row only for an attachment that has none, and never for a durable rule copy, whose plan writes it. - Not found is undefined from Meteor 3's findOneAsync: the Admin Panel addresses test accepts either. meteor test --full-app: 699 passing, 0 failing (was 693 / 6). Thanks to xet7 !
This commit is contained in:
1 parent
788131193e
commit
5ba1098521
8 files changed
+60
-4
No files matched your search
@@ -28,10 +28,23 @@
|
||||
// every two-factor login; counting it would lock out legitimate 2FA users
|
||||
// after a few ordinary sign-ins.
|
||||
//
|
||||
// 'password-login-disabled', 'forgot-password-disabled',
|
||||
// 'ldap-password-login-disabled' — a policy refusal from server/authentication.js
|
||||
// (models/lib/passwordLoginPolicy.js, server/lib/ldapPasswordLoginGuard.js),
|
||||
// made whether or not the password was right. It tells a guesser nothing, so
|
||||
// it is no guess to count - and counting it made this hook throw its own 403
|
||||
// "Incorrect password" over the policy's error, so the person was told the
|
||||
// wrong thing and their account was locked by a setting.
|
||||
//
|
||||
// A wrong second factor ('invalid-2fa-code') is intentionally NOT excluded: the
|
||||
// password was correct, so repeated wrong codes are a real guessing attempt and
|
||||
// should count.
|
||||
const NON_FAILURE_ERROR_CODES = new Set(['no-2fa-code']);
|
||||
const NON_FAILURE_ERROR_CODES = new Set([
|
||||
'no-2fa-code',
|
||||
'password-login-disabled',
|
||||
'forgot-password-disabled',
|
||||
'ldap-password-login-disabled',
|
||||
]);
|
||||
|
||||
function isNonFailureError(error) {
|
||||
return (
|
||||
|
||||
@@ -46,7 +46,7 @@ export async function autoArchiveBoard(board, now = new Date()) {
|
||||
|
||||
export async function scanAutoArchive(now = new Date()) {
|
||||
const boards = await Boards.find(AUTO_ARCHIVE_BOARD_SELECTOR, {
|
||||
fields: { _id: 1, autoArchiveInactiveDays: 1, createdBy: 1 },
|
||||
fields: { _id: 1, autoArchiveInactiveDays: 1, members: 1 },
|
||||
}).fetchAsync();
|
||||
for (const board of boards) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
|
||||
@@ -177,6 +177,16 @@ export async function indexNewAttachment(attachmentId) {
|
||||
if (!attachment) return;
|
||||
const meta = attachment.meta || {};
|
||||
const ChangeHistory = require('/models/changeHistory').default;
|
||||
// One "added" row per attachment. An upload already has one from
|
||||
// server/models/changeHistoryHooks.js, and a durable rule copy one from its
|
||||
// plan; a second row here showed the upload twice in the card history. The
|
||||
// hash is on the attachment itself (contentHash), so nothing is lost. This
|
||||
// row is written only for an attachment that has no "added" row - one the
|
||||
// hook skips, such as an import.
|
||||
if (require('/server/lib/syncRecordingScope').isSyncCopiedAttachment(attachmentId)) return;
|
||||
const added = await ChangeHistory.rawCollection().findOne(
|
||||
{ entityType: 'attachment', entityId: attachmentId, changeType: 'added' }, { projection: { _id: 1 } });
|
||||
if (added) return;
|
||||
await ChangeHistory.record({
|
||||
boardId: meta.boardId || null, swimlaneId: meta.swimlaneId || null, listId: meta.listId || null,
|
||||
cardId: meta.cardId || null, entityType: 'attachment', entityId: attachment._id, group: 'lifecycle',
|
||||
|
||||
@@ -79,6 +79,14 @@ function deferSyncChecklistRecording(kind, doc) {
|
||||
scope.kinds.delete(kind);
|
||||
return true;
|
||||
}
|
||||
// Whether a durable rule copy names this attachment, active or not: its History
|
||||
// row is the plan's, so the content index must not write another one
|
||||
// (server/lib/attachmentContentIndex.js indexNewAttachment, deferred from the
|
||||
// upload and so still inside this scope's async context).
|
||||
function isSyncCopiedAttachment(attachmentId) {
|
||||
const scope=storage.getStore();
|
||||
return !!scope && typeof attachmentId==='string' && scope.attachmentId===attachmentId;
|
||||
}
|
||||
// The same one-shot slot for the one attachment a scope names.
|
||||
function deferSyncAttachmentRecording(kind, doc) {
|
||||
const scope=storage.getStore();
|
||||
@@ -103,4 +111,4 @@ function deferSyncSwimlaneActivity(doc) {
|
||||
return true;
|
||||
}
|
||||
module.exports={withSyncRecordingDeferred,deferSyncRecording,deferSyncLabelActivities,deferSyncItemRecording,deferSyncChecklistRecording,
|
||||
deferSyncAttachmentRecording,withSyncSwimlaneActivityDeferred,deferSyncSwimlaneActivity};
|
||||
deferSyncAttachmentRecording,isSyncCopiedAttachment,withSyncSwimlaneActivityDeferred,deferSyncSwimlaneActivity};
|
||||
@@ -49,7 +49,8 @@ describe('Admin Panel allowed addresses', function () {
|
||||
const user = await as(admin, '203.0.113.9', 'x', () => Meteor.users.findOneAsync(admin));
|
||||
assert.equal(user.isAdmin, false);
|
||||
assert.equal(user.username, `apa-admin-${admin}`, 'still found: their boards work');
|
||||
assert.equal(await as(admin, '203.0.113.9', 'x', () => Meteor.users.findOneAsync({ _id: admin, isAdmin: true })), null);
|
||||
// Not found: Meteor 3's findOneAsync answers undefined, the driver null.
|
||||
assert.equal(await as(admin, '203.0.113.9', 'x', () => Meteor.users.findOneAsync({ _id: admin, isAdmin: true })) == null, true);
|
||||
const stored = await Meteor.users.findOneAsync(admin);
|
||||
assert.equal(stored.isAdmin, true, 'outside any caller the stored flag is read as it is');
|
||||
});
|
||||
|
||||
@@ -80,6 +80,10 @@ test('server: added -> hashed and indexed with an "added" history row; a whole r
|
||||
const index = read('server/lib/attachmentContentIndex.js');
|
||||
assert.match(index, /changeType: 'added', previousContent: null,\s*newContent: \{ deleted: false, name: attachment\.name \|\| '', contentHash: result\.hash\.value \}/);
|
||||
assert.match(index, /group: 'lifecycle'/, 'a lifecycle row: its undo only ever soft-deletes or restores');
|
||||
// Only when it has none yet: the upload hook and a durable rule copy already
|
||||
// wrote one, and a second "added" row listed the upload twice in History.
|
||||
assert.match(index, /isSyncCopiedAttachment\(attachmentId\)\) return;/);
|
||||
assert.match(index, /findOne\(\s*\{ entityType: 'attachment', entityId: attachmentId, changeType: 'added' \}[^;]*;\s*if \(added\) return;/);
|
||||
assert.match(index, /contentHash: \{ algorithm: lib\.ALGORITHM, value: actual\.value, size: actual\.size, at \}/, 'with the time it was made');
|
||||
assert.match(index, /searchText,\s*generatedAt: at,/, 'the search text with the time it was made');
|
||||
const server = read('server/routes/universalFileServer.js');
|
||||
|
||||
@@ -56,3 +56,14 @@ test('a scheduled rule acts as the board, and its created card names its author'
|
||||
const create = helper.slice(helper.indexOf("if (action.actionType === 'createCard') {"));
|
||||
assert.match(create.slice(0, 1200), /const authorId = resolveActingUserId\(activity\);[\s\S]*\.\.\.\(authorId \? \{ userId: authorId \} : \{\}\),/);
|
||||
});
|
||||
|
||||
test('auto-archive fetches the members boardActorId decides from (negative: not createdBy)', () => {
|
||||
// The scan projected { createdBy } only, so boardActorId saw no members and
|
||||
// every auto-archive was recorded as nobody.
|
||||
const src = read('server/autoArchiveCards.js');
|
||||
const scan = src.slice(src.indexOf('export async function scanAutoArchive'));
|
||||
const fields = /fields:\s*\{([^}]*)\}/.exec(scan);
|
||||
assert.ok(fields, 'scanAutoArchive projects its boards');
|
||||
assert.match(fields[1], /\bmembers:\s*1\b/);
|
||||
assert.doesNotMatch(fields[1], /createdBy/);
|
||||
});
|
||||
@@ -158,6 +158,15 @@ test('unknown: non-password logins are ignored', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('known: a policy refusal is NOT a failure, and does not replace its error', () => {
|
||||
for (const code of ['password-login-disabled', 'forgot-password-disabled', 'ldap-password-login-disabled']) {
|
||||
assert.strictEqual(shouldProcessKnownUser({ type: 'password', user: { _id: 'u1' }, error: { error: code } }), false, code);
|
||||
assert.strictEqual(isCountableFailure({ error: code }), false, code);
|
||||
}
|
||||
// Negative: an ordinary credential failure still counts.
|
||||
assert.strictEqual(isCountableFailure({ error: 403, reason: AMBIGUOUS }), true);
|
||||
});
|
||||
|
||||
// --- Robustness ------------------------------------------------------------
|
||||
|
||||
test('never throws on missing / malformed loginInfo', () => {
|
||||
|
||||
Reference in new issue
Block a user