Skip to content

Commit fd72e11

Browse files
author
Olha Virolainen
authored
Annual npm vulnerabilities audit (#21)
Annual npm vulnerabilities audit
1 parent ea7142b commit fd72e11

11 files changed

+144
-66
lines changed

.circleci/config.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: 2
2+
jobs:
3+
test:
4+
docker:
5+
- image: circleci/node:14-stretch
6+
steps:
7+
- checkout
8+
- restore_cache:
9+
key: dependency-cache-{{ checksum "package.json" }}
10+
- run:
11+
name: Audit Dependencies
12+
command: npm audit --audit-level=high
13+
- run:
14+
name: Installing Dependencies
15+
command: npm install
16+
- save_cache:
17+
key: dependency-cache-{{ checksum "package.json" }}
18+
paths:
19+
- node_modules
20+
- run:
21+
name: Running Unit Tests
22+
command: npm test
23+
- run:
24+
name: Running Integration Tests
25+
command: npm run integration-test
26+
27+
workflows:
28+
version: 2
29+
build_and_test:
30+
jobs:
31+
- test

.travis.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.1.3 (November 20, 2020)
2+
3+
* Update Sailor version to 2.6.18
4+
* Annual audit of the component code to check if it exposes a sensitive data in the logs
5+
* Annual npm vulnerabilities audit
6+
17
## 1.1.2 (July 24, 2020)
28

39
* Update sailor version to 2.6.14

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# mssql-component [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
1+
[![CircleCI](https://circleci.com/gh/elasticio/mssql-component.svg?style=svg)](https://circleci.com/gh/elasticio/mssql-component)
2+
# mssql-component
23
> elastic.io integration component for Microsoft SQL Server
34
45
# mssql-component

lib/actions/insert.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ function init(cfg) {
2626
cfg.database
2727
}${(cfg.domain) ? `?domain=${cfg.domain}&encrypt=${cfg.encrypt}`
2828
: `?encrypt=${cfg.encrypt}`}`;
29-
logger.trace(conString);
29+
logger.debug('Connection string is created');
3030
return co(function* gen() {
3131
logger.info('Connecting to the database');
3232
const connection = new cosql.Connection(conString);
3333
// Always attach an error listener
34-
connection.on('error', (err) => this.emit('error', err));
34+
connection.on('error', err => this.emit('error', err));
3535
let sql = cfg.query;
3636
yield connection.connect();
3737
logger.info('Connection established');
38-
logger.trace('Preparing query=%s', sql);
38+
logger.debug('Preparing query...');
3939
const vars = sql.match(VARS_REGEXP);
40-
logger.trace('Found following prepared variable:type pairs=%j', vars);
40+
logger.debug('Found prepared variable:type pairs');
4141
pstmt = new cosql.PreparedStatement(connection);
4242
for (const tuple of vars) {
4343
const [placeholder, type] = tuple.split(':');
@@ -74,7 +74,7 @@ function init(cfg) {
7474
// Now let's remove all :string :boolean :date etc to the name only
7575
sql = sql.replace(tuple, placeholder);
7676
}
77-
logger.trace('Resulting SQL=%s', sql);
77+
logger.trace('Resulting SQL is ready');
7878
yield pstmt.prepare(sql);
7979
logger.info('Preparing statement created');
8080
}.bind(this));

lib/actions/select.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function init(cfg) {
2828
return co(function* gen() {
2929
logger.info('Connecting to the database');
3030
connection = new cosql.Connection(conString);
31-
connection.on('error', (err) => this.emit('error', err));
31+
connection.on('error', err => this.emit('error', err));
3232
yield connection.connect();
3333
logger.info('Connection established');
3434
}.bind(this));
@@ -47,15 +47,14 @@ function processAction(msg, cfg, snapshot = {}) {
4747
const lastPoll = snapshot.lastPoll || new Date(0).toISOString();
4848
this.logger.info('Last polling timestamp=%s', lastPoll);
4949
const sql = originalSql.split(LAST_POLL_PLACEHOLDER).join(lastPoll);
50-
this.logger.trace('Original query=%s', originalSql);
51-
this.logger.trace('Transformed query=%s', sql);
50+
this.logger.debug('Transformed query is ready');
5251
const that = this;
5352
return co(function* gen() {
5453
const request = new cosql.Request(connection);
5554
request.stream = true;
5655

57-
request.on('recordset', (recordset) => {
58-
that.logger.trace('Have got recordset metadata=%j', recordset);
56+
request.on('recordset', () => {
57+
that.logger.trace('Have got recordset metadata');
5958
});
6059

6160
request.on('row', (row) => {

package-lock.json

Lines changed: 30 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mssql-component",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "elastic.io integration component for Microsoft SQL Server",
55
"homepage": "https://www.elastic.io",
66
"author": {
@@ -25,16 +25,16 @@
2525
"node": ">=12.13.0"
2626
},
2727
"scripts": {
28-
"pretest": "node_modules/.bin/eslint lib spec spec-integration --ext .json --ext .js --fix",
28+
"pretest": "eslint lib spec spec-integration --ext .json --ext .js --fix",
2929
"test": "NODE_ENV=test mocha spec/*",
30-
"integration-test": "NODE_ENV=test mocha spec-integration/* --exit"
30+
"integration-test": "mocha spec-integration --recursive --timeout 10000 --exit"
3131
},
3232
"dependencies": {
3333
"bluebird": "3.4.6",
3434
"co": "4.6.0",
3535
"co-mssql": "1.3.0",
3636
"elasticio-node": "0.0.9",
37-
"elasticio-sailor-nodejs": "2.6.14",
37+
"elasticio-sailor-nodejs": "2.6.18",
3838
"@elastic.io/component-logger": "0.0.1",
3939
"mssql": "4.1.0",
4040
"request": "2.87.0",

spec-integration/integration.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('Integration test', () => {
9292
select.process.call({
9393
emit: emitter,
9494
logger,
95-
}, msg, cfg).catch((err) => done(err));
95+
}, msg, cfg).catch(err => done(err));
9696
});
9797
});
9898

@@ -124,7 +124,7 @@ describe('Integration test', () => {
124124
select.process.call({
125125
emit: emitter,
126126
logger,
127-
}, msg, cfg).catch((err) => done(err));
127+
}, msg, cfg).catch(err => done(err));
128128
});
129129
});
130130

@@ -158,7 +158,7 @@ describe('Integration test', () => {
158158
select.process.call({
159159
emit: emitter,
160160
logger,
161-
}, msg, cfg, {}).catch((err) => done(err));
161+
}, msg, cfg, {}).catch(err => done(err));
162162
});
163163
});
164164
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const fs = require('fs');
2+
const { expect } = require('chai');
3+
const logger = require('@elastic.io/component-logger')();
4+
const verifyCredentials = require('../verifyCredentials');
5+
6+
describe('Integration test verify credentials', () => {
7+
if (fs.existsSync('.env')) {
8+
// eslint-disable-next-line global-require
9+
require('dotenv').config();
10+
}
11+
before(() => {
12+
if (!process.env.MSSQL_USERNAME) { throw new Error('Please set MSSQL_USERNAME env variable to proceed'); }
13+
if (!process.env.MSSQL_PASSWORD) { throw new Error('Please set MSSQL_PASSWORD env variable to proceed'); }
14+
if (!process.env.MSSQL_SERVER) { throw new Error('Please set MSSQL_SERVER env variable to proceed'); }
15+
if (!process.env.MSSQL_DATABASE) { throw new Error('Please set MSSQL_DATABASE env variable to proceed'); }
16+
});
17+
const cfg = {
18+
username: process.env.MSSQL_USERNAME,
19+
password: process.env.MSSQL_PASSWORD,
20+
server: process.env.MSSQL_SERVER,
21+
port: process.env.MSSQL_PORT,
22+
instance: process.env.MSSQL_INSTANCE,
23+
database: process.env.MSSQL_DATABASE,
24+
domain: process.env.MSSQL_DOMAIN,
25+
encrypt: process.env.MSSQL_ENCRYPT,
26+
};
27+
28+
it('should successfully verify credentials', (done) => {
29+
verifyCredentials.call({ logger }, cfg, (err, result) => {
30+
if (err) {
31+
done(err);
32+
}
33+
expect(result).deep.equal({ verified: true });
34+
done();
35+
});
36+
});
37+
});

verifyCredentials.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
'use strict';
21
const co = require('co');
32
const sql = require('co-mssql');
43

54
// This function will be called by the platform to verify credentials
65
module.exports = function verifyCredentials(credentials, cb) {
7-
console.log('Credentials passed for verification %j', credentials);
8-
co(function*() {
9-
console.log('Connecting to the database');
10-
var uri = 'mssql://'
11-
+ encodeURIComponent(credentials.username)
12-
+ ':'
13-
+ encodeURIComponent(credentials.password)
14-
+ '@'
15-
+ credentials.server
16-
+ ((credentials.port) ? ':' + credentials.port : '')
17-
+ ((credentials.instance) ? '/' + credentials.instance : '')
18-
+ '/'
19-
+ credentials.database
20-
+ ((credentials.domain) ? '?domain=' + credentials.domain + '&encrypt=' + credentials.encrypt
21-
: '?encrypt=' + credentials.encrypt);
22-
var connection = new sql.Connection(uri);
6+
const self = this;
7+
self.logger.info('Starting credentials verification');
8+
co(function* () {
9+
self.logger.info('Connecting to the database');
10+
const uri = `mssql://${
11+
encodeURIComponent(credentials.username)
12+
}:${
13+
encodeURIComponent(credentials.password)
14+
}@${
15+
credentials.server
16+
}${(credentials.port) ? `:${credentials.port}` : ''
17+
}${(credentials.instance) ? `/${credentials.instance}` : ''
18+
}/${
19+
credentials.database
20+
}${(credentials.domain) ? `?domain=${credentials.domain}&encrypt=${credentials.encrypt}`
21+
: `?encrypt=${credentials.encrypt}`}`;
22+
const connection = new sql.Connection(uri);
2323
yield connection.connect();
24-
console.log('Verification completed successfully');
24+
self.logger.info('Verification completed successfully');
2525
yield connection.close();
26-
cb(null, {verified: true});
27-
}).catch(err => {
28-
console.log('Error occurred', err.stack || err);
29-
cb(err , {verified: false});
26+
cb(null, { verified: true });
27+
}).catch((err) => {
28+
self.logger.info('Error occurred, credentials are not valid');
29+
cb(err, { verified: false });
3030
});
3131
};

0 commit comments

Comments
 (0)