-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4330 from FlowFuse/audit-log-export
Audit log export
- Loading branch information
Showing
6 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,4 +240,69 @@ describe('Audit Log > Platform', async function () { | |
logEntry.body.team.should.have.property('id', TEAM.hashid) | ||
logEntry.body.team.should.have.property('name', TEAM.name) | ||
}) | ||
|
||
describe('audit-log/export', async function () { | ||
const TestObjects = { | ||
tokens: {} | ||
} | ||
|
||
async function login (username, password) { | ||
const response = await app.inject({ | ||
method: 'POST', | ||
url: '/account/login', | ||
payload: { username, password, remember: false } | ||
}) | ||
response.cookies.should.have.length(1) | ||
response.cookies[0].should.have.property('name', 'sid') | ||
TestObjects.tokens[username] = response.cookies[0].value | ||
} | ||
|
||
before(async function () { | ||
TestObjects.alice = await app.db.models.User.byUsername('alice') | ||
TestObjects.bob = await app.db.models.User.create({ username: 'bob', name: 'Bob Solo', email: '[email protected]', email_verified: true, password: 'bbPassword' }) | ||
await login('alice', 'aaPassword') | ||
await login('bob', 'bbPassword') | ||
}) | ||
|
||
it('Audit log should be accessible to admin', async function () { | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/api/v1/admin/audit-log/export', | ||
query: { | ||
limit: 5 | ||
}, | ||
cookies: { sid: TestObjects.tokens.alice } | ||
}) | ||
response.statusCode.should.equal(200) | ||
}) | ||
|
||
it('Audit log should not be accessible to non admin', async function () { | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/api/v1/admin/audit-log/export', | ||
query: { | ||
limit: 5 | ||
}, | ||
cookies: { sid: TestObjects.tokens.bob } | ||
}) | ||
response.statusCode.should.equal(403) | ||
}) | ||
|
||
it('Audit log should have header', async function () { | ||
await platformLogger.platform.stack.created(0, null, STACK) | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/api/v1/admin/audit-log/export', | ||
query: { | ||
limit: 5 | ||
}, | ||
cookies: { sid: TestObjects.tokens.alice } | ||
}) | ||
response.statusCode.should.equal(200) | ||
const body = response.body | ||
const rows = body.split('\r\n') | ||
rows.should.have.length(2) | ||
rows[0].should.equal('id,event,body,scope,trigger,createdAt') | ||
}) | ||
}) | ||
}) |