mirror of
https://github.com/hanzoai/node-jwks-rsa.git
synced 2026-09-24 17:00:54 +00:00
fix: Migrate to WHATWG URL API from node's core url (#465)
This commit is contained in:
@@ -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
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user