Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongodb-build-info

Package Overview
Dependencies
Maintainers
11
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-build-info - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

.github/workflows/test.yml

33

index.js

@@ -1,5 +0,7 @@

const ATLAS_REGEX = /mongodb\.net[:/]/i;
const LOCALHOST_REGEX = /(localhost|127\.0\.0\.1)/i;
const DIGITAL_OCEAN_REGEX = /\.mongo\.ondigitalocean\.com[:/]/i;
const { default: ConnectionString } = require('mongodb-connection-string-url');
const ATLAS_REGEX = /\.mongodb(-dev)?\.net$/i;
const LOCALHOST_REGEX = /^(localhost|127\.0\.0\.1)$/i;
const DIGITAL_OCEAN_REGEX = /\.mongo\.ondigitalocean\.com$/i;
function getDataLake(buildInfo) {

@@ -31,12 +33,31 @@ const res = {

function getHostnameFromHost(host) {
return host.split(':')[0];
}
function getHostnameFromUrl(url) {
if (typeof url !== 'string') {
return '';
}
try {
const connectionString = new ConnectionString(url);
const firstHost = connectionString.hosts[0];
return firstHost.split(':')[0];
} catch (e) {
// we assume is already an hostname, will further be checked against regexes
return getHostnameFromHost(url);
}
}
function isAtlas(uri) {
return !!uri.match(ATLAS_REGEX);
return !!getHostnameFromUrl(uri).match(ATLAS_REGEX);
}
function isLocalhost(uri) {
return !!uri.match(LOCALHOST_REGEX);
return !!getHostnameFromUrl(uri).match(LOCALHOST_REGEX);
}
function isDigitalOcean(uri) {
return !!uri.match(DIGITAL_OCEAN_REGEX);
return !!getHostnameFromUrl(uri).match(DIGITAL_OCEAN_REGEX);
}

@@ -43,0 +64,0 @@

19

package.json
{
"name": "mongodb-build-info",
"version": "1.2.0",
"version": "1.3.0",
"description": "Extract information from mongodb's buildInfo",
"main": "index.js",
"scripts": {
"check": "mongodb-js-precommit",
"test": "mocha test/index.spec.js"
"lint": "eslint .",
"depcheck": "depcheck",
"check": "npm run depcheck && npm run lint",
"test": "mocha test/index.spec.js",
"release": "release-it"
},

@@ -28,6 +31,12 @@ "repository": {

"chai": "^4.2.0",
"depcheck": "^1.4.2",
"eslint": "^8.3.0",
"eslint-config-mongodb-js": "^5.0.3",
"mocha": "^7.1.2",
"mongodb-js-precommit": "^2.2.1"
}
"release-it": "^14.11.8"
},
"dependencies": {
"mongodb-connection-string-url": "^2.2.0"
},
"release-it": {}
}

@@ -53,6 +53,37 @@ const expect = require('chai').expect;

expect(isAtlas('mongodb+srv://admin:catscatscats@cat-data-sets.cats.mongodb.net/admin')).to.be.true;
expect(isAtlas('mongodb://admin:catscatscats@cat-data-sets.cats.mongodb.net/admin')).to.be.true;
expect(isAtlas('mongodb://admin:catscatscats@cat-data-sets.cats1.mongodb.net,cat-data-sets.cats2.mongodb.net/admin')).to.be.true;
});
it('works with host only', () => {
expect(isAtlas('cat-data-sets.cats.mongodb.net:27017')).to.be.true;
});
it('works with hostname', () => {
expect(isAtlas('cat-data-sets.cats.mongodb.net')).to.be.true;
});
it('returns true with atlas dev', () => {
expect(isAtlas('mongodb+srv://admin:catscatscats@cat-data-sets.cats.mongodb-dev.net/admin')).to.be.true;
expect(isAtlas('cat-data-sets.cats.mongodb-dev.net')).to.be.true;
});
it('returns false if not atlas', () => {
expect(isAtlas('cat-data-sets.cats.mangodb.net')).to.be.false;
expect(isAtlas('cat-data-sets.catsmongodb.net')).to.be.false;
expect(isAtlas('cat-data-sets.cats.mongodb.netx')).to.be.false;
expect(isAtlas('cat-data-sets.cats.mongodb.com')).to.be.false;
expect(isAtlas('localhost')).to.be.false;
});
it('does not throw and returns with invalid argument', () => {
expect(isAtlas(123)).to.be.false;
expect(isAtlas('')).to.be.false;
expect(isAtlas({})).to.be.false;
expect(isAtlas(undefined)).to.be.false;
expect(isAtlas(null)).to.be.false;
});
});
it('isLocalhost', () => {
context('isLocalhost', () => {
it('reports on localhost', () => {

@@ -65,2 +96,28 @@ expect(isLocalhost('localhost:27019')).to.be.true;

});
it('works as url', () => {
expect(isLocalhost('mongodb://127.0.0.1:27019')).to.be.true;
expect(isLocalhost('mongodb+srv://127.0.0.1')).to.be.true;
expect(isLocalhost('mongodb://localhost')).to.be.true;
expect(isLocalhost('mongodb://localhost:27019')).to.be.true;
});
it('works as hostname', () => {
expect(isLocalhost('127.0.0.1')).to.be.true;
expect(isLocalhost('localhost')).to.be.true;
});
it('does not report if localhost or 127.0.0.1 is not the hostname', () => {
expect(isLocalhost('127.0.0.2')).to.be.false;
expect(isLocalhost('remotehost')).to.be.false;
expect(isLocalhost('mongodb://remotelocalhost')).to.be.false;
});
it('does not throw and returns with invalid argument', () => {
expect(isLocalhost(123)).to.be.false;
expect(isLocalhost('')).to.be.false;
expect(isLocalhost({})).to.be.false;
expect(isLocalhost(undefined)).to.be.false;
expect(isLocalhost(null)).to.be.false;
});
});

@@ -72,2 +129,24 @@

});
it('works with hostname only', () => {
expect(isDigitalOcean('dave-a1234321.mongo.ondigitalocean.com')).to.be.true;
});
it('works with host only', () => {
expect(isDigitalOcean('dave-a1234321.mongo.ondigitalocean.com:27017')).to.be.true;
});
it('returns false if not digitalocean', () => {
expect(isDigitalOcean('dave-a1234321.mongo.ondigitalocean.com2')).to.be.false;
expect(isDigitalOcean('dave-a1234321mongo.ondigitalocean.com')).to.be.false;
expect(isDigitalOcean('dave-a1234321.mongoxondigitalocean.com')).to.be.false;
});
it('does not throw and returns with invalid argument', () => {
expect(isDigitalOcean(123)).to.be.false;
expect(isDigitalOcean('')).to.be.false;
expect(isDigitalOcean({})).to.be.false;
expect(isDigitalOcean(undefined)).to.be.false;
expect(isDigitalOcean(null)).to.be.false;
});
});

@@ -74,0 +153,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc