-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
27 lines (22 loc) · 1.07 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import * as mod from 'node-xmllint';
import xsd from './schemas/saml-schema-protocol-2.0.xsd';
import assertion from './schemas/saml-schema-assertion-2.0.xsd';
import sig from './schemas/xmldsig-core-schema.xsd';
import xenc from './schemas/xenc-schema.xsd';
// file fix for virtual filesystem of emscripten
const schemaProto = xsd.replace('saml-schema-assertion-2.0.xsd', 'file_0.xsd').replace('xmldsig-core-schema.xsd', 'file_1.xsd');
const schemaAssert = assertion.replace('xmldsig-core-schema.xsd', 'file_1.xsd').replace('xenc-schema.xsd', 'file_2.xsd');
const schemaXenc = xenc.replace('xmldsig-core-schema.xsd', 'file_1.xsd');
export const validate = (xml: string) => {
return new Promise((resolve, reject) => {
const validationResult = mod.validateXML({
xml: xml,
schema: [schemaAssert, sig, schemaXenc, schemaProto]
});
if (!validationResult.errors) {
return resolve('SUCCESS_VALIDATE_XML');
}
console.error(`this is not a valid saml response with errors: ${validationResult.errors}`);
return reject('ERR_EXCEPTION_VALIDATE_XML');
});
};