mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
add tests
This commit is contained in:
1 parent
081a75af8c
commit
54a57d3ca9
8 files changed
+27
-16
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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' },
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user