-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
24 lines (22 loc) · 850 Bytes
/
index.ts
File metadata and controls
24 lines (22 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import * as mod from 'libxml-xsd';
import * as path from 'path';
const xsd = 'saml-schema-protocol-2.0.xsd';
export const validate = (xml: string) => {
return new Promise((resolve, reject) => {
// https://github.com/albanm/node-libxml-xsd/issues/11
process.chdir(path.resolve(__dirname, '../schemas'));
mod.parseFile(path.resolve(xsd), (err, schema) => {
if (err) {
console.error('[ERROR] validateXML', err);
return reject('ERR_INVALID_XML');
}
schema.validate(xml, (techErrors, validationErrors) => {
if (techErrors !== null || validationErrors !== null) {
console.error(`this is not a valid saml response with errors: ${validationErrors}`);
return reject('ERR_EXCEPTION_VALIDATE_XML');
}
return resolve('SUCCESS_VALIDATE_XML');
});
});
});
};