-
Notifications
You must be signed in to change notification settings - Fork 10
fix(db): unmask password when fetching database connection string #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||||||||||||||||||
| import { describe, expect, it } from 'vitest'; | ||||||||||||||||||||||
| import { spliceDatabasePassword } from './oss.js'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| describe('spliceDatabasePassword', () => { | ||||||||||||||||||||||
| // Real shape from cloud `/api/metadata/database-connection-string` | ||||||||||||||||||||||
| const masked = 'postgresql://postgres:********@b4jh2kvi.us-east.database.insforge.app:5432/insforge?sslmode=require'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| it('replaces the masked password with the real one', () => { | ||||||||||||||||||||||
| const result = spliceDatabasePassword(masked, '66666b99c46288a34220009437d8a3c2'); | ||||||||||||||||||||||
| expect(result).toBe('postgresql://postgres:66666b99c46288a34220009437d8a3c2@b4jh2kvi.us-east.database.insforge.app:5432/insforge?sslmode=require'); | ||||||||||||||||||||||
| expect(result).not.toContain('********'); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| it('preserves the rest of the URL exactly (host, port, db, query)', () => { | ||||||||||||||||||||||
| const result = spliceDatabasePassword(masked, 'pw'); | ||||||||||||||||||||||
| expect(result).toContain('@b4jh2kvi.us-east.database.insforge.app:5432/insforge?sslmode=require'); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| it('handles passwords containing special characters', () => { | ||||||||||||||||||||||
| // Backend already URL-encodes special chars; we just inject verbatim. | ||||||||||||||||||||||
| const result = spliceDatabasePassword(masked, 'p%40ss%3Aword'); | ||||||||||||||||||||||
| expect(result).toContain(':p%40ss%3Aword@'); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| it('only replaces the first `://user:...@` block (in case the URL has @ elsewhere)', () => { | ||||||||||||||||||||||
| const m = 'postgresql://postgres:********@db.host.app:5432/insforge?options=user%3D%40admin'; | ||||||||||||||||||||||
| const result = spliceDatabasePassword(m, 'realpw'); | ||||||||||||||||||||||
| expect(result).toBe('postgresql://postgres:realpw@db.host.app:5432/insforge?options=user%3D%40admin'); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
Comment on lines
+25
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edge-case test description and fixture are misaligned Line 26 encodes Suggested test fixture adjustment- it('only replaces the first `://user:...@` block (in case the URL has @ elsewhere)', () => {
- const m = 'postgresql://postgres:********@db.host.app:5432/insforge?options=user%3D%40admin';
+ it('only replaces the first `://user:...@` block (in case the URL has @ elsewhere)', () => {
+ const m = 'postgresql://postgres:********@db.host.app:5432/insforge?note=owner@team';
const result = spliceDatabasePassword(m, 'realpw');
- expect(result).toBe('postgresql://postgres:realpw@db.host.app:5432/insforge?options=user%3D%40admin');
+ expect(result).toBe('postgresql://postgres:realpw@db.host.app:5432/insforge?note=owner@team');
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| }); | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don’t silently swallow parse/read failures for
package.jsonThe empty catch hides malformed
package.jsonand permission/read errors, making setup skips hard to diagnose.Suggested fix
🤖 Prompt for AI Agents