Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pre-commit:
commands:
check:
glob: '*.{js,ts,jsx,tsx}'
run: oxlint {staged_files} && bun format && git add {staged_files}
run: bun oxlint {staged_files} && bun format && git add {staged_files}
31 changes: 30 additions & 1 deletion packages/wabe/src/security.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { describe, it, expect } from 'bun:test'
import { v4 as uuid } from 'uuid'
import getPort from 'get-port'
import { decode, sign } from 'jsonwebtoken'
import { gql } from 'graphql-request'
import {
Expand All @@ -8,11 +10,38 @@ import {
createUserAndUpdateRole,
getUserClient,
} from './utils/helper'
import { setupTests, closeTests } from './utils/testHelper'
import { setupTests, closeTests, getDatabaseAdapter } from './utils/testHelper'
import { RoleEnum } from 'generated/wabe'
import { Session } from './authentication/Session'
import { Wabe } from './server'
import type { DevWabeTypes } from './utils/helper'

describe('Security tests', () => {
it('should throw at server startup when rootKey is empty', async () => {
const databaseId = uuid()
const port = await getPort()

const wabe = new Wabe<DevWabeTypes>({
isProduction: false,
rootKey: '',
database: {
// @ts-expect-error
adapter: await getDatabaseAdapter(databaseId),
},
port,
schema: {
classes: [
{
name: 'Collection1',
fields: { name: { type: 'String' } },
},
],
},
})

await expect(wabe.start()).rejects.toThrow('rootKey cannot be empty')
})

it('should not return private fields (acl) on createObject, getObject and getObjects if not root', async () => {
const setup = await setupTests([
{
Expand Down
3 changes: 3 additions & 0 deletions packages/wabe/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ export class Wabe<T extends WabeTypes> {
}

async start() {
if (!this.config.rootKey || this.config.rootKey.length === 0)
throw new Error('rootKey cannot be empty')

if (this.config.authentication?.session && !this.config.authentication.session.jwtSecret)
throw new Error('Authentication session requires jwt secret')

Expand Down
3 changes: 2 additions & 1 deletion packages/wabe/src/utils/testHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const setupTests = async (
options: {
isProduction?: boolean
disableCSRFProtection?: boolean
rootKey?: string
} = {},
) => {
const databaseId = uuid()
Expand All @@ -28,7 +29,7 @@ export const setupTests = async (

const wabe = new Wabe<DevWabeTypes>({
isProduction: !!options.isProduction,
rootKey: 'dev',
rootKey: options.rootKey ?? 'dev',
database: {
// @ts-expect-error
adapter: await getDatabaseAdapter(databaseId),
Expand Down