@ditojs/server 2.100.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -15
- package/src/controllers/AdminController.js +2 -14
- package/src/models/Model.js +43 -7
- package/types/index.d.ts +187 -93
- package/src/models/Model.test.js +0 -180
- package/src/schema/relations.test.js +0 -177
- package/src/schema/schema.test.js +0 -720
- package/src/storage/Storage.test.js +0 -58
- package/src/utils/function.test.js +0 -77
- package/src/utils/object.test.js +0 -86
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Storage } from './Storage.js'
|
|
2
|
-
|
|
3
|
-
function createStorage(keys = ['test-secret']) {
|
|
4
|
-
const app = { keys }
|
|
5
|
-
return new Storage(app, { name: 'test' })
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function simulateUpload(storage, key, originalname) {
|
|
9
|
-
return storage.convertStorageFile({
|
|
10
|
-
key,
|
|
11
|
-
originalname,
|
|
12
|
-
mimetype: 'image/png',
|
|
13
|
-
size: 2048
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe('Storage: asset key signature verification', () => {
|
|
18
|
-
it('preserves the key through a full upload-then-save cycle', () => {
|
|
19
|
-
const storage = createStorage()
|
|
20
|
-
const uploaded = simulateUpload(storage, 'real-key.png', 'photo.png')
|
|
21
|
-
const fromClient = { ...uploaded }
|
|
22
|
-
storage.convertAssetFile(fromClient, { trusted: false })
|
|
23
|
-
expect(fromClient.key).toBe('real-key.png')
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('throws when a forged key is submitted', () => {
|
|
27
|
-
const storage = createStorage()
|
|
28
|
-
const file = { key: 'victim-key.png', name: 'photo.png' }
|
|
29
|
-
expect(() => {
|
|
30
|
-
storage.convertAssetFile(file, { trusted: false })
|
|
31
|
-
}).toThrow('Invalid asset signature')
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('throws when a valid signature is paired with a swapped key', () => {
|
|
35
|
-
const storage = createStorage()
|
|
36
|
-
const uploaded = simulateUpload(storage, 'legit.png', 'legit.png')
|
|
37
|
-
const forged = { ...uploaded, key: 'victim-file.png' }
|
|
38
|
-
expect(() => {
|
|
39
|
-
storage.convertAssetFile(forged, { trusted: false })
|
|
40
|
-
}).toThrow('Invalid asset signature')
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('does not throw when addFile() converts a server-created file', async () => {
|
|
44
|
-
const storage = createStorage()
|
|
45
|
-
const file = { key: 'imported.png', name: 'import.png' }
|
|
46
|
-
const data = Buffer.from('fake-image-data')
|
|
47
|
-
await storage.addFile(file, data)
|
|
48
|
-
expect(file.key).toBe('imported.png')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('strips signature after conversion', () => {
|
|
52
|
-
const storage = createStorage()
|
|
53
|
-
const uploaded = simulateUpload(storage, 'upload.png', 'photo.png')
|
|
54
|
-
const fromClient = { ...uploaded }
|
|
55
|
-
storage.convertAssetFile(fromClient, { trusted: false })
|
|
56
|
-
expect('signature' in fromClient).toBe(false)
|
|
57
|
-
})
|
|
58
|
-
})
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { describeFunction } from './function.js'
|
|
2
|
-
|
|
3
|
-
describe('describeFunction()', () => {
|
|
4
|
-
it('describes normal functions', () => {
|
|
5
|
-
expect(
|
|
6
|
-
describeFunction(function (a, b, c) {
|
|
7
|
-
return a + b + c
|
|
8
|
-
})
|
|
9
|
-
)
|
|
10
|
-
.toBe('function (a, b, c) { ... }')
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it('describes lambdas with one param and a body', () => {
|
|
14
|
-
expect(
|
|
15
|
-
describeFunction(a => {
|
|
16
|
-
return a
|
|
17
|
-
})
|
|
18
|
-
)
|
|
19
|
-
.toBe('a => { ... }')
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('describes lambdas with one param and no body', () => {
|
|
23
|
-
expect(describeFunction(a => a))
|
|
24
|
-
.toBe('a => ...')
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('describes lambdas with multiple params and a body', () => {
|
|
28
|
-
expect(
|
|
29
|
-
describeFunction((a, b, c) => {
|
|
30
|
-
return a + b + c
|
|
31
|
-
})
|
|
32
|
-
)
|
|
33
|
-
.toBe('(a, b, c) => { ... }')
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('describes lambdas with multiple params and no body', () => {
|
|
37
|
-
expect(describeFunction((a, b, c) => a + b + c))
|
|
38
|
-
.toBe('(a, b, c) => ...')
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('describes async functions', () => {
|
|
42
|
-
expect(
|
|
43
|
-
describeFunction(async function (a, b, c) {
|
|
44
|
-
return a + b + c
|
|
45
|
-
})
|
|
46
|
-
)
|
|
47
|
-
.toBe('async function (a, b, c) { ... }')
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('describes async lambdas with one param and a body', () => {
|
|
51
|
-
expect(
|
|
52
|
-
describeFunction(async a => {
|
|
53
|
-
return a
|
|
54
|
-
})
|
|
55
|
-
)
|
|
56
|
-
.toBe('async a => { ... }')
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('describes async lambdas with one param and no body', () => {
|
|
60
|
-
expect(describeFunction(async a => a))
|
|
61
|
-
.toBe('async a => ...')
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('describes async lambdas with multiple params and a body', () => {
|
|
65
|
-
expect(
|
|
66
|
-
describeFunction(async (a, b, c) => {
|
|
67
|
-
return a + b + c
|
|
68
|
-
})
|
|
69
|
-
)
|
|
70
|
-
.toBe('async (a, b, c) => { ... }')
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('describes async lambdas with multiple params and no body', () => {
|
|
74
|
-
expect(describeFunction(async (a, b, c) => a + b + c))
|
|
75
|
-
.toBe('async (a, b, c) => ...')
|
|
76
|
-
})
|
|
77
|
-
})
|
package/src/utils/object.test.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getAllKeys,
|
|
3
|
-
getOwnProperty,
|
|
4
|
-
createLookup,
|
|
5
|
-
mergeReversed,
|
|
6
|
-
mergeAsReversedArrays
|
|
7
|
-
} from './object.js'
|
|
8
|
-
|
|
9
|
-
const object = Object.create({ a: 1 })
|
|
10
|
-
object.b = 2
|
|
11
|
-
|
|
12
|
-
describe('getAllKeys()', () => {
|
|
13
|
-
it('returns all keys, not just own keys', () => {
|
|
14
|
-
expect(getAllKeys(object)).toEqual(['b', 'a'])
|
|
15
|
-
})
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
describe('getOwnProperty()', () => {
|
|
19
|
-
it('only returns own properties', () => {
|
|
20
|
-
expect(getOwnProperty(object, 'a')).toBeUndefined()
|
|
21
|
-
expect(getOwnProperty(object, 'b')).toBe(2)
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
describe('createLookup()', () => {
|
|
26
|
-
it('creates lookup objects out of arrays of strings', () => {
|
|
27
|
-
expect(createLookup(['a', 'b'])).toEqual({
|
|
28
|
-
a: true,
|
|
29
|
-
b: true
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
describe('mergeReversed()', () => {
|
|
35
|
-
it('merges property values in reversed order', () => {
|
|
36
|
-
expect(
|
|
37
|
-
mergeReversed([
|
|
38
|
-
{
|
|
39
|
-
a: 3
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
a: 2,
|
|
43
|
-
b: 2
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
a: 1,
|
|
47
|
-
b: 1,
|
|
48
|
-
c: 1
|
|
49
|
-
}
|
|
50
|
-
])
|
|
51
|
-
).toEqual({
|
|
52
|
-
a: 3,
|
|
53
|
-
b: 2,
|
|
54
|
-
c: 1
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
describe('mergeAsReversedArrays()', () => {
|
|
60
|
-
it('merges property values into arrays', () => {
|
|
61
|
-
expect(
|
|
62
|
-
mergeAsReversedArrays([
|
|
63
|
-
{
|
|
64
|
-
a: 1,
|
|
65
|
-
b: 1,
|
|
66
|
-
c: 1
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
a: 2,
|
|
70
|
-
b: 2
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
a: 3
|
|
74
|
-
}
|
|
75
|
-
])
|
|
76
|
-
).toEqual({
|
|
77
|
-
a: [3, 2, 1],
|
|
78
|
-
b: [2, 1],
|
|
79
|
-
c: [1]
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
describe.skip('setupPropertyInheritance()', () => {
|
|
85
|
-
// TODO: Add unit tests for this!
|
|
86
|
-
})
|