add tests

This commit is contained in:
undefined committed 2020-08-10 18:51:07 +08:00
1 parent 081a75af8c
commit 54a57d3ca9
8 files changed
+27 -16

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.12.11",
"version": "2.12.12",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+2 -8
View File
@@ -52,12 +52,6 @@ class Loader {
<input name="name" type="text" value="hydro">
</label>
</div></div>
<div class="row"><div class="columns">
<label class="inverse material textbox">
{{ _('Table Prefix') }}
<input name="prefix" type="text" placeholder="{{ _('Leave blank if none') }}">>
</label>
</div></div>
<div class="row"><div class="columns">
<label class="inverse material textbox">
{{ _('Database Username') }}
@@ -109,7 +103,7 @@ async function get(ctx: Context) {
async function post(ctx: Context) {
const {
host, port, name, username, password, prefix,
host, port, name, username, password,
} = ctx.request.body;
let mongourl = 'mongodb://';
if (username) mongourl += `${username}:${password}@`;
@@ -119,7 +113,7 @@ async function post(ctx: Context) {
useNewUrlParser: true, useUnifiedTopology: true,
});
const db = Database.db(name);
const coll = prefix ? db.collection('system') : db.collection(`${prefix}.system`);
const coll = db.collection('system');
await Promise.all([
coll.updateOne(
{ _id: 'server.host' },
+14
View File
@@ -0,0 +1,14 @@
import 'hydrooj';
import pwhash from 'hydrooj/src/lib/hash.hydro';
import 'hydrooj/src/utils';
describe('Hash', () => {
test('server', () => {
const password1 = 'password1';
const salt1 = '0326Bc23E6fac733K01g29fBBUSAj7O4';
const salt2 = String.random(32);
const hash1 = '70a2db6a53ecd75d8d4b19d8647a416b4e812c1a6635c4a1f5069a00382fdcb6';
expect(pwhash(password1, salt1)).toStrictEqual(hash1);
expect(pwhash(password1, salt2)).not.toEqual(hash1);
});
});