Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"license": "MIT",
"dependencies": {
"axios": "^0.27.2",
"bcrypt": "^5.0.1",
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"express": "^4.18.1",
"express-basic-auth": "^1.2.1",
Expand Down
6 changes: 3 additions & 3 deletions src/models/admin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose from 'mongoose';
import moment from 'moment';
import bcrypt from 'bcrypt';
import bcryptjs from 'bcryptjs';
import crypto from 'crypto';
import jwt from 'jsonwebtoken';
import Domain from './domain';
Expand Down Expand Up @@ -142,7 +142,7 @@ adminSchema.statics.findByCredentials = async (email, password) => {
throw new Error('Unable to login');
}

const isMatch = await bcrypt.compare(password, admin.password);
const isMatch = await bcryptjs.compare(password, admin.password);

if (!isMatch) {
throw new Error('Unable to login');
Expand Down Expand Up @@ -196,7 +196,7 @@ adminSchema.pre('save', async function (next) {
const admin = this;

if (admin.isModified('password')) {
admin.password = await bcrypt.hash(admin.password, 8);
admin.password = await bcryptjs.hash(admin.password, 8);
notifyAcCreation(admin._id);
}

Expand Down
8 changes: 4 additions & 4 deletions src/models/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose from 'mongoose';
import moment from 'moment';
import bcrypt from 'bcrypt';
import bcryptjs from 'bcryptjs';
import jwt from 'jsonwebtoken';
import { Config } from './config';
import Domain from './domain';
Expand Down Expand Up @@ -53,8 +53,8 @@ componentSchema.options.toJSON = {

componentSchema.methods.generateApiKey = async function () {
const component = this;
const apiKey = await bcrypt.hash(component._id + component.name, 8);
const hash = await bcrypt.hash(apiKey, 8);
const apiKey = await bcryptjs.hash(component._id + component.name, 8);
const hash = await bcryptjs.hash(apiKey, 8);
component.apihash = hash;
await component.save();

Expand Down Expand Up @@ -84,7 +84,7 @@ componentSchema.statics.findByCredentials = async (domainName, componentName, ap
}

let decoded = Buffer.from(apiKey, 'base64').toString('ascii');
const isMatch = await bcrypt.compare(decoded, component.apihash);
const isMatch = await bcryptjs.compare(decoded, component.apihash);

if (!isMatch) {
throw new Error('Unable to find this Component');
Expand Down
6 changes: 3 additions & 3 deletions tests/client-api.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose from 'mongoose';
import request from 'supertest';
import bcrypt from 'bcrypt';
import bcryptjs from 'bcryptjs';
import app from '../src/app';
import Domain from '../src/models/domain';
import GroupConfig from '../src/models/group-config';
Expand Down Expand Up @@ -557,8 +557,8 @@ describe('Testing criteria [REST] ', () => {
owner: adminMasterAccountId
};

const hashApiKey = await bcrypt.hash(component._id + component.name, 8);
const hash = await bcrypt.hash(hashApiKey, 8);
const hashApiKey = await bcryptjs.hash(component._id + component.name, 8);
const hash = await bcryptjs.hash(hashApiKey, 8);
component.apihash = hash;
await new Component(component).save();
const generatedApiKey = Buffer.from(hashApiKey).toString('base64');
Expand Down
4 changes: 2 additions & 2 deletions tests/component.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose from 'mongoose';
import request from 'supertest';
import bcrypt from 'bcrypt';
import bcryptjs from 'bcryptjs';
import app from '../src/app';
import Component from '../src/models/component';
import {
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('Insertion tests', () => {
// DB validation - current Domain token should not be as the same as the generated
const apiKey = Buffer.from(response.body.apiKey, 'base64').toString('ascii');
const component = await Component.findById(component1Id).lean();
const isMatch = await bcrypt.compare(apiKey, component.apihash);
const isMatch = await bcryptjs.compare(apiKey, component.apihash);
expect(isMatch).toEqual(true);
});

Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/db_api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mongoose from 'mongoose';
import bcrypt from 'bcrypt';
import bcryptjs from 'bcryptjs';
import jwt from 'jsonwebtoken';
import Admin from '../../src/models/admin';
import Domain from '../../src/models/domain';
Expand Down Expand Up @@ -245,8 +245,8 @@ export const setupDatabase = async () => {
await new Permission(permissionAll3).save();
await new Permission(permissionAll4).save();

const hashApiKey = await bcrypt.hash(component1._id + component1.name, 8);
const hash = await bcrypt.hash(hashApiKey, 8);
const hashApiKey = await bcryptjs.hash(component1._id + component1.name, 8);
const hash = await bcryptjs.hash(hashApiKey, 8);
component1.apihash = hash;
await new Component(component1).save();
};
6 changes: 3 additions & 3 deletions tests/fixtures/db_client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose from 'mongoose';
import jwt from 'jsonwebtoken';
import bcrypt from 'bcrypt';
import bcryptjs from 'bcryptjs';
import Admin from '../../src/models/admin';
import Domain from '../../src/models/domain';
import GroupConfig from '../../src/models/group-config';
Expand Down Expand Up @@ -226,8 +226,8 @@ export const setupDatabase = async () => {
await new ConfigStrategy(configStrategyTIME_BETWEENDocument).save();
await new ConfigStrategy(configStrategyTIME_GREATDocument).save();

const hashApiKey = await bcrypt.hash(component1._id + component1.name, 8);
const hash = await bcrypt.hash(hashApiKey, 8);
const hashApiKey = await bcryptjs.hash(component1._id + component1.name, 8);
const hash = await bcryptjs.hash(hashApiKey, 8);
component1.apihash = hash;
await new Component(component1).save();
apiKey = Buffer.from(hashApiKey).toString('base64');
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/db_client_payload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose from 'mongoose';
import jwt from 'jsonwebtoken';
import bcrypt from 'bcrypt';
import bcryptjs from 'bcryptjs';
import Admin from '../../src/models/admin';
import Domain from '../../src/models/domain';
import GroupConfig from '../../src/models/group-config';
Expand Down Expand Up @@ -115,8 +115,8 @@ export const setupDatabase = async () => {
await new Config(configPayloadDocument).save();
await new ConfigStrategy(configStrategyPAYLOAD_HAS_ONEDocument).save();

const hashApiKey = await bcrypt.hash(component1._id + component1.name, 8);
const hash = await bcrypt.hash(hashApiKey, 8);
const hashApiKey = await bcryptjs.hash(component1._id + component1.name, 8);
const hash = await bcryptjs.hash(hashApiKey, 8);
component1.apihash = hash;
await new Component(component1).save();
apiKey = Buffer.from(hashApiKey).toString('base64');
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/db_factory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mongoose from 'mongoose';
import bcrypt from 'bcrypt';
import bcryptjs from 'bcryptjs';
import Component from '../../src/models/component';
import Domain from '../../src/models/domain';
import { EnvType } from '../../src/models/environment';
Expand All @@ -26,8 +26,8 @@ export async function createDummyComponent(componentName, domainId, accountId) {
owner: accountId
};

const apiKey = await bcrypt.hash(componentDocument._id + componentDocument.name, 8);
const hash = await bcrypt.hash(apiKey, 8);
const apiKey = await bcryptjs.hash(componentDocument._id + componentDocument.name, 8);
const hash = await bcryptjs.hash(apiKey, 8);
componentDocument.apihash = hash;

await new Component(componentDocument).save();
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/db_metrics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose from 'mongoose';
import jwt from 'jsonwebtoken';
import bcrypt from 'bcrypt';
import bcryptjs from 'bcryptjs';
import { Metric } from '../../src/models/metric';
import Admin from '../../src/models/admin';
import { EnvType } from '../../src/models/environment';
Expand Down Expand Up @@ -169,8 +169,8 @@ export const setupDatabase = async () => {
await new Metric(entry3).save();
await new Metric(entry4).save();

const apiKey = await bcrypt.hash(component1._id + component1.name, 8);
const hash = await bcrypt.hash(apiKey, 8);
const apiKey = await bcryptjs.hash(component1._id + component1.name, 8);
const hash = await bcryptjs.hash(apiKey, 8);
component1.apihash = hash;
await new Component(component1).save();
};