eslint-plugin-postgresql-security 1.5.0 → 1.5.1
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/README.md +5 -5
- package/package.json +9 -23
- package/src/constants.js +4 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +75 -0
- package/src/oxlint.d.ts +17 -0
- package/src/oxlint.js +3 -0
- package/{dist/src → src}/rules/check-query-params/index.js +2 -13
- package/{dist/src → src}/rules/no-batch-insert-loop/index.js +1 -14
- package/{dist/src → src}/rules/no-floating-query/index.js +1 -16
- package/{dist/src → src}/rules/no-hardcoded-credentials/index.js +1 -10
- package/{dist/src → src}/rules/no-insecure-ssl/index.js +0 -6
- package/{dist/src → src}/rules/no-missing-client-release/index.js +0 -17
- package/{dist/src → src}/rules/no-select-all/index.js +0 -13
- package/{dist/src → src}/rules/no-transaction-on-pool/index.js +0 -12
- package/{dist/src → src}/rules/no-unsafe-copy-from/index.js +2 -28
- package/{dist/src → src}/rules/no-unsafe-query/index.js +0 -26
- package/{dist/src → src}/rules/no-unsafe-search-path/index.js +0 -43
- package/{dist/src → src}/rules/prefer-pool-query/index.js +3 -20
- package/{dist/src → src}/rules/prevent-double-release/index.js +0 -75
- package/src/types/index.js +2 -0
- package/CHANGELOG.md +0 -150
- package/dist/AGENTS.md +0 -118
- package/dist/CHANGELOG.md +0 -150
- package/dist/LICENSE +0 -23
- package/dist/README.md +0 -169
- package/dist/package.json +0 -99
- package/dist/src/constants.d.ts +0 -6
- package/dist/src/constants.js +0 -13
- package/dist/src/index.d.ts +0 -26
- package/dist/src/index.js +0 -116
- package/dist/src/oxlint.d.ts +0 -20
- package/dist/src/oxlint.js +0 -21
- package/dist/src/rules/check-query-params/index.d.ts +0 -8
- package/dist/src/rules/no-batch-insert-loop/index.d.ts +0 -8
- package/dist/src/rules/no-floating-query/index.d.ts +0 -8
- package/dist/src/rules/no-hardcoded-credentials/index.d.ts +0 -8
- package/dist/src/rules/no-insecure-ssl/index.d.ts +0 -8
- package/dist/src/rules/no-missing-client-release/index.d.ts +0 -8
- package/dist/src/rules/no-select-all/index.d.ts +0 -8
- package/dist/src/rules/no-transaction-on-pool/index.d.ts +0 -8
- package/dist/src/rules/no-unsafe-copy-from/index.d.ts +0 -10
- package/dist/src/rules/no-unsafe-query/index.d.ts +0 -8
- package/dist/src/rules/no-unsafe-search-path/index.d.ts +0 -8
- package/dist/src/rules/prefer-pool-query/index.d.ts +0 -8
- package/dist/src/rules/prevent-double-release/index.d.ts +0 -8
- package/dist/src/types/index.js +0 -7
- package/src/__compatibility__/pg-interface.spec.ts +0 -495
- package/src/constants.ts +0 -11
- package/src/index.spec.ts +0 -14
- package/src/index.test.ts +0 -59
- package/src/index.ts +0 -130
- package/src/oxlint.spec.ts +0 -70
- package/src/oxlint.ts +0 -23
- package/src/rules/check-query-params/check-query-params.test.ts +0 -68
- package/src/rules/check-query-params/index.spec.ts +0 -117
- package/src/rules/check-query-params/index.ts +0 -106
- package/src/rules/no-batch-insert-loop/index.spec.ts +0 -105
- package/src/rules/no-batch-insert-loop/index.ts +0 -105
- package/src/rules/no-batch-insert-loop/no-batch-insert-loop.test.ts +0 -68
- package/src/rules/no-floating-query/index.spec.ts +0 -112
- package/src/rules/no-floating-query/index.ts +0 -81
- package/src/rules/no-floating-query/no-floating-query.test.ts +0 -68
- package/src/rules/no-hardcoded-credentials/index.spec.ts +0 -38
- package/src/rules/no-hardcoded-credentials/index.ts +0 -93
- package/src/rules/no-hardcoded-credentials/no-hardcoded-credentials.test.ts +0 -68
- package/src/rules/no-insecure-ssl/index.spec.ts +0 -40
- package/src/rules/no-insecure-ssl/index.ts +0 -81
- package/src/rules/no-insecure-ssl/no-insecure-ssl.test.ts +0 -68
- package/src/rules/no-missing-client-release/coverage-gaps.spec.ts +0 -42
- package/src/rules/no-missing-client-release/index.spec.ts +0 -52
- package/src/rules/no-missing-client-release/index.ts +0 -100
- package/src/rules/no-missing-client-release/no-missing-client-release.test.ts +0 -68
- package/src/rules/no-select-all/index.spec.ts +0 -44
- package/src/rules/no-select-all/index.ts +0 -92
- package/src/rules/no-select-all/no-select-all.test.ts +0 -68
- package/src/rules/no-transaction-on-pool/index.spec.ts +0 -36
- package/src/rules/no-transaction-on-pool/index.ts +0 -85
- package/src/rules/no-transaction-on-pool/no-transaction-on-pool.test.ts +0 -68
- package/src/rules/no-unsafe-copy-from/coverage-gaps.spec.ts +0 -76
- package/src/rules/no-unsafe-copy-from/index.spec.ts +0 -274
- package/src/rules/no-unsafe-copy-from/index.ts +0 -226
- package/src/rules/no-unsafe-copy-from/no-unsafe-copy-from.test.ts +0 -78
- package/src/rules/no-unsafe-query/coverage-gaps.spec.ts +0 -61
- package/src/rules/no-unsafe-query/index.spec.ts +0 -103
- package/src/rules/no-unsafe-query/index.ts +0 -149
- package/src/rules/no-unsafe-query/no-unsafe-query.test.ts +0 -73
- package/src/rules/no-unsafe-search-path/index.spec.ts +0 -46
- package/src/rules/no-unsafe-search-path/index.ts +0 -164
- package/src/rules/no-unsafe-search-path/no-unsafe-search-path.test.ts +0 -68
- package/src/rules/prefer-pool-query/coverage-gaps.spec.ts +0 -76
- package/src/rules/prefer-pool-query/index.spec.ts +0 -97
- package/src/rules/prefer-pool-query/index.ts +0 -118
- package/src/rules/prefer-pool-query/prefer-pool-query.test.ts +0 -68
- package/src/rules/prevent-double-release/coverage-gaps.spec.ts +0 -538
- package/src/rules/prevent-double-release/index.spec.ts +0 -824
- package/src/rules/prevent-double-release/index.ts +0 -534
- package/src/rules/prevent-double-release/prevent-double-release.test.ts +0 -70
- package/src/types/index.ts +0 -58
- /package/{dist/src → src}/types/index.d.ts +0 -0
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pg Interface Compatibility Tests
|
|
3
|
-
*
|
|
4
|
-
* PURPOSE:
|
|
5
|
-
* These tests verify that the 'pg' package exports the interfaces, classes,
|
|
6
|
-
* methods, and type signatures that our ESLint rules depend on. If any of
|
|
7
|
-
* these tests fail after a pg version update, it indicates a breaking change
|
|
8
|
-
* that may require rule updates.
|
|
9
|
-
*
|
|
10
|
-
* HOW IT WORKS:
|
|
11
|
-
* - We import the 'pg' package and verify its public API
|
|
12
|
-
* - We test class existence, method signatures, and property shapes
|
|
13
|
-
* - We do NOT test runtime behavior (that's what pg's own tests do)
|
|
14
|
-
*
|
|
15
|
-
* WHEN THIS FAILS:
|
|
16
|
-
* 1. Check the pg changelog for the tested version
|
|
17
|
-
* 2. Review which rules depend on the changed interfaces
|
|
18
|
-
* 3. Update rules and/or add new test cases for changed behavior
|
|
19
|
-
* 4. Update peerDependencies in package.json if needed
|
|
20
|
-
*
|
|
21
|
-
* @sdk pg
|
|
22
|
-
* @version-tested 8.x
|
|
23
|
-
* @last-updated 2026-01-02
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import { describe, it, expect, beforeAll } from 'vitest';
|
|
27
|
-
|
|
28
|
-
// We dynamically import to handle cases where pg might not be installed
|
|
29
|
-
let pg: typeof import('pg');
|
|
30
|
-
|
|
31
|
-
beforeAll(async () => {
|
|
32
|
-
try {
|
|
33
|
-
pg = await import('pg');
|
|
34
|
-
} catch {
|
|
35
|
-
throw new Error(
|
|
36
|
-
'pg package is not installed. Run: pnpm add pg --save-dev -w'
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
}, 30_000); // native-addon packages can take >10s to load cold
|
|
40
|
-
|
|
41
|
-
describe('pg Interface Compatibility', () => {
|
|
42
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
43
|
-
// CORE EXPORTS
|
|
44
|
-
// Rules: All rules check for Client/Pool class usage
|
|
45
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
46
|
-
|
|
47
|
-
describe('Core Exports', () => {
|
|
48
|
-
it('exports Client class (used by all rules)', () => {
|
|
49
|
-
expect(pg.Client).toBeDefined();
|
|
50
|
-
expect(typeof pg.Client).toBe('function');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('exports Pool class (used by all rules)', () => {
|
|
54
|
-
expect(pg.Pool).toBeDefined();
|
|
55
|
-
expect(typeof pg.Pool).toBe('function');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('exports Query class (used for advanced query patterns)', () => {
|
|
59
|
-
// Some versions export Query, some don't - this is informational
|
|
60
|
-
// Our rules don't strictly depend on this
|
|
61
|
-
expect(pg.Query).toBeDefined();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('exports types object (for TypeOIDs)', () => {
|
|
65
|
-
expect(pg.types).toBeDefined();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('default export equals named exports', () => {
|
|
69
|
-
// Some import styles use default, some use named
|
|
70
|
-
expect(pg.default?.Client || pg.Client).toBeDefined();
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
75
|
-
// CLIENT CLASS INTERFACE
|
|
76
|
-
// Rules: no-unsafe-query, no-hardcoded-credentials, no-insecure-ssl,
|
|
77
|
-
// check-query-params, no-floating-query
|
|
78
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
79
|
-
|
|
80
|
-
describe('Client Interface', () => {
|
|
81
|
-
describe('Constructor (Rules: no-hardcoded-credentials, no-insecure-ssl)', () => {
|
|
82
|
-
it('Client constructor accepts config object', () => {
|
|
83
|
-
// We're testing that Client can be instantiated with a config
|
|
84
|
-
// This matters for rules checking connection patterns
|
|
85
|
-
expect(pg.Client.length).toBeGreaterThanOrEqual(0); // accepts 0+ args
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('Client can be instantiated without throwing', () => {
|
|
89
|
-
// Verify the constructor pattern works (no actual connection)
|
|
90
|
-
expect(() => {
|
|
91
|
-
// Just verify the class exists and is instantiable
|
|
92
|
-
// We don't check the instance because it would try to connect
|
|
93
|
-
void new pg.Client({ host: 'localhost', port: 5432 });
|
|
94
|
-
}).toBeDefined();
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('Prototype Methods (Critical for Rule Detection)', () => {
|
|
99
|
-
it('Client.prototype.query exists (Rules: no-unsafe-query, check-query-params)', () => {
|
|
100
|
-
expect(pg.Client.prototype.query).toBeDefined();
|
|
101
|
-
expect(typeof pg.Client.prototype.query).toBe('function');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('Client.prototype.connect exists (Rules: no-missing-client-release)', () => {
|
|
105
|
-
expect(pg.Client.prototype.connect).toBeDefined();
|
|
106
|
-
expect(typeof pg.Client.prototype.connect).toBe('function');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('Client.prototype.end exists (connection cleanup)', () => {
|
|
110
|
-
expect(pg.Client.prototype.end).toBeDefined();
|
|
111
|
-
expect(typeof pg.Client.prototype.end).toBe('function');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('Client.prototype does NOT have release (it is on PoolClient)', () => {
|
|
115
|
-
// IMPORTANT: release() is NOT on Client.prototype
|
|
116
|
-
// It's dynamically added to PoolClient instances by Pool.connect()
|
|
117
|
-
// Our rules check for 'client.release()' calls on variables that
|
|
118
|
-
// came from pool.connect(), not from new Client()
|
|
119
|
-
// This test documents that distinction
|
|
120
|
-
// @ts-expect-error - release does not exist on Client.prototype, testing that it's undefined
|
|
121
|
-
expect(pg.Client.prototype.release).toBeUndefined();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('Client.prototype.on exists (event emitter pattern)', () => {
|
|
125
|
-
// Client extends EventEmitter for error handling
|
|
126
|
-
expect(pg.Client.prototype.on).toBeDefined();
|
|
127
|
-
expect(typeof pg.Client.prototype.on).toBe('function');
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
describe('Query Method Signatures (Rules: no-unsafe-query, check-query-params)', () => {
|
|
132
|
-
// Our rules inspect query() call patterns
|
|
133
|
-
it('query method is callable', () => {
|
|
134
|
-
expect(pg.Client.prototype.query).toBeDefined();
|
|
135
|
-
expect(typeof pg.Client.prototype.query).toBe('function');
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('query method accepts multiple arguments (text, values, callback)', () => {
|
|
139
|
-
// pg.query(text) - simple query
|
|
140
|
-
// pg.query(text, values) - parameterized query
|
|
141
|
-
// pg.query(text, values, callback) - callback style
|
|
142
|
-
// pg.query(config) - QueryConfig object
|
|
143
|
-
// The function signature should be flexible
|
|
144
|
-
expect(pg.Client.prototype.query.length).toBeGreaterThanOrEqual(0);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
150
|
-
// POOL CLASS INTERFACE
|
|
151
|
-
// Rules: prefer-pool-query, no-transaction-on-pool, no-missing-client-release,
|
|
152
|
-
// prevent-double-release
|
|
153
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
154
|
-
|
|
155
|
-
describe('Pool Interface', () => {
|
|
156
|
-
describe('Constructor (Rules: no-hardcoded-credentials, no-insecure-ssl)', () => {
|
|
157
|
-
it('Pool constructor accepts config object', () => {
|
|
158
|
-
expect(pg.Pool.length).toBeGreaterThanOrEqual(0);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('Pool can be instantiated without throwing', () => {
|
|
162
|
-
expect(() => {
|
|
163
|
-
void new pg.Pool({ host: 'localhost', port: 5432 });
|
|
164
|
-
}).toBeDefined();
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
describe('Prototype Methods (Critical for Rule Detection)', () => {
|
|
169
|
-
it('Pool.prototype.query exists (direct pool queries - Rules: prefer-pool-query)', () => {
|
|
170
|
-
expect(pg.Pool.prototype.query).toBeDefined();
|
|
171
|
-
expect(typeof pg.Pool.prototype.query).toBe('function');
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('Pool.prototype.connect exists (checkout client - Rules: no-missing-client-release)', () => {
|
|
175
|
-
expect(pg.Pool.prototype.connect).toBeDefined();
|
|
176
|
-
expect(typeof pg.Pool.prototype.connect).toBe('function');
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('Pool.prototype.end exists (close all connections)', () => {
|
|
180
|
-
expect(pg.Pool.prototype.end).toBeDefined();
|
|
181
|
-
expect(typeof pg.Pool.prototype.end).toBe('function');
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('Pool.prototype.on exists (event emitter pattern)', () => {
|
|
185
|
-
// Pool extends EventEmitter
|
|
186
|
-
expect(pg.Pool.prototype.on).toBeDefined();
|
|
187
|
-
expect(typeof pg.Pool.prototype.on).toBe('function');
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('Pool.prototype.totalCount is accessible (pool monitoring)', () => {
|
|
191
|
-
// Pool has properties for monitoring
|
|
192
|
-
// These are getters, so we verify on an instance
|
|
193
|
-
const pool = new pg.Pool({ host: 'localhost' });
|
|
194
|
-
expect(typeof pool.totalCount).toBe('number');
|
|
195
|
-
pool.end();
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('Pool.prototype.idleCount is accessible (pool monitoring)', () => {
|
|
199
|
-
const pool = new pg.Pool({ host: 'localhost' });
|
|
200
|
-
expect(typeof pool.idleCount).toBe('number');
|
|
201
|
-
pool.end();
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('Pool.prototype.waitingCount is accessible (pool monitoring)', () => {
|
|
205
|
-
const pool = new pg.Pool({ host: 'localhost' });
|
|
206
|
-
expect(typeof pool.waitingCount).toBe('number');
|
|
207
|
-
pool.end();
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
describe('Pool Configuration Options (Rules: no-hardcoded-credentials, no-insecure-ssl)', () => {
|
|
212
|
-
it('Pool accepts host config option', () => {
|
|
213
|
-
const pool = new pg.Pool({ host: 'localhost' });
|
|
214
|
-
expect(pool).toBeDefined();
|
|
215
|
-
pool.end();
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('Pool accepts port config option', () => {
|
|
219
|
-
const pool = new pg.Pool({ port: 5432 });
|
|
220
|
-
expect(pool).toBeDefined();
|
|
221
|
-
pool.end();
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('Pool accepts user config option', () => {
|
|
225
|
-
const pool = new pg.Pool({ user: 'testuser' });
|
|
226
|
-
expect(pool).toBeDefined();
|
|
227
|
-
pool.end();
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('Pool accepts password config option (Rules: no-hardcoded-credentials)', () => {
|
|
231
|
-
const pool = new pg.Pool({ password: 'testpass' });
|
|
232
|
-
expect(pool).toBeDefined();
|
|
233
|
-
pool.end();
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it('Pool accepts database config option', () => {
|
|
237
|
-
const pool = new pg.Pool({ database: 'testdb' });
|
|
238
|
-
expect(pool).toBeDefined();
|
|
239
|
-
pool.end();
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('Pool accepts connectionString config option (Rules: no-hardcoded-credentials)', () => {
|
|
243
|
-
const pool = new pg.Pool({ connectionString: 'postgres://localhost/test' });
|
|
244
|
-
expect(pool).toBeDefined();
|
|
245
|
-
pool.end();
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('Pool accepts ssl config option (Rules: no-insecure-ssl)', () => {
|
|
249
|
-
// ssl can be boolean or object
|
|
250
|
-
const pool = new pg.Pool({ ssl: true });
|
|
251
|
-
expect(pool).toBeDefined();
|
|
252
|
-
pool.end();
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it('Pool accepts ssl.rejectUnauthorized config option (Rules: no-insecure-ssl)', () => {
|
|
256
|
-
// This is what no-insecure-ssl checks for
|
|
257
|
-
const pool = new pg.Pool({ ssl: { rejectUnauthorized: true } });
|
|
258
|
-
expect(pool).toBeDefined();
|
|
259
|
-
pool.end();
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it('Pool accepts max/min pool size options', () => {
|
|
263
|
-
const pool = new pg.Pool({ max: 20, min: 5 });
|
|
264
|
-
expect(pool).toBeDefined();
|
|
265
|
-
pool.end();
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it('Pool accepts idleTimeoutMillis option', () => {
|
|
269
|
-
const pool = new pg.Pool({ idleTimeoutMillis: 30000 });
|
|
270
|
-
expect(pool).toBeDefined();
|
|
271
|
-
pool.end();
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it('Pool accepts connectionTimeoutMillis option', () => {
|
|
275
|
-
const pool = new pg.Pool({ connectionTimeoutMillis: 5000 });
|
|
276
|
-
expect(pool).toBeDefined();
|
|
277
|
-
pool.end();
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
describe('PoolClient Interface (Rules: no-missing-client-release, prevent-double-release)', () => {
|
|
282
|
-
// Note: We can't easily get a real PoolClient without a database connection.
|
|
283
|
-
// Instead, we document the expected interface here.
|
|
284
|
-
|
|
285
|
-
it('Pool.connect returns a thenable (for await pool.connect())', () => {
|
|
286
|
-
// This is critical - Pool.connect() must return a Promise<PoolClient>
|
|
287
|
-
expect(pg.Pool.prototype.connect).toBeDefined();
|
|
288
|
-
expect(typeof pg.Pool.prototype.connect).toBe('function');
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
294
|
-
// QUERY RESULT INTERFACE
|
|
295
|
-
// Rules: check-query-params, no-select-all
|
|
296
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
297
|
-
|
|
298
|
-
describe('Query Result Interface', () => {
|
|
299
|
-
it('QueryResult type is expected to have rows property', () => {
|
|
300
|
-
// Our rules don't check QueryResult at runtime, but we document the expectation
|
|
301
|
-
// QueryResult.rows: any[]
|
|
302
|
-
// QueryResult.rowCount: number
|
|
303
|
-
// QueryResult.command: string
|
|
304
|
-
expect(pg.Client.prototype.query).toBeDefined();
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
309
|
-
// SQL COMMAND PATTERNS
|
|
310
|
-
// Rules: no-unsafe-query, no-unsafe-copy-from, no-unsafe-search-path,
|
|
311
|
-
// no-transaction-on-pool, prefer-pool-query
|
|
312
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
313
|
-
|
|
314
|
-
describe('SQL Command Patterns (AST-based detection)', () => {
|
|
315
|
-
// These tests document the SQL patterns our rules detect
|
|
316
|
-
// The rules use AST analysis, not runtime execution
|
|
317
|
-
|
|
318
|
-
describe('Transaction Commands (Rules: no-transaction-on-pool, prefer-pool-query)', () => {
|
|
319
|
-
it('query accepts BEGIN statements', () => {
|
|
320
|
-
// Our rule detects: pool.query('BEGIN')
|
|
321
|
-
expect(pg.Client.prototype.query).toBeDefined();
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
it('query accepts COMMIT statements', () => {
|
|
325
|
-
// Our rule detects: pool.query('COMMIT')
|
|
326
|
-
expect(pg.Client.prototype.query).toBeDefined();
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it('query accepts ROLLBACK statements', () => {
|
|
330
|
-
// Our rule detects: pool.query('ROLLBACK')
|
|
331
|
-
expect(pg.Client.prototype.query).toBeDefined();
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
describe('COPY FROM Commands (Rules: no-unsafe-copy-from)', () => {
|
|
336
|
-
it('query accepts COPY commands', () => {
|
|
337
|
-
// Our rule detects: client.query('COPY ... FROM ...')
|
|
338
|
-
expect(pg.Client.prototype.query).toBeDefined();
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
describe('Search Path Commands (Rules: no-unsafe-search-path)', () => {
|
|
343
|
-
it('query accepts SET statements', () => {
|
|
344
|
-
// Our rule detects: client.query("SET search_path TO ...")
|
|
345
|
-
expect(pg.Client.prototype.query).toBeDefined();
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
describe('Parameterized Query Patterns (Rules: no-unsafe-query, check-query-params)', () => {
|
|
350
|
-
it('query accepts parameterized format with $1, $2, etc.', () => {
|
|
351
|
-
// Our rule checks for: client.query('SELECT * FROM users WHERE id = $1', [id])
|
|
352
|
-
expect(pg.Client.prototype.query).toBeDefined();
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
358
|
-
// TYPE UTILITIES
|
|
359
|
-
// Used for advanced type checking in rules
|
|
360
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
361
|
-
|
|
362
|
-
describe('Type Utilities', () => {
|
|
363
|
-
it('types object provides OID mappings', () => {
|
|
364
|
-
expect(pg.types).toBeDefined();
|
|
365
|
-
expect(typeof pg.types).toBe('object');
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
it('types.getTypeParser exists', () => {
|
|
369
|
-
expect(pg.types.getTypeParser).toBeDefined();
|
|
370
|
-
expect(typeof pg.types.getTypeParser).toBe('function');
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it('types.setTypeParser exists', () => {
|
|
374
|
-
expect(pg.types.setTypeParser).toBeDefined();
|
|
375
|
-
expect(typeof pg.types.setTypeParser).toBe('function');
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
it('types.builtins exists with OID constants', () => {
|
|
379
|
-
// pg.types.builtins contains OID constants like INT4, TEXT, etc.
|
|
380
|
-
expect(pg.types.builtins).toBeDefined();
|
|
381
|
-
expect(typeof pg.types.builtins).toBe('object');
|
|
382
|
-
});
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
386
|
-
// ERROR HANDLING
|
|
387
|
-
// Rules: no-floating-query (checks for unhandled rejections)
|
|
388
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
389
|
-
|
|
390
|
-
describe('Error Handling', () => {
|
|
391
|
-
it('Client supports error event listener', () => {
|
|
392
|
-
expect(pg.Client.prototype.on).toBeDefined();
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
it('Pool supports error event listener', () => {
|
|
396
|
-
expect(pg.Pool.prototype.on).toBeDefined();
|
|
397
|
-
});
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
401
|
-
// NATIVE BINDINGS (OPTIONAL)
|
|
402
|
-
// Some users use pg-native for performance
|
|
403
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
404
|
-
|
|
405
|
-
describe('Native Bindings (optional)', () => {
|
|
406
|
-
it('pg.native may or may not exist', () => {
|
|
407
|
-
// pg.native is an optional binding that provides native libpq
|
|
408
|
-
// Our rules should work with or without it
|
|
409
|
-
// We just document its potential existence
|
|
410
|
-
expect(pg.Client).toBeDefined(); // Core always exists
|
|
411
|
-
});
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
415
|
-
// PACKAGE METADATA
|
|
416
|
-
// Useful for debugging compatibility issues
|
|
417
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
418
|
-
|
|
419
|
-
describe('Package Metadata', () => {
|
|
420
|
-
it('has discoverable version', async () => {
|
|
421
|
-
const pkgPath = require.resolve('pg/package.json');
|
|
422
|
-
const pkg = await import(pkgPath, { with: { type: 'json' } }).then(
|
|
423
|
-
(m) => m.default
|
|
424
|
-
);
|
|
425
|
-
expect(pkg.version).toBeDefined();
|
|
426
|
-
console.log(`📦 pg version: ${pkg.version}`);
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
it('version satisfies our peerDependency range', async () => {
|
|
430
|
-
const pkgPath = require.resolve('pg/package.json');
|
|
431
|
-
const pkg = await import(pkgPath, { with: { type: 'json' } }).then(
|
|
432
|
-
(m) => m.default
|
|
433
|
-
);
|
|
434
|
-
// Our peerDeps: ^6.0.0 || ^7.0.0 || ^8.0.0
|
|
435
|
-
const major = parseInt(pkg.version.split('.')[0], 10);
|
|
436
|
-
expect(major).toBeGreaterThanOrEqual(6);
|
|
437
|
-
expect(major).toBeLessThanOrEqual(9); // Update when we support pg 10+
|
|
438
|
-
});
|
|
439
|
-
});
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
443
|
-
// INTERFACE SHAPE DOCUMENTATION
|
|
444
|
-
// This section documents the expected shapes for rule authors
|
|
445
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Expected pg exports our rules depend on:
|
|
449
|
-
*
|
|
450
|
-
* CLASSES:
|
|
451
|
-
* - pg.Client
|
|
452
|
-
* - constructor(config?: ClientConfig)
|
|
453
|
-
* - .prototype.query(text, values?, callback?) -> Promise<QueryResult>
|
|
454
|
-
* - .prototype.connect() -> Promise<void>
|
|
455
|
-
* - .prototype.end() -> Promise<void>
|
|
456
|
-
* - .prototype.on(event, handler) -> this
|
|
457
|
-
*
|
|
458
|
-
* - pg.Pool
|
|
459
|
-
* - constructor(config?: PoolConfig)
|
|
460
|
-
* - .prototype.query(text, values?, callback?) -> Promise<QueryResult>
|
|
461
|
-
* - .prototype.connect() -> Promise<PoolClient>
|
|
462
|
-
* - .prototype.end() -> Promise<void>
|
|
463
|
-
* - .prototype.on(event, handler) -> this
|
|
464
|
-
* - .totalCount: number
|
|
465
|
-
* - .idleCount: number
|
|
466
|
-
* - .waitingCount: number
|
|
467
|
-
*
|
|
468
|
-
* - PoolClient (extends Client)
|
|
469
|
-
* - .release(err?: Error) -> void // Added dynamically by Pool.connect()
|
|
470
|
-
*
|
|
471
|
-
* CONFIG OPTIONS (checked by rules):
|
|
472
|
-
* - host: string
|
|
473
|
-
* - port: number
|
|
474
|
-
* - user: string
|
|
475
|
-
* - password: string // no-hardcoded-credentials
|
|
476
|
-
* - database: string
|
|
477
|
-
* - connectionString: string // no-hardcoded-credentials
|
|
478
|
-
* - ssl: boolean | TlsOptions // no-insecure-ssl
|
|
479
|
-
* - rejectUnauthorized: boolean // no-insecure-ssl
|
|
480
|
-
* - max: number
|
|
481
|
-
* - min: number
|
|
482
|
-
* - idleTimeoutMillis: number
|
|
483
|
-
* - connectionTimeoutMillis: number
|
|
484
|
-
*
|
|
485
|
-
* SQL PATTERNS DETECTED BY RULES:
|
|
486
|
-
* - BEGIN, COMMIT, ROLLBACK // no-transaction-on-pool
|
|
487
|
-
* - COPY ... FROM ... // no-unsafe-copy-from
|
|
488
|
-
* - SET search_path TO ... // no-unsafe-search-path
|
|
489
|
-
* - $1, $2, ... placeholders // check-query-params
|
|
490
|
-
*
|
|
491
|
-
* TYPE UTILITIES:
|
|
492
|
-
* - pg.types.getTypeParser(oid) -> Parser
|
|
493
|
-
* - pg.types.setTypeParser(oid, parser) -> void
|
|
494
|
-
* - pg.types.builtins -> { INT4: number, TEXT: number, ... }
|
|
495
|
-
*/
|
package/src/constants.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
-
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
-
* MIT license that can be found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
* Connection string protocols for PostgreSQL
|
|
10
|
-
*/
|
|
11
|
-
export const PG_PROTOCOLS = ['postgres://', 'postgresql://'];
|
package/src/index.spec.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import plugin from './index';
|
|
3
|
-
|
|
4
|
-
describe('eslint-plugin-postgresql-security', () => {
|
|
5
|
-
it('should export a plugin object', () => {
|
|
6
|
-
expect(plugin).toBeDefined();
|
|
7
|
-
expect(plugin.meta).toBeDefined();
|
|
8
|
-
expect(plugin.meta?.name).toBe('eslint-plugin-postgresql-security');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('should export rules object', () => {
|
|
12
|
-
expect(plugin.rules).toBeDefined();
|
|
13
|
-
});
|
|
14
|
-
});
|
package/src/index.test.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import plugin from './index';
|
|
3
|
-
import { rules, configs } from './index';
|
|
4
|
-
|
|
5
|
-
describe('eslint-plugin-postgresql-security plugin interface', () => {
|
|
6
|
-
it('should export correct meta information', () => {
|
|
7
|
-
expect(plugin.meta).toBeDefined();
|
|
8
|
-
expect(plugin.meta?.name).toBe('eslint-plugin-postgresql-security');
|
|
9
|
-
expect(plugin.meta?.version).toBeDefined();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should export all pg rules', () => {
|
|
13
|
-
expect(plugin.rules).toBeDefined();
|
|
14
|
-
const ruleKeys = Object.keys(plugin.rules || {});
|
|
15
|
-
expect(ruleKeys).toEqual([
|
|
16
|
-
'no-unsafe-query',
|
|
17
|
-
'no-insecure-ssl',
|
|
18
|
-
'no-hardcoded-credentials',
|
|
19
|
-
'check-query-params',
|
|
20
|
-
'no-missing-client-release',
|
|
21
|
-
'no-transaction-on-pool',
|
|
22
|
-
'no-floating-query',
|
|
23
|
-
'no-select-all',
|
|
24
|
-
'prefer-pool-query',
|
|
25
|
-
'no-batch-insert-loop',
|
|
26
|
-
'no-unsafe-search-path',
|
|
27
|
-
'no-unsafe-copy-from',
|
|
28
|
-
'prevent-double-release',
|
|
29
|
-
]);
|
|
30
|
-
expect(ruleKeys.length).toBe(13);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('configurations', () => {
|
|
34
|
-
it('should provide recommended configuration', () => {
|
|
35
|
-
expect(configs.recommended).toBeDefined();
|
|
36
|
-
expect(configs.recommended.plugins?.['pg']).toBeDefined();
|
|
37
|
-
|
|
38
|
-
const recommendedRules = configs.recommended.rules || {};
|
|
39
|
-
Object.keys(recommendedRules).forEach(ruleName => {
|
|
40
|
-
expect(ruleName).toMatch(/^pg\//);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
expect(recommendedRules['pg/no-unsafe-query']).toBe('error');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should provide strict configuration', () => {
|
|
47
|
-
expect(configs.strict).toBeDefined();
|
|
48
|
-
expect(configs.strict.plugins?.['pg']).toBeDefined();
|
|
49
|
-
|
|
50
|
-
const strictRules = configs.strict.rules || {};
|
|
51
|
-
Object.keys(strictRules).forEach(ruleName => {
|
|
52
|
-
expect(ruleName).toMatch(/^pg\//);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
expect(strictRules['pg/no-unsafe-query']).toBe('error');
|
|
56
|
-
expect(Object.keys(strictRules).length).toBe(Object.keys(rules).length);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|