Skip to content

Commit

Permalink
Revert enum type change for PrefixSecurityEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
colincasey committed Apr 15, 2024
1 parent f3f18ba commit 3e2533d
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 148 deletions.
2 changes: 1 addition & 1 deletion api/docs/tough-cookie.cookiejar.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ string

</td><td>

The configured value for the [CookieJar](./tough-cookie.cookiejar.md)<!-- -->.
The configured [PrefixSecurityEnum](./tough-cookie.prefixsecurityenum.md) value for the [CookieJar](./tough-cookie.cookiejar.md)<!-- -->.


</td></tr>
Expand Down
2 changes: 1 addition & 1 deletion api/docs/tough-cookie.cookiejar.prefixsecurity.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## CookieJar.prefixSecurity property

The configured value for the [CookieJar](./tough-cookie.cookiejar.md)<!-- -->.
The configured [PrefixSecurityEnum](./tough-cookie.prefixsecurityenum.md) value for the [CookieJar](./tough-cookie.cookiejar.md)<!-- -->.

**Signature:**

Expand Down
2 changes: 1 addition & 1 deletion api/docs/tough-cookie.createcookiejaroptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Defaults to `false` if not specified.

</td><td>

_(Optional)_ Controls how cookie prefixes are handled. See .
_(Optional)_ Controls how cookie prefixes are handled. See [PrefixSecurityEnum](./tough-cookie.prefixsecurityenum.md)<!-- -->.

Defaults to `silent` if not specified.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## CreateCookieJarOptions.prefixSecurity property

Controls how cookie prefixes are handled. See .
Controls how cookie prefixes are handled. See [PrefixSecurityEnum](./tough-cookie.prefixsecurityenum.md)<!-- -->.

Defaults to `silent` if not specified.

Expand Down
47 changes: 19 additions & 28 deletions api/docs/tough-cookie.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,6 @@ Base class for [CookieJar](./tough-cookie.cookiejar.md) stores.
The storage model for each [CookieJar](./tough-cookie.cookiejar.md) instance can be replaced with a custom implementation. The default is [MemoryCookieStore](./tough-cookie.memorycookiestore.md)<!-- -->.


</td></tr>
</tbody></table>

## Enumerations

<table><thead><tr><th>

Enumeration


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[PrefixSecurity](./tough-cookie.prefixsecurity.md)


</td><td>

Cookie prefixes are a way to indicate that a given cookie was set with a set of attributes simply by inspecting the first few characters of the cookie's name. These are defined in [RFC6265bis - Section 4.1.3](https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-13#section-4.1.3)<!-- -->.

The following values can be used to configure how a [CookieJar](./tough-cookie.cookiejar.md) enforces attribute restrictions for Cookie prefixes.


</td></tr>
</tbody></table>

Expand Down Expand Up @@ -362,6 +334,25 @@ Description
</th></tr></thead>
<tbody><tr><td>

[PrefixSecurityEnum](./tough-cookie.prefixsecurityenum.md)


</td><td>

Cookie prefixes are a way to indicate that a given cookie was set with a set of attributes simply by inspecting the first few characters of the cookie's name. These are defined in [RFC6265bis - Section 4.1.3](https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-13#section-4.1.3)<!-- -->.

The following values can be used to configure how a [CookieJar](./tough-cookie.cookiejar.md) enforces attribute restrictions for Cookie prefixes:

- `silent` - Enable cookie prefix checking but silently ignores the cookie if conditions are not met. This is the default configuration for a [CookieJar](./tough-cookie.cookiejar.md)<!-- -->.

- `strict` - Enables cookie prefix checking and will raise an error if conditions are not met.

- `unsafe-disabled` - Disables cookie prefix checking.


</td></tr>
<tr><td>

[version](./tough-cookie.version.md)


Expand Down
83 changes: 0 additions & 83 deletions api/docs/tough-cookie.prefixsecurity.md

This file was deleted.

10 changes: 5 additions & 5 deletions api/tough-cookie.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ export function permuteDomain(domain: string, allowSpecialUseDomain?: boolean):
export function permutePath(path: string): string[];

// @public
export enum PrefixSecurity {
DISABLED = "unsafe-disabled",
SILENT = "silent",
STRICT = "strict"
}
export const PrefixSecurityEnum: Readonly<{
SILENT: "silent";
STRICT: "strict";
DISABLED: "unsafe-disabled";
}>;

// @public
export interface SerializedCookieJar {
Expand Down
8 changes: 4 additions & 4 deletions lib/__tests__/cookiePrefixes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrefixSecurity } from '../cookie/constants'
import { PrefixSecurityEnum } from '../cookie/constants'
import { CookieJar } from '../cookie/cookieJar'

let cookieJar: CookieJar
Expand All @@ -11,7 +11,7 @@ describe('When `prefixSecurity` is enabled for `CookieJar`', () => {
cookieJar = new CookieJar(null, {
prefixSecurity: 'silent',
})
expect(cookieJar.prefixSecurity).toBe(PrefixSecurity.SILENT)
expect(cookieJar.prefixSecurity).toBe(PrefixSecurityEnum.SILENT)
})

describe('__Secure prefix', () => {
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('When `prefixSecurity` is enabled for `CookieJar`', () => {
cookieJar = new CookieJar(null, {
prefixSecurity: 'strict',
})
expect(cookieJar.prefixSecurity).toBe(PrefixSecurity.STRICT)
expect(cookieJar.prefixSecurity).toBe(PrefixSecurityEnum.STRICT)
})

describe('__Secure prefix', () => {
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('When `prefixSecurity` is enabled for `CookieJar`', () => {
cookieJar = new CookieJar(null, {
prefixSecurity: 'unsafe-disabled',
})
expect(cookieJar.prefixSecurity).toBe(PrefixSecurity.DISABLED)
expect(cookieJar.prefixSecurity).toBe(PrefixSecurityEnum.DISABLED)
})

describe('__Secure prefix', () => {
Expand Down
27 changes: 12 additions & 15 deletions lib/cookie/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
* Cookie prefixes are a way to indicate that a given cookie was set with a set of attributes simply by inspecting the
* first few characters of the cookie's name. These are defined in {@link https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-13#section-4.1.3 | RFC6265bis - Section 4.1.3}.
*
* The following values can be used to configure how a {@link CookieJar} enforces attribute restrictions for Cookie prefixes.
* The following values can be used to configure how a {@link CookieJar} enforces attribute restrictions for Cookie prefixes:
*
* - `silent` - Enable cookie prefix checking but silently ignores the cookie if conditions are not met. This is the default configuration for a {@link CookieJar}.
*
* - `strict` - Enables cookie prefix checking and will raise an error if conditions are not met.
*
* - `unsafe-disabled` - Disables cookie prefix checking.
* @public
*/
export enum PrefixSecurity {
/**
* Enable cookie prefix checking but silently ignores the cookie if conditions are not met. This is the default configuration for a {@link CookieJar}.
*/
SILENT = 'silent',
/**
* Enables cookie prefix checking and will raise an error if conditions are not met.
*/
STRICT = 'strict',
/**
* Disables cookie prefix checking.
*/
DISABLED = 'unsafe-disabled',
}
export const PrefixSecurityEnum = Object.freeze({
SILENT: 'silent',
STRICT: 'strict',
DISABLED: 'unsafe-disabled',
})

const IP_V6_REGEX = `
\\[?(?:
Expand Down
17 changes: 9 additions & 8 deletions lib/cookie/cookieJar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { canonicalDomain } from './canonicalDomain'
import {
IP_V6_REGEX_OBJECT,
PrefixSecurity,
PrefixSecurityEnum,
SerializedCookieJar,
} from './constants'
import { defaultPath } from './defaultPath'
Expand Down Expand Up @@ -256,22 +256,23 @@ function isHostPrefixConditionMet(cookie: Cookie): boolean {
)
}

type PrefixSecurityValue = (typeof PrefixSecurity)[keyof typeof PrefixSecurity]
type PrefixSecurityValue =
(typeof PrefixSecurityEnum)[keyof typeof PrefixSecurityEnum]
function getNormalizedPrefixSecurity(
prefixSecurity: string,
): PrefixSecurityValue {
if (prefixSecurity != null) {
const normalizedPrefixSecurity = prefixSecurity.toLowerCase()
/* The three supported options */
switch (normalizedPrefixSecurity) {
case PrefixSecurity.STRICT:
case PrefixSecurity.SILENT:
case PrefixSecurity.DISABLED:
case PrefixSecurityEnum.STRICT:
case PrefixSecurityEnum.SILENT:
case PrefixSecurityEnum.DISABLED:
return normalizedPrefixSecurity
}
}
/* Default is SILENT */
return PrefixSecurity.SILENT
return PrefixSecurityEnum.SILENT
}

/**
Expand Down Expand Up @@ -606,9 +607,9 @@ export class CookieJar {

/* 6265bis-02 S5.4 Steps 15 & 16 */
const ignoreErrorForPrefixSecurity =
this.prefixSecurity === PrefixSecurity.SILENT
this.prefixSecurity === PrefixSecurityEnum.SILENT
const prefixSecurityDisabled =
this.prefixSecurity === PrefixSecurity.DISABLED
this.prefixSecurity === PrefixSecurityEnum.DISABLED
/* If prefix checking is not disabled ...*/
if (!prefixSecurityDisabled) {
let errorFound = false
Expand Down
2 changes: 1 addition & 1 deletion lib/cookie/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export { ParameterError } from '../validators'
export { version } from '../version'
export { Callback, ErrorCallback } from '../utils'
export { canonicalDomain } from './canonicalDomain'
export { PrefixSecurity, SerializedCookieJar } from './constants'
export { PrefixSecurityEnum, SerializedCookieJar } from './constants'
export { Cookie } from './cookie'
export { cookieCompare } from './cookieCompare'
export {
Expand Down

0 comments on commit 3e2533d

Please sign in to comment.