aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/server/logs.ts145
1 files changed, 96 insertions, 49 deletions
diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts
index 68f442199..d3c877408 100644
--- a/server/tests/api/server/logs.ts
+++ b/server/tests/api/server/logs.ts
@@ -2,17 +2,10 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
6 flushTests,
7 killallServers,
8 flushAndRunServer,
9 ServerInfo,
10 setAccessTokensToServers,
11 cleanupTests
12} from '../../../../shared/extra-utils/index'
13import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 6import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
14import { uploadVideo } from '../../../../shared/extra-utils/videos/videos' 7import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
15import { getLogs } from '../../../../shared/extra-utils/logs/logs' 8import { getAuditLogs, getLogs } from '../../../../shared/extra-utils/logs/logs'
16 9
17const expect = chai.expect 10const expect = chai.expect
18 11
@@ -26,69 +19,123 @@ describe('Test logs', function () {
26 await setAccessTokensToServers([ server ]) 19 await setAccessTokensToServers([ server ])
27 }) 20 })
28 21
29 it('Should get logs with a start date', async function () { 22 describe('With the standard log file', function () {
30 this.timeout(10000) 23 it('Should get logs with a start date', async function () {
24 this.timeout(10000)
31 25
32 await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) 26 await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
33 await waitJobs([ server ]) 27 await waitJobs([ server ])
34 28
35 const now = new Date() 29 const now = new Date()
36 30
37 await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) 31 await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
38 await waitJobs([ server ]) 32 await waitJobs([ server ])
39 33
40 const res = await getLogs(server.url, server.accessToken, now) 34 const res = await getLogs(server.url, server.accessToken, now)
41 const logsString = JSON.stringify(res.body) 35 const logsString = JSON.stringify(res.body)
42 36
43 expect(logsString.includes('video 1')).to.be.false 37 expect(logsString.includes('video 1')).to.be.false
44 expect(logsString.includes('video 2')).to.be.true 38 expect(logsString.includes('video 2')).to.be.true
45 }) 39 })
40
41 it('Should get logs with an end date', async function () {
42 this.timeout(20000)
43
44 await uploadVideo(server.url, server.accessToken, { name: 'video 3' })
45 await waitJobs([ server ])
46
47 const now1 = new Date()
48
49 await uploadVideo(server.url, server.accessToken, { name: 'video 4' })
50 await waitJobs([ server ])
51
52 const now2 = new Date()
53
54 await uploadVideo(server.url, server.accessToken, { name: 'video 5' })
55 await waitJobs([ server ])
56
57 const res = await getLogs(server.url, server.accessToken, now1, now2)
58 const logsString = JSON.stringify(res.body)
46 59
47 it('Should get logs with an end date', async function () { 60 expect(logsString.includes('video 3')).to.be.false
48 this.timeout(20000) 61 expect(logsString.includes('video 4')).to.be.true
62 expect(logsString.includes('video 5')).to.be.false
63 })
49 64
50 await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) 65 it('Should get filter by level', async function () {
51 await waitJobs([ server ]) 66 this.timeout(10000)
52 67
53 const now1 = new Date() 68 const now = new Date()
54 69
55 await uploadVideo(server.url, server.accessToken, { name: 'video 4' }) 70 await uploadVideo(server.url, server.accessToken, { name: 'video 6' })
56 await waitJobs([ server ]) 71 await waitJobs([ server ])
57 72
58 const now2 = new Date() 73 {
74 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
75 const logsString = JSON.stringify(res.body)
59 76
60 await uploadVideo(server.url, server.accessToken, { name: 'video 5' }) 77 expect(logsString.includes('video 6')).to.be.true
61 await waitJobs([ server ]) 78 }
62 79
63 const res = await getLogs(server.url, server.accessToken, now1, now2) 80 {
64 const logsString = JSON.stringify(res.body) 81 const res = await getLogs(server.url, server.accessToken, now, undefined, 'warn')
82 const logsString = JSON.stringify(res.body)
65 83
66 expect(logsString.includes('video 3')).to.be.false 84 expect(logsString.includes('video 6')).to.be.false
67 expect(logsString.includes('video 4')).to.be.true 85 }
68 expect(logsString.includes('video 5')).to.be.false 86 })
69 }) 87 })
70 88
71 it('Should get filter by level', async function () { 89 describe('With the audit log', function () {
72 this.timeout(10000) 90 it('Should get logs with a start date', async function () {
91 this.timeout(10000)
73 92
74 const now = new Date() 93 await uploadVideo(server.url, server.accessToken, { name: 'video 7' })
94 await waitJobs([ server ])
75 95
76 await uploadVideo(server.url, server.accessToken, { name: 'video 6' }) 96 const now = new Date()
77 await waitJobs([ server ])
78 97
79 { 98 await uploadVideo(server.url, server.accessToken, { name: 'video 8' })
80 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info') 99 await waitJobs([ server ])
100
101 const res = await getAuditLogs(server.url, server.accessToken, now)
81 const logsString = JSON.stringify(res.body) 102 const logsString = JSON.stringify(res.body)
82 103
83 expect(logsString.includes('video 6')).to.be.true 104 expect(logsString.includes('video 7')).to.be.false
84 } 105 expect(logsString.includes('video 8')).to.be.true
106
107 expect(res.body).to.have.lengthOf(1)
108
109 const item = res.body[0]
110
111 const message = JSON.parse(item.message)
112 expect(message.domain).to.equal('videos')
113 expect(message.action).to.equal('create')
114 })
115
116 it('Should get logs with an end date', async function () {
117 this.timeout(20000)
118
119 await uploadVideo(server.url, server.accessToken, { name: 'video 9' })
120 await waitJobs([ server ])
121
122 const now1 = new Date()
123
124 await uploadVideo(server.url, server.accessToken, { name: 'video 10' })
125 await waitJobs([ server ])
126
127 const now2 = new Date()
128
129 await uploadVideo(server.url, server.accessToken, { name: 'video 11' })
130 await waitJobs([ server ])
85 131
86 { 132 const res = await getAuditLogs(server.url, server.accessToken, now1, now2)
87 const res = await getLogs(server.url, server.accessToken, now, undefined, 'warn')
88 const logsString = JSON.stringify(res.body) 133 const logsString = JSON.stringify(res.body)
89 134
90 expect(logsString.includes('video 6')).to.be.false 135 expect(logsString.includes('video 9')).to.be.false
91 } 136 expect(logsString.includes('video 10')).to.be.true
137 expect(logsString.includes('video 11')).to.be.false
138 })
92 }) 139 })
93 140
94 after(async function () { 141 after(async function () {