Skip to content

Commit

Permalink
Upgrade devdependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tngan committed Feb 22, 2019
1 parent f59bd2a commit cf07ca7
Show file tree
Hide file tree
Showing 7 changed files with 1,147 additions and 1,192 deletions.
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -50,10 +50,10 @@
"@types/node-forge": "^0.7.4",
"@types/uuid": "3.0.0",
"@types/xmldom": "^0.1.28",
"ava": "^0.19.1",
"ava": "^1.2.1",
"coveralls": "^3.0.2",
"nyc": "^11.9.0",
"tslint": "5.4.2",
"typescript": "^2.9.2"
"tslint": "^5.12.1",
"typescript": "^3.3.3333"
}
}
8 changes: 4 additions & 4 deletions src/schema-validator.ts
Expand Up @@ -55,7 +55,7 @@ const getValidatorModule: GetValidatorModuleSpec = async () => {
return v;
};

const validator = await import(SchemaValidators.JAVAC);
const validator = await import (SchemaValidators.JAVAC);
const mod = setSchemaDir(new validator());

return {
Expand All @@ -77,7 +77,7 @@ const getValidatorModule: GetValidatorModuleSpec = async () => {
}

if (selectedValidator === SchemaValidators.LIBXML) {
const mod = await import(SchemaValidators.LIBXML);
const mod = await import (SchemaValidators.LIBXML);
return {
validate: (xml: string) => {
return new Promise((resolve, reject) => {
Expand All @@ -103,13 +103,13 @@ const getValidatorModule: GetValidatorModuleSpec = async () => {

if (selectedValidator === SchemaValidators.XMLLINT) {

const mod = await import(SchemaValidators.XMLLINT);
const mod = await import (SchemaValidators.XMLLINT);

const schemaPath = (schema: string) => path.resolve(__dirname, `../schemas/${schema}`);

let schemaProto = fs.readFileSync(schemaPath(xsd), 'utf-8');
let schemaAssert = fs.readFileSync(schemaPath('saml-schema-assertion-2.0.xsd'), 'utf-8');
let schemaXmldsig = fs.readFileSync(schemaPath('xmldsig-core-schema.xsd'), 'utf-8');
const schemaXmldsig = fs.readFileSync(schemaPath('xmldsig-core-schema.xsd'), 'utf-8');
let schemaXenc = fs.readFileSync(schemaPath('xenc-schema.xsd'), 'utf-8');

// file fix for virtual filesystem of emscripten
Expand Down
12 changes: 8 additions & 4 deletions src/validator.ts
Expand Up @@ -4,17 +4,21 @@ function verifyTime(utcNotBefore?: string, utcNotOnOrAfter?: string): boolean {
if (!utcNotBefore && !utcNotOnOrAfter) {
return true; // throw exception todo
}

let notBeforeLocal = null;
let notOnOrAfterLocal = null;

if (utcNotBefore && !utcNotOnOrAfter) {
const notBeforeLocal = new Date(utcNotBefore);
notBeforeLocal = new Date(utcNotBefore);
return +notBeforeLocal <= +now;
}
if (!utcNotBefore && utcNotOnOrAfter) {
const notOnOrAfterLocal = new Date(utcNotOnOrAfter);
notOnOrAfterLocal = new Date(utcNotOnOrAfter);
return now < notOnOrAfterLocal;
}

const notBeforeLocal = new Date(utcNotBefore);
const notOnOrAfterLocal = new Date(utcNotOnOrAfter);
notBeforeLocal = new Date(utcNotBefore);
notOnOrAfterLocal = new Date(utcNotOnOrAfter);
return +notBeforeLocal <= +now && now < notOnOrAfterLocal;
}

Expand Down
18 changes: 9 additions & 9 deletions test/flow.ts
Expand Up @@ -25,17 +25,17 @@ const loginResponseTemplate = {
],
};

const createTemplateCallback = (idp, sp, user) => template => {
const createTemplateCallback = (_idp, _sp, user) => template => {
const _id = '_8e8dc5f69a98cc4c1ff3427e5ce34606fd672f91e6';
const now = new Date();
const spEntityID = sp.entityMeta.getEntityID();
const idpSetting = idp.entitySetting;
const spEntityID = _sp.entityMeta.getEntityID();
const idpSetting = _idp.entitySetting;
const fiveMinutesLater = new Date(now.getTime());
fiveMinutesLater.setMinutes(fiveMinutesLater.getMinutes() + 5);
const tvalue = {
ID: _id,
AssertionID: idpSetting.generateID ? idpSetting.generateID() : `${uuid.v4()}`,
Destination: sp.entityMeta.getAssertionConsumerService(binding.post),
Destination: _sp.entityMeta.getAssertionConsumerService(binding.post),
Audience: spEntityID,
SubjectRecipient: spEntityID,
NameIDFormat: 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
Expand All @@ -45,7 +45,7 @@ const createTemplateCallback = (idp, sp, user) => template => {
ConditionsNotBefore: now.toISOString(),
ConditionsNotOnOrAfter: fiveMinutesLater.toISOString(),
SubjectConfirmationDataNotOnOrAfter: fiveMinutesLater.toISOString(),
AssertionConsumerServiceURL: sp.entityMeta.getAssertionConsumerService(binding.post),
AssertionConsumerServiceURL: _sp.entityMeta.getAssertionConsumerService(binding.post),
EntityID: spEntityID,
InResponseTo: '_4606cc1f427fa981e6ffd653ee8d6972fc5ce398c4',
StatusCode: 'urn:oasis:names:tc:SAML:2.0:status:Success',
Expand Down Expand Up @@ -193,7 +193,7 @@ test('create login request with post binding using [custom template]', t => {

test('create login response with undefined binding', async t => {
const user = { email: 'user@esaml2.com' };
const error = await t.throws(idp.createLoginResponse(sp, {}, 'undefined', user, createTemplateCallback(idp, sp, user)));
const error = await t.throwsAsync(() => idp.createLoginResponse(sp, {}, 'undefined', user, createTemplateCallback(idp, sp, user)));
t.is(error.message, 'ERR_CREATE_RESPONSE_UNDEFINED_BINDING');
});

Expand Down Expand Up @@ -565,10 +565,10 @@ test('avoid mitm attack', async t => {
const { context: SAMLResponse } = await idpNoEncrypt.createLoginResponse(sp, sampleRequestInfo, 'post', user, createTemplateCallback(idpNoEncrypt, sp, user));
const rawResponse = String(utility.base64Decode(SAMLResponse, true));
const attackResponse = `<NameID>evil@evil.com${rawResponse}</NameID>`;
const error = await t.throws(sp.parseLoginResponse(idpNoEncrypt, 'post', { body: { SAMLResponse: utility.base64Encode(attackResponse) } }));
const error = await t.throwsAsync(() => sp.parseLoginResponse(idpNoEncrypt, 'post', { body: { SAMLResponse: utility.base64Encode(attackResponse) } }));
});

test('should reject signature wrapped response', async t => {
test('should reject signature wrapped response - case 1', async t => {
//
const user = { email: 'user@esaml2.com' };
const { id, context: SAMLResponse } = await idpNoEncrypt.createLoginResponse(sp, sampleRequestInfo, 'post', user, createTemplateCallback(idpNoEncrypt, sp, user));
Expand All @@ -592,7 +592,7 @@ test('should reject signature wrapped response', async t => {
}
});

test('should reject signature wrapped response', async t => {
test('should reject signature wrapped response - case 2', async t => {
//
const user = { email: 'user@esaml2.com' };
const { id, context: SAMLResponse } = await idpNoEncrypt.createLoginResponse(sp, sampleRequestInfo, 'post', user, createTemplateCallback(idpNoEncrypt, sp, user));
Expand Down
10 changes: 5 additions & 5 deletions test/index.ts
Expand Up @@ -264,22 +264,22 @@ test('getAssertionConsumerService with two bindings', t => {
t.is(libsaml.verifySignature(xml, { keyFile: './test/key/sp/cert.cer' })[0], true);
});
test('encrypt assertion test passes', async t => {
await t.notThrows(libsaml.encryptAssertion(idp, sp, sampleSignedResponse));
await t.notThrowsAsync(() => libsaml.encryptAssertion(idp, sp, sampleSignedResponse));
});
test('encrypt assertion response without assertion returns error', async t => {
const error = await t.throws(libsaml.encryptAssertion(idp, sp, wrongResponse));
const error = await t.throwsAsync(() => libsaml.encryptAssertion(idp, sp, wrongResponse));
t.is(error.message, 'ERR_MULTIPLE_ASSERTION');
});
test('encrypt assertion with invalid xml syntax returns error', async t => {
const error = await t.throws(libsaml.encryptAssertion(idp, sp, 'This is not a xml format string'));
const error = await t.throwsAsync(() => libsaml.encryptAssertion(idp, sp, 'This is not a xml format string'));
t.is(error.message, 'ERR_MULTIPLE_ASSERTION');
});
test('encrypt assertion with empty string returns error', async t => {
const error = await t.throws(libsaml.encryptAssertion(idp, sp, ''));
const error = await t.throwsAsync(() => libsaml.encryptAssertion(idp, sp, ''));
t.is(error.message, 'ERR_UNDEFINED_ASSERTION');
});
test('encrypt assertion with undefined string returns error', async t => {
const error = await t.throws(libsaml.encryptAssertion(idp, sp, undefined));
const error = await t.throwsAsync(() => libsaml.encryptAssertion(idp, sp, undefined));
t.is(error.message, 'ERR_UNDEFINED_ASSERTION');
});
test('building attribute statement with one attribute', t => {
Expand Down
5 changes: 5 additions & 0 deletions tslint.json
@@ -1,6 +1,11 @@
{
"extends": "tslint:recommended",
"rulesDirectory": [],
"linterOptions": {
"exclude": [
"node_modules/**"
]
},
"rules": {
"arrow-parens": [true, "ban-single-arg-parens"],
"comment-format": false,
Expand Down

0 comments on commit cf07ca7

Please sign in to comment.