Skip to content

Commit

Permalink
Add lint script and apply lint fixes to codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
waldyrious authored and rplopes committed Oct 29, 2019
1 parent ae44ae7 commit 91aa02e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extends: uphold
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"test": "test"
},
"scripts": {
"lint": "uphold-scripts lint",
"test": "uphold-scripts test"
},
"dependencies": {
Expand All @@ -22,6 +23,9 @@
"devDependencies": {
"uphold-scripts": "^0.4.0"
},
"pre-commit": [
"lint"
],
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
}
Expand Down
30 changes: 19 additions & 11 deletions test/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,21 @@ describe('Anonymizer', () => {

expect(anonymize({ foo: 'foo' })).toEqual({ foo: '--REDACTED--' });
});

it('should not obfuscate recursively the keys of an object that are part of the whitelist', () => {
const anonymize = anonymizer(whitelist);

expect(anonymize({
foo: {
bar: {
baz: { bax: [2, 3, { bax: 4, [whitelist[1]]: '5' }] },
[whitelist[0]]: 'foobar',
[whitelist[2]]: 'foobiz'
expect(
anonymize({
foo: {
bar: {
baz: { bax: [2, 3, { bax: 4, [whitelist[1]]: '5' }] },
[whitelist[0]]: 'foobar',
[whitelist[2]]: 'foobiz'
}
}
}
})).toEqual({
})
).toEqual({
foo: {
bar: {
baz: { bax: ['--REDACTED--', '--REDACTED--', { bax: '--REDACTED--', [whitelist[1]]: '--REDACTED--' }] },
Expand All @@ -74,17 +76,23 @@ describe('Anonymizer', () => {
it('should not treat a `.` in the whitelist as a special character in the regexp', () => {
const anonymize = anonymizer(['foo.bar']);

expect(anonymize({ foo: { bar: 'biz' }, fooabar: 'foobiz' })).toEqual({ foo: { bar: 'biz' }, fooabar: '--REDACTED--' });
expect(anonymize({ foo: { bar: 'biz' }, fooabar: 'foobiz' })).toEqual({
foo: { bar: 'biz' },
fooabar: '--REDACTED--'
});
});

it('should allow using `*` in the whitelist path', () => {
const anonymize = anonymizer(['*.foo', '*.foobar']);

expect(anonymize({ parent: { foo: 'bar', foobar: 'foobiz' } })).toEqual({ parent: { foo: 'bar', foobar: 'foobiz' } });
expect(anonymize({ parent: { foo: 'bar', foobar: 'foobiz' } })).toEqual({
parent: { foo: 'bar', foobar: 'foobiz' }
});
});

it('should allow circular references', () => {
const object = {};

object.reference = object;

const anonymize = anonymizer(['*']);
Expand Down

0 comments on commit 91aa02e

Please sign in to comment.