Skip to content

Commit

Permalink
Merge pull request #159 from internxt/feat/upgrade-network-mongo-db
Browse files Browse the repository at this point in the history
[PB-1482]: feat/compatibility-with-mongo-db-to-4.4
  • Loading branch information
sg-gs authored Jan 19, 2024
2 parents 471c2bf + 4b7c791 commit 083dd09
Show file tree
Hide file tree
Showing 18 changed files with 1,379 additions and 30 deletions.
52 changes: 51 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,66 @@ jobs:
node-version: [16.x]
env:
DATABASE_URI: ${{ secrets.DATABASE_URI }}
inxtbridge_storage__mongoUrl: mongodb://admin:password@127.0.0.1:27017/bridge-test
inxtbridge_storage__mongoOpts__user: admin
inxtbridge_storage__mongoOpts__pass: password
inxtbridge_storage__mongoOpts__dbName: bridge-test
inxtbridge_server__port: 0
inxtbridge_api_keys__segment_test: inxtbridge_api_keys__segment_test
inxtbridge_application__CLUSTER__0: inxtbridge_application__CLUSTER__0
inxtbridge_logger__level: 5
inxtbridge_storage__mongoOpts__authSource: inxtbridge_storage__mongoOpts__authSource
inxtbridge_stripe__PK_LIVE: inxtbridge_stripe__PK_LIVE
inxtbridge_api_keys__segment: inxtbridge_api_keys__segment
inxtbridge_stripe__SK_LIVE: inxtbridge_stripe__SK_LIVE
inxtbridge_redis__port: 6379
inxtbridge_server__ssl__redirect: 443
inxtbridge_redis__password:
inxtbridge_complex__rpcUser: inxtbridge_complex__rpcUser
inxtbridge_stripe__SIG_TEST: inxtbridge_stripe__SIG_TEST
inxtbridge_gateway__username: inxtbridge_gateway__username
inxtbridge_mailer__auth__pass: inxtbridge_mailer__auth__pass
inxtbridge_stripe__PK_TEST: inxtbridge_stripe__PK_TEST
inxtbridge_complex__rpcPassword: inxtbridge_complex__rpcPassword
inxtbridge_mailer__host: inxtbridge_mailer__host
inxtbridge_server__public__host: inxtbridge_server__public__host
inxtbridge_stripe__SK_TEST: inxtbridge_stripe__SK_TEST
inxtbridge_complex__rpcUrl: inxtbridge_complex__rpcUrl
inxtbridge_mailer__auth__user: inxtbridge_mailer__auth__user
inxtbridge_mailer__sendgrid__api_key: inxtbridge_mailer__sendgrid__api_key
inxtbridge_storage__mongoOpts__server__poolSize: inxtbridge_storage__mongoOpts__server__poolSize
inxtbridge_stripe__SIG: inxtbridge_stripe__SIG
inxtbridge_drive__api: inxtbridge_drive__api
inxtbridge_server__public__port: 443
inxtbridge_mailer__port: 465
inxtbridge_gateway__password: inxtbridge_gateway__password
inxtbridge_gateway__JWT_SECRET: inxtbridge_gateway__JWT_SECRET
inxtbridge_QUEUE_HOST: inxtbridge_QUEUE_HOST
inxtbridge_QUEUE_USERNAME: inxtbridge_QUEUE_USERNAME
inxtbridge_QUEUE_PASSWORD: inxtbridge_QUEUE_PASSWORD

steps:
- name: Start MongoDB
run: docker run -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=password -e MONGO_INITDB_DATABASE=bridge-test -d mongo:5
run: docker run -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=password -e MONGO_INITDB_DATABASE=bridge-test -d mongo:4.4

- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: https://npm.pkg.github.com/

- run: yarn --ignore-engines
name: Install dependencies
env:
NODE_AUTH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

- run: yarn run test
name: Run Tests

- run: yarn run test:e2e
name: Run E2E Tests
#
# - run: yarn run test-mongo-init
# - run: yarn run test-mongo

3 changes: 2 additions & 1 deletion infrastructure/mongo-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ db.createUser({
pwd: 'password',
roles: [
{ role: 'readWrite', db: '__inxt-network' },
{ role: 'readAnyDatabase', db: 'admin' }
{ role: 'readAnyDatabase', db: 'admin' },
{ role: 'clusterMonitor', db: 'admin' }
],
});

Expand Down
2 changes: 1 addition & 1 deletion lib/core/buckets/usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class InvalidUploadIndexes extends Error {
}
export class InvalidMultiPartValueError extends Error {
constructor() {
super('Multipart is not allowed for files smaller than 500MB');
super('Multipart is not allowed for files smaller than 100MB');

Object.setPrototypeOf(this, InvalidMultiPartValueError.prototype);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/core/users/usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ export class UsersUsecase {
return user;
}

async requestUserDestroy(userEmail: string, deactivator: string, redirect: string) {
const user = await this.usersRepository.findByEmail(userEmail);
async requestUserDestroy(userId: string, deactivator: string, redirect: string) {
const user = await this.usersRepository.findById(userId);

if (!user) {
throw new UserNotFoundError(userEmail);
throw new UserNotFoundError(userId);
}

await this.usersRepository.updateById(user.id, { deactivator });
Expand Down
2 changes: 1 addition & 1 deletion lib/server/routes/buckets.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { randomBytes } = require('crypto');
const DELETING_FILE_MESSAGE = require('../queues/messageTypes').DELETING_FILE_MESSAGE;
const { v4: uuidv4, validate: uuidValidate } = require('uuid');
const { isHexString } = require('../middleware/farmer-auth');
const { default: axios } = require('axios');
const axios = require('axios');
const { MongoDBBucketEntriesRepository } = require('../../core/bucketEntries/MongoDBBucketEntriesRepository');
const { BucketsUsecase, BucketEntryNotFoundError, BucketEntryFrameNotFoundError, BucketNotFoundError, BucketForbiddenError, MissingUploadsError, MaxSpaceUsedError, InvalidUploadIndexes, InvalidMultiPartValueError, NoNodeFoundError, EmptyMirrorsError } = require('../../core/buckets/usecase');
const { BucketEntriesUsecase, BucketEntryVersionNotFoundError } = require('../../core/bucketEntries/usecase');
Expand Down
30 changes: 18 additions & 12 deletions lib/server/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,29 @@ UsersRouter.prototype.createUser = function (req, res, next) {

trackUserActivated(user.uuid, req.body.email);

user.save();
user.save((err) => {

/*
analytics.identify(req.headers.dnt, {
userId: user.uuid,
traits: {
activated: false
if (err) {
return next(err);
}
});
/*
analytics.identify(req.headers.dnt, {
userId: user.uuid,
traits: {
activated: false
}
});
analytics.track(req.headers.dnt, {
userId: user.uuid,
event: 'User Created'
analytics.track(req.headers.dnt, {
userId: user.uuid,
event: 'User Created'
});
*/

self._dispatchAndCreatePubKey(user, req, res, next);
});
*/

self._dispatchAndCreatePubKey(user, req, res, next);

});
}
};
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
"make-docs": "./node_modules/.bin/jsdoc index.js lib -r -R README.md -u ./doc -c .jsdoc.json --verbose -d ./jsdoc",
"publish-docs": "gh-pages -d jsdoc --repo git@github.com:internxt/bridge.git",
"build": "tsc",
"test": "jest --testPathIgnorePatterns ./tests/lib/mongo",
"test": "jest --testPathIgnorePatterns ./tests/lib/mongo ./tests/lib/e2e",
"test:cov": "jest --coverage",
"test:e2e": "NODE_ENV=test jest --config ./tests/lib/e2e/jest-e2e.json --setupFiles dotenv/config",
"test-mongo-init": "ts-node ./tests/lib/mongo/init",
"test-mongo": "jest ./tests/lib/mongo --testTimeout 30000 --runInBand",
"clean": "ts-node ./bin/delete-objects",
Expand All @@ -53,6 +54,7 @@
"homepage": "https://github.com/internxt/bridge#readme",
"devDependencies": {
"@types/async": "^3.2.13",
"@types/chance": "^1.1.6",
"@types/express": "^4.17.13",
"@types/jest": "^27.4.1",
"@types/jsonwebtoken": "^8.5.8",
Expand All @@ -62,8 +64,10 @@
"@types/node": "^17.0.23",
"@types/node-mongodb-fixtures": "^3.2.3",
"@types/sinon": "^10.0.11",
"@types/supertest": "^2.0.12",
"@types/uuid": "^8.3.4",
"chai": "^4.2.0",
"chance": "^1.1.11",
"coveralls": "^2.11.6",
"dotenv": "^16.0.0",
"eslint": "^7.10.0",
Expand All @@ -85,6 +89,7 @@
"redis-mock": "^0.16.0",
"rimraf": "^2.6.3",
"sinon": "^13.0.1",
"supertest": "^6.2.4",
"ts-jest": "^27.1.4",
"ts-node": "^10.7.0"
},
Expand Down
12 changes: 6 additions & 6 deletions tests/lib/core/users/usecase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ describe('Users usecases', () => {
it('When requesting a user destroy, it should work if the user exists', async () => {
const user = fixtures.getUser();
const redirect = 'redirect';
const findUser = stub(usersRepository, 'findByEmail').resolves(user);
const findUser = stub(usersRepository, 'findById').resolves(user);
const updateById = jest.spyOn(usersRepository, 'updateById').mockImplementation();
const eventBusEmitterSpy = jest.spyOn(eventBus, 'emit').mockImplementation();

await usecase.requestUserDestroy(user.email, user.deactivator as string, redirect);
await usecase.requestUserDestroy(user.id, user.deactivator as string, redirect);

expect(findUser.calledOnce).toBeTruthy();
expect(findUser.firstCall.args).toStrictEqual([user.email]);
expect(findUser.firstCall.args).toStrictEqual([user.id]);
expect(updateById).toBeCalledTimes(1);
expect(updateById).toBeCalledWith(user.id, { deactivator: user.deactivator });
expect(eventBusEmitterSpy).toBeCalledTimes(1);
Expand All @@ -368,15 +368,15 @@ describe('Users usecases', () => {
it('When requesting a user destroy, it should fail if the user does not exist', async () => {
const user = fixtures.getUser();
const redirect = 'redirect';
const findUser = stub(usersRepository, 'findByEmail').resolves(null);
const findUser = stub(usersRepository, 'findById').resolves(null);

try {
await usecase.requestUserDestroy(user.email, user.deactivator as string, redirect);
await usecase.requestUserDestroy(user.id, user.deactivator as string, redirect);
expect(true).toBeFalsy();
} catch (err) {
expect(err).toBeInstanceOf(UserNotFoundError);
expect(findUser.calledOnce).toBeTruthy();
expect(findUser.firstCall.args).toStrictEqual([user.email]);
expect(findUser.firstCall.args).toStrictEqual([user.id]);
}
});
});
Expand Down
Loading

0 comments on commit 083dd09

Please sign in to comment.