Skip to content
This repository was archived by the owner on Nov 10, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/test/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { strict as assert } from 'node:assert';
import * as crypto from 'node:crypto';
import { after, suite, test } from 'node:test';

import { Config } from '../config-loader.ts';
import { Ladder } from '../ladder.ts';
import { Server } from '../server.ts';
import * as tables from '../tables.ts';
Expand Down Expand Up @@ -81,6 +82,41 @@ void suite('Loginserver actions', () => {
});
assert(newPasswordLogin.result.actionsuccess, 'User could not log in with the new password');
});

void test('Should give bot accounts the bot usertype', async t => {
// the test config has no signing key, so use a throwaway one to get a real assertion
const oldPrivateKey = Config.privatekey;
t.after(() => {
Config.privatekey = oldPrivateKey;
});
Config.privatekey = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
publicKeyEncoding: { type: 'spki', format: 'pem' },
}).privateKey;

await tables.users.delete('entrapta').catch(() => null);
await server.request('register', {
username: 'Entrapta',
password: 'imp0ssible',
cpassword: 'imp0ssible',
captcha: 'pikachu',
challstr: crypto.randomBytes(128).toString('hex'),
challengekeyid: '1',
});
await tables.users.update('entrapta', { group: 10 });

const login = await server.request('login', {
name: 'entrapta',
pass: 'imp0ssible',
challengekeyid: `${Config.challengekeyid}`,
challstr: crypto.randomBytes(128).toString('hex'),
});
const [challenge, userid, userType] = login.result.assertion.split(';')[0].split(',');
assert(challenge, `Login failed: ${login.result.assertion}`);
assert.equal(userid, 'entrapta');
assert.equal(userType, '10');
});
});

// prepreplay no longer exists
Expand Down
2 changes: 1 addition & 1 deletion src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class Session {
forceUsertype = '5';
}
let userType;
const userData = user.loggedIn ? await users.get(user.id, SQL`banstate, registertime, logintime`) : null;
const userData = user.loggedIn ? await users.get(user.id, SQL`banstate, registertime, logintime, "${'group'}"`) : null;
const { banstate, group, registertime, logintime } = userData || {
banstate: 0, registertime: 0, logintime: 0, group: 0,
};
Expand Down