mirror of
https://github.com/caprover/caprover
synced 2025-10-30 01:57:03 +00:00
Pass linter
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -13,5 +13,5 @@
|
||||
},
|
||||
"typescript.referencesCodeLens.enabled": true,
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"cSpell.words": ["csrf", "definitelytyped", "promisified"]
|
||||
"cSpell.words": ["csrf", "definitelytyped", "dockerode", "promisified"]
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import EnvVars from '../utils/EnvVars'
|
||||
import Logger from '../utils/Logger'
|
||||
import Utils from '../utils/Utils'
|
||||
import Dockerode = require('dockerode')
|
||||
// @ts-ignore
|
||||
import dockerodeUtils = require('dockerode/lib/util')
|
||||
|
||||
const Base64 = Base64Provider.Base64
|
||||
|
||||
@@ -47,7 +47,7 @@ class LoadBalancerManager {
|
||||
private requestedReloadPromises: {
|
||||
dataStore: DataStore
|
||||
resolve: VoidFunction
|
||||
reject: VoidFunction
|
||||
reject: (reason: any) => void
|
||||
}[]
|
||||
private captainPublicRandomKey: string
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import * as crypto from 'crypto'
|
||||
const itoa64 =
|
||||
'./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
|
||||
|
||||
const DIGEST_ENCODING = 'base64'
|
||||
export default class ApacheMd5 {
|
||||
// To 64 bit version.
|
||||
static to64(index: number, count: number) {
|
||||
@@ -95,7 +96,8 @@ export default class ApacheMd5 {
|
||||
let final = crypto
|
||||
.createHash('md5')
|
||||
.update(password + salt + password, 'ascii')
|
||||
.digest('binary')
|
||||
//@ts-ignore
|
||||
.digest(DIGEST_ENCODING)
|
||||
|
||||
for (let pl = password.length; pl > 0; pl -= 16) {
|
||||
ctx += final.substr(0, pl > 16 ? 16 : pl)
|
||||
@@ -109,7 +111,12 @@ export default class ApacheMd5 {
|
||||
}
|
||||
}
|
||||
|
||||
final = crypto.createHash('md5').update(ctx, 'ascii').digest('binary')
|
||||
//@ts-ignore
|
||||
final = crypto
|
||||
.createHash('md5')
|
||||
.update(ctx, 'ascii')
|
||||
//@ts-ignore
|
||||
.digest(DIGEST_ENCODING)
|
||||
|
||||
// 1000 loop.
|
||||
for (let i = 0; i < 1000; ++i) {
|
||||
@@ -140,7 +147,8 @@ export default class ApacheMd5 {
|
||||
final = crypto
|
||||
.createHash('md5')
|
||||
.update(ctxl, 'ascii')
|
||||
.digest('binary')
|
||||
//@ts-ignore
|
||||
.digest(DIGEST_ENCODING)
|
||||
}
|
||||
|
||||
return `${magic + salt}$${ApacheMd5.getPassword(final)}`
|
||||
|
||||
41
tests/ApacheMd5.test.ts
Normal file
41
tests/ApacheMd5.test.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import ApacheMd5 from '../src/utils/ApacheMd5'
|
||||
|
||||
test('apache_test', () => {
|
||||
// Test for valid password.
|
||||
{
|
||||
const encrypted = ApacheMd5.createApacheHash(
|
||||
'su/P3R%se#ret!',
|
||||
'$apr1$cF.rAvCe$YlzjmK4qu/ia6hC8CNfnm/'
|
||||
)
|
||||
expect(encrypted).toBe('$apr1$cF.rAvCe$YlzjmK4qu/ia6hC8CNfnm/')
|
||||
}
|
||||
|
||||
// Test for valid short password.
|
||||
{
|
||||
const encrypted = ApacheMd5.createApacheHash(
|
||||
'123456',
|
||||
'$1$VV5.4y5.$JbhytGQBPmDHBbrSjF2i7.'
|
||||
)
|
||||
expect(encrypted).toBe('$1$VV5.4y5.$JbhytGQBPmDHBbrSjF2i7.')
|
||||
}
|
||||
|
||||
// Test for invalid password.
|
||||
{
|
||||
const encrypted =
|
||||
ApacheMd5.createApacheHash(
|
||||
'invalidPass',
|
||||
'$apr1$cF.rAvCe$YlzjmK4qu/ia6hC8CNfnm/'
|
||||
) == '$apr1$cF.rAvCe$YlzjmK4qu/ia6hC8CNfnm/'
|
||||
expect(encrypted).toBeFalsy()
|
||||
}
|
||||
|
||||
// Test for invalid short password.
|
||||
{
|
||||
const encrypted =
|
||||
ApacheMd5.createApacheHash(
|
||||
'passw0rdpa55wore',
|
||||
'$1$VV5.4y5.$9981ZZhKTHmeXFKQur4cV0'
|
||||
) == '$1$VV5.4y5.$9981ZZhKTHmeXFKQur4cV0'
|
||||
expect(encrypted).toBeFalsy()
|
||||
}
|
||||
})
|
||||
26
tests/dockerutil.test.ts
Normal file
26
tests/dockerutil.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
// @ts-ignore
|
||||
import dockerodeUtils = require('dockerode/lib/util')
|
||||
|
||||
test('dockerodeUtils', () => {
|
||||
{
|
||||
const parsed = dockerodeUtils.parseRepositoryTag('lib/repo:tag.v1.0')
|
||||
expect(parsed.tag).toBe('tag.v1.0')
|
||||
expect(parsed.repository).toBe('lib/repo')
|
||||
}
|
||||
|
||||
{
|
||||
const parsed = dockerodeUtils.parseRepositoryTag(
|
||||
'domain.com:3000/lib/repo:tag.v1.0'
|
||||
)
|
||||
expect(parsed.tag).toBe('tag.v1.0')
|
||||
expect(parsed.repository).toBe('domain.com:3000/lib/repo')
|
||||
}
|
||||
|
||||
{
|
||||
const parsed = dockerodeUtils.parseRepositoryTag(
|
||||
'domain.com:3000/repo:tag.v1.0'
|
||||
)
|
||||
expect(parsed.tag).toBe('tag.v1.0')
|
||||
expect(parsed.repository).toBe('domain.com:3000/repo')
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user