Skip to content

Commit

Permalink
wpt: add scheme-others.sub.any.js and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and ronag committed Oct 17, 2022
1 parent 77a17f4 commit 2533d76
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
4 changes: 3 additions & 1 deletion lib/fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ class Response {
throw new TypeError('Illegal invocation')
}

const urlList = this[kState].urlList

// The url getter steps are to return the empty string if this’s
// response’s URL is null; otherwise this’s response’s URL,
// serialized with exclude fragment set to true.
const url = this[kState].urlList[0] ?? null
const url = urlList[urlList.length - 1] ?? null

if (url === null) {
return ''
Expand Down
1 change: 0 additions & 1 deletion lib/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ function bytesMatch (bytes, metadataList) {
const expectedValue = item.hash

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

// 4. If actualValue is a case-sensitive match for expectedValue,
Expand Down
7 changes: 1 addition & 6 deletions test/fetch/about-uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ const { fetch } = require('../..')

test('fetching about: uris', async (t) => {
t.test('about:blank', async (t) => {
const res = await fetch('about:blank')

t.equal(res.url, 'about:blank')
t.equal(res.statusText, 'OK')
t.equal(res.headers.get('Content-Type'), 'text/html;charset=utf-8')
t.end()
await t.rejects(fetch('about:blank'))
})

t.test('All other about: urls should return an error', async (t) => {
Expand Down
4 changes: 2 additions & 2 deletions test/fetch/integrity.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ setGlobalDispatcher(new Agent({

test('request with correct integrity checksum', (t) => {
const body = 'Hello world!'
const hash = createHash('sha256').update(body).digest('hex')
const hash = createHash('sha256').update(body).digest('base64')

const server = createServer((req, res) => {
res.end(body)
Expand Down Expand Up @@ -58,7 +58,7 @@ test('request with wrong integrity checksum', (t) => {

test('request with integrity checksum on encoded body', (t) => {
const body = 'Hello world!'
const hash = createHash('sha256').update(body).digest('hex')
const hash = createHash('sha256').update(body).digest('base64')

const server = createServer((req, res) => {
res.setHeader('content-encoding', 'gzip')
Expand Down
8 changes: 4 additions & 4 deletions test/node-fetch/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1532,12 +1532,12 @@ describe('node-fetch', () => {
})
})

it('should keep `?` sign in URL when no params are given', () => {
it('should NOT keep `?` sign in URL when no params are given', () => {
const url = `${base}question?`
const urlObject = new URL(url)
const request = new Request(urlObject)
return fetch(request).then(res => {
expect(res.url).to.equal(url)
expect(res.url).to.equal(url.slice(0, -1))
expect(res.ok).to.be.true
expect(res.status).to.equal(200)
})
Expand All @@ -1554,12 +1554,12 @@ describe('node-fetch', () => {
})
})

it('should preserve the hash (#) symbol', () => {
it('should NOT preserve the hash (#) symbol', () => {
const url = `${base}question?#`
const urlObject = new URL(url)
const request = new Request(urlObject)
return fetch(request).then(res => {
expect(res.url).to.equal(url)
expect(res.url).to.equal(url.slice(0, -2))
expect(res.ok).to.be.true
expect(res.status).to.equal(200)
})
Expand Down
2 changes: 1 addition & 1 deletion test/node-fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('Response', () => {
status: 346,
statusText: 'production'
})
res[kState].urlList = [base]
res[kState].urlList = [new URL(base)]
const cl = res.clone()
expect(cl.headers.get('a')).to.equal('1')
expect(cl.type).to.equal('default')
Expand Down
31 changes: 31 additions & 0 deletions test/wpt/tests/fetch/api/basic/scheme-others.sub.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// META: global=window,worker
// META: script=../resources/utils.js

function checkKoUrl(url, desc) {
if (!desc)
desc = "Fetching " + url.substring(0, 45) + " is KO"
promise_test(function(test) {
var promise = fetch(url);
return promise_rejects_js(test, TypeError, promise);
}, desc);
}

var urlWithoutScheme = "://{{host}}:{{ports[http][0]}}/";
checkKoUrl("aaa" + urlWithoutScheme);
checkKoUrl("cap" + urlWithoutScheme);
checkKoUrl("cid" + urlWithoutScheme);
checkKoUrl("dav" + urlWithoutScheme);
checkKoUrl("dict" + urlWithoutScheme);
checkKoUrl("dns" + urlWithoutScheme);
checkKoUrl("geo" + urlWithoutScheme);
checkKoUrl("im" + urlWithoutScheme);
checkKoUrl("imap" + urlWithoutScheme);
checkKoUrl("ipp" + urlWithoutScheme);
checkKoUrl("ldap" + urlWithoutScheme);
checkKoUrl("mailto" + urlWithoutScheme);
checkKoUrl("nfs" + urlWithoutScheme);
checkKoUrl("pop" + urlWithoutScheme);
checkKoUrl("rtsp" + urlWithoutScheme);
checkKoUrl("snmp" + urlWithoutScheme);

done();

0 comments on commit 2533d76

Please sign in to comment.