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
29 changes: 0 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
"@types/jest": "^29.2.1",
"@types/js-yaml": "^4.0.5",
"@types/json-bigint": "^1.0.4",
"@types/mustache": "^4.2.2",
"@types/node": "^22.18.8",
"@types/pg": "^8.6.4",
"@types/stream-buffers": "^3.0.7",
Expand All @@ -110,7 +109,6 @@
"jest": "^29.7.0",
"js-yaml": "^4.1.0",
"json-schema-to-ts": "^3.0.0",
"mustache": "^4.2.0",
"patch-package": "^8.0.0",
"pino-pretty": "^13.1.3",
"prettier": "^2.8.8",
Expand Down
19 changes: 17 additions & 2 deletions src/test/rls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import FormData from 'form-data'
import fs from 'fs'
import yaml from 'js-yaml'
import { Knex, knex } from 'knex'
import Mustache from 'mustache'
import path from 'path'
import app from '../app'
import { getConfig } from '../config'
Expand Down Expand Up @@ -64,6 +63,22 @@ interface RlsTestSpec {
tests: TestCase[]
}

function renderRlsTemplate(template: string, values: Record<string, string>) {
const rendered = template.replace(/{{\s*([a-zA-Z0-9_]+)\s*}}/g, (_match, key: string) => {
if (!Object.prototype.hasOwnProperty.call(values, key)) {
throw new Error(`Unknown RLS template variable: ${key}`)
}

return values[key]
})

if (rendered.includes('{{')) {
throw new Error('Unsupported template tag in rls_tests.yaml')
}

return rendered
}

const testSpec = yaml.load(
fs.readFileSync(path.resolve(__dirname, 'rls_tests.yaml'), 'utf8')
) as RlsTestSpec
Expand Down Expand Up @@ -151,7 +166,7 @@ describe('RLS policies', () => {
const originalBucketName = bucketName

const testScopedSpec = yaml.load(
Mustache.render(content, {
renderRlsTemplate(content, {
uid: userId,
bucketName,
objectName,
Expand Down
Loading