Skip to content

Commit

Permalink
Catch errors when overrideImportLocation fails (#1257)
Browse files Browse the repository at this point in the history
  • Loading branch information
simakvladimir authored Sep 29, 2024
1 parent 9c3822b commit 96455b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1209,15 +1209,19 @@ export class WSDL {
includePath = url.resolve(this.uri || '', include.location);
}

if (this.options.wsdl_options !== undefined && typeof this.options.wsdl_options.overrideImportLocation === 'function') {
includePath = this.options.wsdl_options.overrideImportLocation(includePath);
}

const options = Object.assign({}, this.options);
// follow supplied ignoredNamespaces option
options.ignoredNamespaces = this._originalIgnoredNamespaces || this.options.ignoredNamespaces;
options.WSDL_CACHE = this.WSDL_CACHE;

if (this.options.wsdl_options !== undefined && typeof this.options.wsdl_options.overrideImportLocation === 'function') {
try {
includePath = this.options.wsdl_options.overrideImportLocation(includePath, this.uri, include.location, options);
} catch (e) {
return callback(e);
}
}

open_wsdl_recursive(includePath, options, (err, wsdl) => {
if (err) {
return callback(err);
Expand Down
22 changes: 22 additions & 0 deletions test/wsdl-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ describe('WSDL Parser (strict)', () => {
});
});

it('should catch error on overrideImportLocation option', (done) => {
const options = {
strict: true,
wsdl_options: {
overrideImportLocation: (location, parent, include, options) => {
assert.equal(location, __dirname+'/wsdl/wsdlImport/sub.wsdl');
assert.equal(parent, __dirname+'/wsdl/wsdlImport/main.wsdl');
assert.equal(include, 'sub.wsdl')
assert.notEqual(options, null);
throw new Error(`user error`);
}
},
disableCache: true,
};

soap.createClient(__dirname+'/wsdl/wsdlImport/main.wsdl', options, function(err, client){
assert.notEqual(err, null);
assert.equal(err.message, 'user error');
done();
});
});

it('should get the parent namespace when parent namespace is empty string', (done) => {
soap.createClient(__dirname+'/wsdl/marketo.wsdl', {strict: true}, function(err, client){
assert.ifError(err);
Expand Down

0 comments on commit 96455b7

Please sign in to comment.