kopia lustrzana https://github.com/cloudflare/wildebeest
enable BE prefer-const eslint rule
rodzic
e8a5595163
commit
d44d1e6103
|
@ -12,6 +12,7 @@ module.exports = {
|
|||
plugins: ['@typescript-eslint'],
|
||||
root: true,
|
||||
rules: {
|
||||
'prefer-const': 'error',
|
||||
'no-var': 'error',
|
||||
/*
|
||||
Note: the following rules have been set to off so that linting
|
||||
|
@ -25,7 +26,6 @@ module.exports = {
|
|||
'@typescript-eslint/restrict-plus-operands': 'off',
|
||||
'no-constant-condition': 'off',
|
||||
'@typescript-eslint/await-thenable': 'off',
|
||||
'prefer-const': 'off',
|
||||
'@typescript-eslint/require-await': 'off',
|
||||
'@typescript-eslint/restrict-template-expressions': 'off',
|
||||
'@typescript-eslint/no-misused-promises': 'off',
|
||||
|
|
|
@ -64,7 +64,7 @@ const base64URLDecode = (s: string) => {
|
|||
}
|
||||
|
||||
const asciiToUint8Array = (s: string) => {
|
||||
let chars = []
|
||||
const chars = []
|
||||
for (let i = 0; i < s.length; ++i) {
|
||||
chars.push(s.charCodeAt(i))
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ const headers = {
|
|||
export async function deliverToActor(signingKey: CryptoKey, from: Actor, to: Actor, activity: Activity) {
|
||||
const body = JSON.stringify(activity)
|
||||
console.log({ body })
|
||||
let req = new Request(to.inbox, {
|
||||
const req = new Request(to.inbox, {
|
||||
method: 'POST',
|
||||
body,
|
||||
headers,
|
||||
|
|
|
@ -20,7 +20,7 @@ export async function signRequest(request: Request, key: CryptoKey, keyId: URL):
|
|||
request.headers.set('Host', url.host)
|
||||
}
|
||||
|
||||
let components = ['@request-target', 'host']
|
||||
const components = ['@request-target', 'host']
|
||||
if (request.method == 'POST') {
|
||||
components.push('digest')
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ import { HEADER, HttpSignatureError, InvalidAlgorithmError, validateAlgorithm }
|
|||
|
||||
///--- Globals
|
||||
|
||||
let State = {
|
||||
const State = {
|
||||
New: 0,
|
||||
Params: 1,
|
||||
}
|
||||
|
||||
let ParamsState = {
|
||||
const ParamsState = {
|
||||
Name: 0,
|
||||
Quote: 1,
|
||||
Value: 2,
|
||||
|
@ -125,10 +125,10 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
|
|||
headers = options.headers
|
||||
}
|
||||
|
||||
let authz = request.headers.get(HEADER.AUTH) || request.headers.get(HEADER.SIG)
|
||||
const authz = request.headers.get(HEADER.AUTH) || request.headers.get(HEADER.SIG)
|
||||
|
||||
if (!authz) {
|
||||
let errHeader = HEADER.AUTH + ' or ' + HEADER.SIG
|
||||
const errHeader = HEADER.AUTH + ' or ' + HEADER.SIG
|
||||
|
||||
throw new MissingHeaderError('no ' + errHeader + ' header ' + 'present in the request')
|
||||
}
|
||||
|
@ -141,14 +141,14 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
|
|||
let tmpName = ''
|
||||
let tmpValue = ''
|
||||
|
||||
let parsed = {
|
||||
const parsed = {
|
||||
scheme: authz === request.headers.get(HEADER.SIG) ? 'Signature' : '',
|
||||
params: {},
|
||||
signingString: '',
|
||||
}
|
||||
|
||||
for (i = 0; i < authz.length; i++) {
|
||||
let c = authz.charAt(i)
|
||||
const c = authz.charAt(i)
|
||||
let code = c.charCodeAt(0)
|
||||
|
||||
switch (Number(state)) {
|
||||
|
@ -268,7 +268,7 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
|
|||
|
||||
// Build the signingString
|
||||
for (i = 0; i < parsed.params.headers.length; i++) {
|
||||
let h = parsed.params.headers[i].toLowerCase()
|
||||
const h = parsed.params.headers[i].toLowerCase()
|
||||
parsed.params.headers[i] = h
|
||||
|
||||
if (h === 'request-line') {
|
||||
|
@ -290,7 +290,7 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
|
|||
} else if (h === '(algorithm)') {
|
||||
parsed.signingString += '(algorithm): ' + parsed.params.algorithm
|
||||
} else if (h === '(opaque)') {
|
||||
let opaque = parsed.params.opaque
|
||||
const opaque = parsed.params.opaque
|
||||
if (opaque === undefined) {
|
||||
throw new MissingHeaderError('opaque param was not in the ' + authzHeaderName + ' header')
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
|
|||
} else if (h === '(expires)') {
|
||||
parsed.signingString += '(expires): ' + parsed.params.expires
|
||||
} else {
|
||||
let value = request.headers.get(h)
|
||||
const value = request.headers.get(h)
|
||||
if (value === null) throw new MissingHeaderError(h + ' was not in the request')
|
||||
parsed.signingString += h + ': ' + value
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
|
|||
} else {
|
||||
date = new Date(request.headers.date)
|
||||
}
|
||||
let now = new Date()
|
||||
const now = new Date()
|
||||
skew = Math.abs(now.getTime() - date.getTime())
|
||||
|
||||
if (skew > options.clockSkew * 1000) {
|
||||
|
@ -341,7 +341,7 @@ export function parseRequest(request: Request, options?: Options): ParsedSignatu
|
|||
}
|
||||
|
||||
if (parsed.params.expires) {
|
||||
let expiredSince = Math.floor(Date.now() / 1000) - parsed.params.expires
|
||||
const expiredSince = Math.floor(Date.now() / 1000) - parsed.params.expires
|
||||
if (expiredSince > options.clockSkew) {
|
||||
throw new ExpiredRequestError(
|
||||
'Request expired with skew ' + expiredSince + 's greater than allowed ' + options.clockSkew + 's'
|
||||
|
|
|
@ -31,7 +31,7 @@ export class InvalidAlgorithmError extends HttpSignatureError {
|
|||
* @returns {[string, string]}
|
||||
*/
|
||||
export function validateAlgorithm(algorithm: string, publicKeyType?: string): [string, string] {
|
||||
var alg = algorithm.toLowerCase().split('-')
|
||||
const alg = algorithm.toLowerCase().split('-')
|
||||
|
||||
if (alg[0] === 'hs2019') {
|
||||
return publicKeyType !== undefined ? validateAlgorithm(publicKeyType + '-sha256') : ['hs2019', 'sha256']
|
||||
|
|
|
@ -66,9 +66,7 @@ describe('utils', () => {
|
|||
})
|
||||
|
||||
test('URL to handle', async () => {
|
||||
let res
|
||||
|
||||
res = urlToHandle(new URL('https://host.org/users/foobar'))
|
||||
const res = urlToHandle(new URL('https://host.org/users/foobar'))
|
||||
assert.equal(res, 'foobar@host.org')
|
||||
})
|
||||
})
|
||||
|
|
Ładowanie…
Reference in New Issue