mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
add tests
This commit is contained in:
1 parent
081a75af8c
commit
54a57d3ca9
8 files changed
+27
-16
No files matched your search
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
dist
|
dist
|
||||||
*.d.ts
|
*.d.ts
|
||||||
*.js
|
*.js
|
||||||
|
test
|
||||||
@@ -34,7 +34,7 @@ jobs:
|
|||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
file: ./coverage/lcov.info
|
file: ./.coverage/lcov.info
|
||||||
name: codecov
|
name: codecov
|
||||||
- name: Publish
|
- name: Publish
|
||||||
run: node build/publish.js
|
run: node build/publish.js
|
||||||
+3
-1
@@ -22,4 +22,6 @@ packages/**/*.js
|
|||||||
packages/**/*.js.map
|
packages/**/*.js.map
|
||||||
packages/**/*.d.ts
|
packages/**/*.d.ts
|
||||||
|
|
||||||
*.mmdb
|
*.mmdb
|
||||||
|
|
||||||
|
.coverage
|
||||||
+2
-3
@@ -9,9 +9,8 @@ module.exports = {
|
|||||||
preset: 'ts-jest',
|
preset: 'ts-jest',
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
moduleFileExtensions: ['ts', 'js', 'json'],
|
moduleFileExtensions: ['ts', 'js', 'json'],
|
||||||
moduleNameMapper: {
|
collectCoverage: true,
|
||||||
'[\\w-]+': '<rootDir>/packages/$0/src',
|
coverageDirectory: '<rootDir>/.coverage',
|
||||||
},
|
|
||||||
coverageProvider: 'v8',
|
coverageProvider: 'v8',
|
||||||
coverageReporters: ['text', 'lcov'],
|
coverageReporters: ['text', 'lcov'],
|
||||||
coveragePathIgnorePatterns: [
|
coveragePathIgnorePatterns: [
|
||||||
|
|||||||
+2
-1
@@ -16,6 +16,7 @@
|
|||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cross-spawn": "^6.0.2",
|
"@types/cross-spawn": "^6.0.2",
|
||||||
|
"@types/jest": "^26.0.9",
|
||||||
"@types/node": "^14.0.27",
|
"@types/node": "^14.0.27",
|
||||||
"@typescript-eslint/eslint-plugin": "^3.8.0",
|
"@typescript-eslint/eslint-plugin": "^3.8.0",
|
||||||
"@typescript-eslint/parser": "^3.8.0",
|
"@typescript-eslint/parser": "^3.8.0",
|
||||||
@@ -36,4 +37,4 @@
|
|||||||
"fs-extra": "^9.0.1",
|
"fs-extra": "^9.0.1",
|
||||||
"yargs": "^15.4.1"
|
"yargs": "^15.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.12.11",
|
"version": "2.12.12",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -52,12 +52,6 @@ class Loader {
|
|||||||
<input name="name" type="text" value="hydro">
|
<input name="name" type="text" value="hydro">
|
||||||
</label>
|
</label>
|
||||||
</div></div>
|
</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">
|
<div class="row"><div class="columns">
|
||||||
<label class="inverse material textbox">
|
<label class="inverse material textbox">
|
||||||
{{ _('Database Username') }}
|
{{ _('Database Username') }}
|
||||||
@@ -109,7 +103,7 @@ async function get(ctx: Context) {
|
|||||||
|
|
||||||
async function post(ctx: Context) {
|
async function post(ctx: Context) {
|
||||||
const {
|
const {
|
||||||
host, port, name, username, password, prefix,
|
host, port, name, username, password,
|
||||||
} = ctx.request.body;
|
} = ctx.request.body;
|
||||||
let mongourl = 'mongodb://';
|
let mongourl = 'mongodb://';
|
||||||
if (username) mongourl += `${username}:${password}@`;
|
if (username) mongourl += `${username}:${password}@`;
|
||||||
@@ -119,7 +113,7 @@ async function post(ctx: Context) {
|
|||||||
useNewUrlParser: true, useUnifiedTopology: true,
|
useNewUrlParser: true, useUnifiedTopology: true,
|
||||||
});
|
});
|
||||||
const db = Database.db(name);
|
const db = Database.db(name);
|
||||||
const coll = prefix ? db.collection('system') : db.collection(`${prefix}.system`);
|
const coll = db.collection('system');
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
coll.updateOne(
|
coll.updateOne(
|
||||||
{ _id: 'server.host' },
|
{ _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