Skip to content
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 to support full eslint rule configurations #289

Merged
merged 5 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
//"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
Expand All @@ -16,16 +16,6 @@
// this is only needed because `createPromiseCallback` uses arguments to support the callback-style api
// we should strongly consider dropping the callback and sync api variants (in say v6) to reduce the
// surface area and complexity of tough-cookie
"prefer-rest-params": "warn",
"@typescript-eslint/no-unused-vars": "warn",

// used by callSync which needs to use Function because it's used by several apis
"@typescript-eslint/ban-types": "warn",

// there are several areas that still have ts-ignore comments, let's try to eliminate those
"@typescript-eslint/ban-ts-comment": "warn",

// i'd like to clean up all usages of any but the current api is just too loose
"@typescript-eslint/no-explicit-any": "warn"
"prefer-rest-params": "off"
colincasey marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion lib/__tests__/cookieJar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ it('should fix issue #197 - CookieJar().setCookie throws an error when empty coo
).rejects.toThrowError('Cookie failed to parse')
})

it('should fix issue #282 - Prototype pollution when setting a cookie with the domain __proto__', async () => {
it('should fix issue #282 - Prototype pollution when setting a cookie with the domain __proto__', () => {
const jar = new CookieJar(undefined, {
rejectPublicSuffixes: false,
})
Expand Down
73 changes: 46 additions & 27 deletions lib/__tests__/jarSerialization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,33 +201,52 @@ describe('cookieJar serialization', () => {
}

// corner cases
const cornerCases = [
{ expires: 'Infinity', key: 'infExp', value: 'infExp' },
{ maxAge: 3600, key: 'max', value: 'max' },
{
expires,
key: 'flags',
value: 'flags',
secure: true,
httpOnly: true,
},
{
expires,
key: 'honly',
value: 'honly',
hostOnly: true,
domain: 'www.example.org',
},
]

for await (const cornerCase of cornerCases) {
const domain = cornerCase.domain ?? 'example.org'
const path = '/'
const cookie = new Cookie({ ...cornerCase, domain, path })
await jar.setCookie(cookie, 'https://www.example.org/', {
ignoreError: true,
})
}
const corner_case_1 = new Cookie({
expires: 'Infinity',
key: 'infExp',
value: 'infExp',
domain: 'example.org',
path: '/',
})
await jar.setCookie(corner_case_1, 'https://www.example.org/', {
ignoreError: true,
})

const corner_case_2 = new Cookie({
maxAge: 3600,
key: 'max',
value: 'max',
domain: 'example.org',
path: '/',
})
await jar.setCookie(corner_case_2, 'https://www.example.org/', {
ignoreError: true,
})

const corner_case_3 = new Cookie({
expires,
key: 'flags',
value: 'flags',
secure: true,
httpOnly: true,
domain: 'example.org',
path: '/',
})
await jar.setCookie(corner_case_3, 'https://www.example.org/', {
ignoreError: true,
})

const corner_case_4 = new Cookie({
expires,
key: 'honly',
value: 'honly',
hostOnly: true,
domain: 'www.example.org',
path: '/',
})
await jar.setCookie(corner_case_4, 'https://www.example.org/', {
ignoreError: true,
})
colincasey marked this conversation as resolved.
Show resolved Hide resolved
})

it('should have the expected metadata', async () => {
Expand Down
15 changes: 3 additions & 12 deletions lib/__tests__/nodeUtilFallback.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,13 @@ describe('Node util module fallback for non-node environments', () => {
)
})

it('should not be null in a node environment when custom inspect symbol cannot be retrieved (< node v10.12.0', () => {
it('should not be null in a non-node environment since we create the symbol if it does not exist', () => {
expect(
getCustomInspectSymbol({
lookupCustomInspectSymbol: () => null,
requireUtil: () => undefined,
}),
).toEqual(Symbol.for('nodejs.util.inspect.custom') || util.inspect.custom)
})

it('should be null in a non-node environment since `util` features cannot be relied on', () => {
expect(
getCustomInspectSymbol({
lookupCustomInspectSymbol: () => null,
requireUtil: () => null,
}),
).toBeNull()
})
})

describe('getUtilInspect', () => {
Expand All @@ -39,7 +30,7 @@ describe('Node util module fallback for non-node environments', () => {

it('should use fallback inspect function in a non-node environment', () => {
const inspect = getUtilInspect(() => 'fallback', {
requireUtil: () => null,
requireUtil: () => undefined,
})
expect(inspect('util.inspect')).toEqual('fallback')
})
Expand Down
Loading