Skip to content

Commit

Permalink
fix: allow masking of passwords with special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan committed Mar 11, 2019
1 parent a2f5772 commit e2bf26d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class Configuration {

getClientUrl(hidePassword = false): string {
if (hidePassword) {
return this.options.clientUrl!.replace(/\/\/([^:]+):(\w+)@/, '//$1:*****@');
return this.options.clientUrl!.replace(/\/\/([^:]+):(.+)@/, '//$1:*****@');
}

return this.options.clientUrl!;
Expand Down
8 changes: 8 additions & 0 deletions tests/MikroORM.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ describe('MikroORM', () => {
await expect(MikroORM.init({ dbName: 'test', baseDir: BASE_DIR, entities: [FooBaz2], cache: { enabled: false }, entitiesDirsTs: ['entities'] })).rejects.toThrowError(error);
});

test('should hide password from connection uri', async () => {
const clientUrl = 'mongodb://dev-vision:Q#ais@2d-Aa_43:ui!0d.ai6d@mongodb-replicaset-0.mongodb-replicaset.dev.svc.cluster.local:27017,mongodb-replicaset-1...';
const expected = 'mongodb://dev-vision:*****@mongodb-replicaset-0.mongodb-replicaset.dev.svc.cluster.local:27017,mongodb-replicaset-1...';
const conf = new Configuration({ clientUrl } as any, false);
const hidden = conf.getClientUrl(true);
expect(hidden).toBe(expected);
});

test('should init itself with entity manager', async () => {
const orm = await MikroORM.init({
entitiesDirs: ['entities'],
Expand Down

0 comments on commit e2bf26d

Please sign in to comment.