@sqldoc/ns-anon 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/src/__tests__/anon.test.ts +0 -94
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@sqldoc/ns-anon",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"description": "PostgreSQL Anonymizer namespace for sqldoc -- generates SECURITY LABEL statements",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -14,15 +14,16 @@
|
|
|
14
14
|
"types": "./src/index.ts",
|
|
15
15
|
"files": [
|
|
16
16
|
"src",
|
|
17
|
+
"!src/__tests__",
|
|
17
18
|
"package.json"
|
|
18
19
|
],
|
|
19
20
|
"peerDependencies": {
|
|
20
|
-
"@sqldoc/core": "0.0.
|
|
21
|
+
"@sqldoc/core": "0.0.2"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"typescript": "^5.9.3",
|
|
24
25
|
"vitest": "^4.1.0",
|
|
25
|
-
"@sqldoc/core": "0.0.
|
|
26
|
+
"@sqldoc/core": "0.0.2"
|
|
26
27
|
},
|
|
27
28
|
"scripts": {
|
|
28
29
|
"test": "vitest run"
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { TagContext } from '@sqldoc/core'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import plugin from '../index'
|
|
4
|
-
|
|
5
|
-
function makeCtx(overrides: Partial<TagContext> = {}): TagContext {
|
|
6
|
-
return {
|
|
7
|
-
target: 'column',
|
|
8
|
-
objectName: 'users',
|
|
9
|
-
columnName: 'email',
|
|
10
|
-
tag: { name: 'mask', args: ['anon.fake_email()'] },
|
|
11
|
-
namespaceTags: [],
|
|
12
|
-
siblingTags: [],
|
|
13
|
-
fileTags: [],
|
|
14
|
-
astNode: null,
|
|
15
|
-
fileStatements: [],
|
|
16
|
-
config: {},
|
|
17
|
-
filePath: 'test.sql',
|
|
18
|
-
...overrides,
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
describe('ns-anon plugin', () => {
|
|
23
|
-
it('exports apiVersion === 1', () => {
|
|
24
|
-
expect(plugin.apiVersion).toBe(1)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('exports name === "anon"', () => {
|
|
28
|
-
expect(plugin.name).toBe('anon')
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it('has mask, fake, and $self tag entries', () => {
|
|
32
|
-
expect(plugin.tags).toHaveProperty('mask')
|
|
33
|
-
expect(plugin.tags).toHaveProperty('fake')
|
|
34
|
-
expect(plugin.tags).toHaveProperty('$self')
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
describe('onTag', () => {
|
|
38
|
-
it('@anon.mask produces SECURITY LABEL statement', () => {
|
|
39
|
-
const ctx = makeCtx({
|
|
40
|
-
objectName: 'users',
|
|
41
|
-
columnName: 'last_name',
|
|
42
|
-
tag: { name: 'mask', args: ['anon.fake_last_name()'] },
|
|
43
|
-
})
|
|
44
|
-
const result = plugin.onTag!(ctx) as any
|
|
45
|
-
expect(result.sql).toEqual([
|
|
46
|
-
{
|
|
47
|
-
sql: `SECURITY LABEL FOR anon ON COLUMN "users"."last_name" IS 'MASKED WITH FUNCTION anon.fake_last_name()';`,
|
|
48
|
-
},
|
|
49
|
-
])
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('@anon.fake produces SECURITY LABEL statement', () => {
|
|
53
|
-
const ctx = makeCtx({
|
|
54
|
-
objectName: 'users',
|
|
55
|
-
columnName: 'email',
|
|
56
|
-
tag: { name: 'fake', args: ['anon.fake_email()'] },
|
|
57
|
-
})
|
|
58
|
-
const result = plugin.onTag!(ctx) as any
|
|
59
|
-
expect(result.sql).toEqual([
|
|
60
|
-
{
|
|
61
|
-
sql: `SECURITY LABEL FOR anon ON COLUMN "users"."email" IS 'MASKED WITH FUNCTION anon.fake_email()';`,
|
|
62
|
-
},
|
|
63
|
-
])
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('@anon.$self with no args on table returns undefined', () => {
|
|
67
|
-
const ctx = makeCtx({
|
|
68
|
-
target: 'table',
|
|
69
|
-
columnName: undefined,
|
|
70
|
-
tag: { name: '$self', args: {} },
|
|
71
|
-
})
|
|
72
|
-
const result = plugin.onTag!(ctx)
|
|
73
|
-
expect(result).toBeUndefined()
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('mask with missing columnName returns undefined', () => {
|
|
77
|
-
const ctx = makeCtx({
|
|
78
|
-
columnName: undefined,
|
|
79
|
-
tag: { name: 'mask', args: ['anon.fake_last_name()'] },
|
|
80
|
-
})
|
|
81
|
-
const result = plugin.onTag!(ctx)
|
|
82
|
-
expect(result).toBeUndefined()
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('fake with missing columnName returns undefined', () => {
|
|
86
|
-
const ctx = makeCtx({
|
|
87
|
-
columnName: undefined,
|
|
88
|
-
tag: { name: 'fake', args: ['anon.fake_email()'] },
|
|
89
|
-
})
|
|
90
|
-
const result = plugin.onTag!(ctx)
|
|
91
|
-
expect(result).toBeUndefined()
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
})
|