Skip to content

Commit

Permalink
Update wpts (nodejs#2226)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and crysmags committed Feb 27, 2024
1 parent 773cebb commit 57fe9da
Show file tree
Hide file tree
Showing 185 changed files with 3,480 additions and 663 deletions.
2 changes: 1 addition & 1 deletion lib/fetch/response.js
Expand Up @@ -49,7 +49,7 @@ class Response {
}

// https://fetch.spec.whatwg.org/#dom-response-json
static json (data = undefined, init = {}) {
static json (data, init = {}) {
webidl.argumentLengthCheck(arguments, 1, { header: 'Response.json' })

if (init !== null) {
Expand Down
25 changes: 23 additions & 2 deletions lib/fetch/util.js
Expand Up @@ -556,16 +556,37 @@ function bytesMatch (bytes, metadataList) {
const algorithm = item.algo

// 2. Let expectedValue be the val component of item.
const expectedValue = item.hash
let expectedValue = item.hash

// See https://github.com/web-platform-tests/wpt/commit/e4c5cc7a5e48093220528dfdd1c4012dc3837a0e
// "be liberal with padding". This is annoying, and it's not even in the spec.

if (expectedValue.endsWith('==')) {
expectedValue = expectedValue.slice(0, -2)
}

// 3. Let actualValue be the result of applying algorithm to bytes.
const actualValue = crypto.createHash(algorithm).update(bytes).digest('base64')
let actualValue = crypto.createHash(algorithm).update(bytes).digest('base64')

if (actualValue.endsWith('==')) {
actualValue = actualValue.slice(0, -2)
}

// 4. If actualValue is a case-sensitive match for expectedValue,
// return true.
if (actualValue === expectedValue) {
return true
}

let actualBase64URL = crypto.createHash(algorithm).update(bytes).digest('base64url')

if (actualBase64URL.endsWith('==')) {
actualBase64URL = actualBase64URL.slice(0, -2)
}

if (actualBase64URL === expectedValue) {
return true
}
}

// 6. Return false.
Expand Down
2 changes: 2 additions & 0 deletions test/wpt/runner/runner.mjs
Expand Up @@ -312,6 +312,8 @@ export class WPTRunner extends EventEmitter {
`unexpected failures: ${failed - expectedFailures}, ` +
`skipped: ${skipped}`
)

process.exit(0)
}

addInitScript (code) {
Expand Down
8 changes: 7 additions & 1 deletion test/wpt/status/fetch.status.json
Expand Up @@ -2,11 +2,13 @@
"api": {
"abort": {
"general.any.js": {
"note": "TODO(@KhafraDev): Clone aborts with original controller can probably be fixed",
"fail": [
"Already aborted signal rejects immediately",
"Underlying connection is closed when aborting after receiving response - no-cors",
"Stream errors once aborted. Underlying connection closed.",
"Readable stream synchronously cancels with AbortError if aborted before reading"
"Readable stream synchronously cancels with AbortError if aborted before reading",
"Clone aborts with original controller"
]
},
"cache.https.any.js": {
Expand Down Expand Up @@ -128,6 +130,10 @@
]
}
},
"fetch-later": {
"note": "this is not part of the spec, only a proposal",
"skip": true
},
"headers": {
"header-setcookie.any.js": {
"note": "undici doesn't filter headers",
Expand Down

0 comments on commit 57fe9da

Please sign in to comment.