mirror of
https://github.com/streamwall/streamwall.git
synced 2025-12-06 01:45:37 -05:00
Start working on coverage
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "streamwall",
|
||||
"version": "1.0.0",
|
||||
"description": "View streams in a grid",
|
||||
"description": "View streams in a grid",
|
||||
"main": "./.webpack/main",
|
||||
"scripts": {
|
||||
"start": "electron-forge start -- --trace-warnings --control.address=http://localhost:4444 --control.username=admin --control.password=password",
|
||||
"make": "electron-forge make",
|
||||
"package": "electron-forge package",
|
||||
"publish": "electron-forge publish",
|
||||
"test": "jest",
|
||||
"test": "jest --verbose --detectOpenHandles --no-stack-trace-limit",
|
||||
"test:ci": "jest --ci --reporters=default --reporters=jest-junit --coverage"
|
||||
},
|
||||
"author": "Max Goodhart <c@chromakode.com>",
|
||||
|
||||
39
src/node/auth.test.js
Normal file
39
src/node/auth.test.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Auth } from './auth'
|
||||
|
||||
describe('Auth', () => {
|
||||
it('uses provided salt from persistData', () => {
|
||||
const auth = new Auth({
|
||||
adminUsername: 'admin',
|
||||
adminPassword: 'pass',
|
||||
persistData: { salt: 'MY_FIXED_SALT' }
|
||||
})
|
||||
expect(auth.salt).toBe('MY_FIXED_SALT')
|
||||
})
|
||||
|
||||
it('throws on invalid role', async () => {
|
||||
const auth = new Auth({ adminUsername: 'admin', adminPassword: 'pass' })
|
||||
await expect(
|
||||
auth.createToken({ kind: 'session', role: 'notreal', name: 'Test' })
|
||||
).rejects.toThrow('invalid role')
|
||||
})
|
||||
|
||||
it('logs when logEnabled is true', async () => {
|
||||
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {})
|
||||
const auth = new Auth({
|
||||
adminUsername: 'admin',
|
||||
adminPassword: 'pass',
|
||||
logEnabled: true
|
||||
})
|
||||
await auth.createToken({ kind: 'session', role: 'operator', name: 'Test' })
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Created session token:'),
|
||||
expect.objectContaining({ role: 'operator', name: 'Test' })
|
||||
)
|
||||
consoleSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('silently ignores deleting a non-existent token', () => {
|
||||
const auth = new Auth({ adminUsername: 'admin', adminPassword: 'pass' })
|
||||
expect(() => auth.deleteToken('nope')).not.toThrow()
|
||||
})
|
||||
})
|
||||
@@ -212,6 +212,17 @@ describe('streamwall server', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects websocket upgrade if origin is invalid', async () => {
|
||||
// Make a raw WebSocket connection with a bogus origin
|
||||
const badWs = new WebSocket(`ws://localhost:${port}/ws`, [], {
|
||||
origin: 'http://evilsite.com', // not the expectedOrigin
|
||||
})
|
||||
const closePromise = once(badWs, 'close')
|
||||
const [code] = await closePromise
|
||||
expect(code).toBe(401)
|
||||
// or just expect the server forcibly closed the connection
|
||||
})
|
||||
|
||||
describe('admin role', () => {
|
||||
it('can view tokens', async () => {
|
||||
await auth.createToken({
|
||||
|
||||
Reference in New Issue
Block a user