fix: Migrate to WHATWG URL API from node's core url (#465)

This commit is contained in:
Chetan Sharma
2026-01-15 16:44:57 +05:30
committed by GitHub
2 changed files with 20 additions and 8 deletions
+9 -7
View File
@@ -1,6 +1,6 @@
const http = require('http');
const https = require('https');
const urlUtil = require('url');
const ArgumentError = require('../errors/ArgumentError');
module.exports.default = (options) => {
if (options.fetcher) {
@@ -8,12 +8,14 @@ module.exports.default = (options) => {
}
return new Promise((resolve, reject) => {
const {
hostname,
path,
port,
protocol
} = urlUtil.parse(options.uri);
let url;
try {
url = new URL(options.uri);
} catch (err) {
throw new ArgumentError('Invalid JWKS URI: The provided URI is not a valid URL.');
}
const { hostname, port, protocol, pathname, search } = url;
const path = pathname + search;
const requestOptions = {
hostname,
+11 -1
View File
@@ -48,7 +48,7 @@ describe('Request wrapper tests', () => {
.reply(500, function () { this.req.response.statusMessage = errorMsg; });
request({ uri })
.then(() => done('Shoul dhave thrown error'))
.then(() => done('Should have thrown error'))
.catch((err) => {
expect(err.errorMsg).to.eql(errorMsg);
done();
@@ -131,4 +131,14 @@ describe('Request wrapper tests', () => {
.catch(done);
});
});
it('should reject with the ArgumentError message for malformed URI', (done) => {
const badUrl = 'not-a-valid-url';
request({ uri: badUrl })
.then(() => done('Should have thrown error'))
.catch((err) => {
expect(err.message).to.equal('Invalid JWKS URI: The provided URI is not a valid URL.');
done();
});
});
});