fixed env variables and removed unneeded files
This commit is contained in:
@@ -0,0 +1 @@
|
||||
// TODO: Add example env file
|
||||
@@ -1,17 +1,16 @@
|
||||
import path from "path";
|
||||
|
||||
const getEnvVariables = () => {
|
||||
const configPath = path.join(__dirname, "..", "..", "config");
|
||||
const configPath = path.join(__dirname, "..", "..", "backend", "config");
|
||||
|
||||
const processType = process.env.NODE_ENV;
|
||||
console.log("123process", processType);
|
||||
|
||||
if (processType === "production" || processType === undefined) {
|
||||
require("dotenv").config({ path: configPath + "/prod.env" });
|
||||
require("dotenv").config({ path: configPath + "/.env.production" });
|
||||
} else if (processType === "development") {
|
||||
require("dotenv").config({ path: configPath + "/dev.env" });
|
||||
require("dotenv").config({ path: configPath + "/.env.development" });
|
||||
} else if (processType === "test") {
|
||||
require("dotenv").config({ path: configPath + "/test.env" });
|
||||
require("dotenv").config({ path: configPath + "/.env.test" });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@
|
||||
"vite-test": "vite",
|
||||
"dev-test": "concurrently \"vite\" \"nodemon server.js\"",
|
||||
"dev-hot": "concurrently \"vite\" \"tsc -w -p ./backend/tsconfig.json\" \"npm run dev:backend\"",
|
||||
"dev:backend": "nodemon dist/server/server-start.js",
|
||||
"dev:backend": "NODE_ENV=development nodemon dist/server/server-start.js",
|
||||
"vite-build": "vite build",
|
||||
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'"
|
||||
},
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
VITE_BACKEND_URL=http://localhost:5173/api
|
||||
Vendored
BIN
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -1,460 +0,0 @@
|
||||
import User from "../../../../dist/models/user";
|
||||
import mongoose from "../../../../dist/db/mongoose";
|
||||
import UtilsFolder from "../../../../dist/db/utils/folderUtils";
|
||||
import Folder from "../../../../dist/models/folder"
|
||||
const conn = mongoose.connection;
|
||||
const createUser = require("../../../fixtures/createUser");
|
||||
const utilsFolder = new UtilsFolder();
|
||||
|
||||
|
||||
let user;
|
||||
let folder;
|
||||
|
||||
process.env.KEY = "1234";
|
||||
|
||||
const waitForDatabase = () => {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (conn.readyState !== 1) {
|
||||
|
||||
conn.once("open", () => {
|
||||
|
||||
resolve();
|
||||
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
resolve();
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(async(done) => {
|
||||
|
||||
await waitForDatabase();
|
||||
|
||||
const {user: gotUser} = await createUser();
|
||||
user = gotUser;
|
||||
|
||||
const folderData = {
|
||||
name: "bunny",
|
||||
owner: user._id,
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
|
||||
folder = new Folder(folderData);
|
||||
await folder.save();
|
||||
|
||||
done();
|
||||
|
||||
// if (conn.readyState === 0) {
|
||||
|
||||
// conn.once("open", async() => {
|
||||
|
||||
// //user = await createUser();
|
||||
// const {user: gotUser} = await createUser();
|
||||
// user = gotUser;
|
||||
|
||||
// const folderData = {
|
||||
// name: "bunny",
|
||||
// owner: user._id,
|
||||
// parent: "/",
|
||||
// parentList: ["/"]
|
||||
// }
|
||||
|
||||
|
||||
// folder = new Folder(folderData);
|
||||
// await folder.save();
|
||||
|
||||
// done();
|
||||
|
||||
|
||||
// })
|
||||
|
||||
// } else {
|
||||
|
||||
// //user = await createUser();
|
||||
// const {user: gotUser} = await createUser();
|
||||
// user = gotUser;
|
||||
|
||||
// const folderData = {
|
||||
// name: "bunny",
|
||||
// owner: user._id,
|
||||
// parent: "/",
|
||||
// parentList: ["/"]
|
||||
// }
|
||||
|
||||
|
||||
// folder = new Folder(folderData);
|
||||
// await folder.save();
|
||||
|
||||
// done();
|
||||
// }
|
||||
|
||||
})
|
||||
|
||||
afterEach( async(done) => {
|
||||
|
||||
await User.deleteMany({});
|
||||
await Folder.deleteMany({});
|
||||
|
||||
done();
|
||||
|
||||
})
|
||||
|
||||
test("When giving userID, and search query, should return a searched filtered folder list", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
let search = "coco";
|
||||
search = new RegExp(search, 'i')
|
||||
|
||||
const folderTwo = await new Folder({
|
||||
name: "coconut",
|
||||
owner: userID,
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
const folderThree = await new Folder({
|
||||
name: "dinnerbone",
|
||||
owner: userID,
|
||||
parent: "1234",
|
||||
parentList: ["/", "1234"]
|
||||
})
|
||||
|
||||
const folderFour = await new Folder({
|
||||
name: "cocoelephant",
|
||||
owner: "1234",
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
await folderTwo.save();
|
||||
await folderThree.save();
|
||||
await folderFour.save();
|
||||
|
||||
|
||||
|
||||
const recievedFolderList = await utilsFolder.getFolderSearchList(userID, search);
|
||||
|
||||
|
||||
expect(recievedFolderList.length).toBe(1);
|
||||
expect(recievedFolderList[0]._id).toEqual(folderTwo._id)
|
||||
})
|
||||
|
||||
test("When giving the wrong userID, should not return search query", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const wrongUserID = "123456789012"
|
||||
let search = "coco";
|
||||
search = new RegExp(search, 'i')
|
||||
|
||||
const folderTwo = await new Folder({
|
||||
name: "coconut",
|
||||
owner: userID,
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
const folderThree = await new Folder({
|
||||
name: "dinnerbone",
|
||||
owner: userID,
|
||||
parent: "1234",
|
||||
parentList: ["/", "1234"]
|
||||
})
|
||||
|
||||
const folderFour = await new Folder({
|
||||
name: "cocoelephant",
|
||||
owner: "1234",
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
await folderTwo.save();
|
||||
await folderThree.save();
|
||||
await folderFour.save();
|
||||
|
||||
|
||||
|
||||
const recievedFolderList = await utilsFolder.getFolderSearchList(wrongUserID, search);
|
||||
|
||||
|
||||
expect(recievedFolderList.length).toBe(0);
|
||||
})
|
||||
|
||||
test("When giving folderID and userID, should return folder info", async() => {
|
||||
|
||||
const folderID = folder._id;
|
||||
const userID = user._id;
|
||||
|
||||
|
||||
const recievedFolder = await utilsFolder.getFolderInfo(folderID, userID);
|
||||
|
||||
|
||||
expect(recievedFolder._id).toEqual(folderID);
|
||||
})
|
||||
|
||||
test("When giving the wrong folderID, should not return folder info", async() => {
|
||||
|
||||
const wrongFolderID = "123456789012";
|
||||
const userID = user._id;
|
||||
|
||||
|
||||
const recievedFolder = await utilsFolder.getFolderInfo(wrongFolderID, userID);
|
||||
|
||||
|
||||
expect(recievedFolder).toBe(null);
|
||||
})
|
||||
|
||||
|
||||
test("When giving the wrong userID, should not return folder info", async() => {
|
||||
|
||||
const folderID = folder._id;
|
||||
const wrongUserID = "123456789012"
|
||||
|
||||
|
||||
const recievedFolder = await utilsFolder.getFolderInfo(folderID, wrongUserID);
|
||||
|
||||
|
||||
expect(recievedFolder).toBe(null);
|
||||
})
|
||||
|
||||
test("When giving userID, parent, and sortby, should return filtered folder list by parent", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const parent = "1234";
|
||||
const sortBy = {createdAt: -1}
|
||||
|
||||
const folderTwo = await new Folder({
|
||||
name: "coconut",
|
||||
owner: userID,
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
const folderThree = await new Folder({
|
||||
name: "dinnerbone",
|
||||
owner: userID,
|
||||
parent: "1234",
|
||||
parentList: ["/", "1234"]
|
||||
})
|
||||
|
||||
const folderFour = await new Folder({
|
||||
name: "cocoelephant",
|
||||
owner: "1234",
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
await folderTwo.save();
|
||||
await folderThree.save();
|
||||
await folderFour.save();
|
||||
|
||||
|
||||
|
||||
const recievedFolderList = await utilsFolder.getFolderListByParent(userID, parent, sortBy);
|
||||
|
||||
|
||||
expect(recievedFolderList.length).toBe(1);
|
||||
expect(recievedFolderList[0]._id).toEqual(folderThree._id);
|
||||
})
|
||||
|
||||
test("When giving the wrong userID, should not return folder list filtered by parent", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const parent = "1234";
|
||||
const sortBy = {createdAt: -1}
|
||||
const wrongUserID = "123456789012"
|
||||
|
||||
|
||||
const folderTwo = await new Folder({
|
||||
name: "coconut",
|
||||
owner: userID,
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
const folderThree = await new Folder({
|
||||
name: "dinnerbone",
|
||||
owner: userID,
|
||||
parent: "1234",
|
||||
parentList: ["/", "1234"]
|
||||
})
|
||||
|
||||
const folderFour = await new Folder({
|
||||
name: "cocoelephant",
|
||||
owner: "1234",
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
await folderTwo.save();
|
||||
await folderThree.save();
|
||||
await folderFour.save();
|
||||
|
||||
|
||||
|
||||
const recievedFolderList = await utilsFolder.getFolderListByParent(wrongUserID, parent, sortBy);
|
||||
|
||||
|
||||
expect(recievedFolderList.length).toBe(0)
|
||||
})
|
||||
|
||||
test("When giving userID, search query, and sort by, should return folder list by search (no limit)" , async() => {
|
||||
|
||||
const userID = user._id;
|
||||
let search = "coco";
|
||||
search = new RegExp(search, 'i')
|
||||
|
||||
const folderTwo = await new Folder({
|
||||
name: "coconut",
|
||||
owner: userID,
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
const folderThree = await new Folder({
|
||||
name: "dinnerbone",
|
||||
owner: userID,
|
||||
parent: "1234",
|
||||
parentList: ["/", "1234"]
|
||||
})
|
||||
|
||||
const folderFour = await new Folder({
|
||||
name: "cocoelephant",
|
||||
owner: "1234",
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
await folderTwo.save();
|
||||
await folderThree.save();
|
||||
await folderFour.save();
|
||||
|
||||
|
||||
|
||||
const recievedFolderList = await utilsFolder.getFolderListBySearch(userID, search);
|
||||
|
||||
|
||||
expect(recievedFolderList.length).toBe(1);
|
||||
expect(recievedFolderList[0]._id).toEqual(folderTwo._id)
|
||||
|
||||
})
|
||||
|
||||
test("When giving wrong userID, should not return folder list by search (no limit)", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
let search = "coco";
|
||||
search = new RegExp(search, 'i')
|
||||
const wrongUserID = "123456789012"
|
||||
|
||||
const folderTwo = await new Folder({
|
||||
name: "coconut",
|
||||
owner: userID,
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
const folderThree = await new Folder({
|
||||
name: "dinnerbone",
|
||||
owner: userID,
|
||||
parent: "1234",
|
||||
parentList: ["/", "1234"]
|
||||
})
|
||||
|
||||
const folderFour = await new Folder({
|
||||
name: "cocoelephant",
|
||||
owner: "1234",
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
await folderTwo.save();
|
||||
await folderThree.save();
|
||||
await folderFour.save();
|
||||
|
||||
|
||||
|
||||
const recievedFolderList = await utilsFolder.getFolderListBySearch(wrongUserID, search);
|
||||
|
||||
|
||||
expect(recievedFolderList.length).toBe(0);
|
||||
})
|
||||
|
||||
test("When giving folderID, userID, and title, should rename folder", async() => {
|
||||
|
||||
const folderID = folder._id;
|
||||
const userID = user._id;
|
||||
const newName = "almonds";
|
||||
|
||||
|
||||
await utilsFolder.renameFolder(folderID, userID, newName);
|
||||
const updatedFolder = await Folder.findById(folderID);
|
||||
|
||||
|
||||
expect(updatedFolder.name).toBe(newName);
|
||||
})
|
||||
|
||||
test("When giving wrong folderID, should not rename folder", async() => {
|
||||
|
||||
const folderID = folder._id;
|
||||
const userID = user._id;
|
||||
const newName = "almonds";
|
||||
const wrongFolderID = "123456789012"
|
||||
|
||||
|
||||
await utilsFolder.renameFolder(wrongFolderID, userID, newName);
|
||||
const updatedFolder = await Folder.findById(folderID);
|
||||
|
||||
|
||||
expect(updatedFolder.name).toBe(folder.name);
|
||||
})
|
||||
|
||||
test("When giving the wrong userID, should not rename folder", async() => {
|
||||
|
||||
const folderID = folder._id;
|
||||
const wrongUserID = "123456789012";
|
||||
const newName = "almonds";
|
||||
|
||||
|
||||
await utilsFolder.renameFolder(folderID, wrongUserID, newName);
|
||||
const updatedFolder = await Folder.findById(folderID);
|
||||
|
||||
|
||||
expect(updatedFolder.name).toBe(folder.name);
|
||||
})
|
||||
|
||||
test("When giving folderID, userID, parent, and parentList, should move folder", async() => {
|
||||
|
||||
const folderID = folder._id;
|
||||
const userID = user._id;
|
||||
const parent = "1234";
|
||||
const parentList = ["/", "1234"];
|
||||
|
||||
|
||||
await utilsFolder.moveFolder(folderID, userID, parent, parentList);
|
||||
const updatedFolder = await Folder.findById(folderID);
|
||||
|
||||
expect(updatedFolder.parentList.length).toBe(2);
|
||||
expect(updatedFolder.parent).toBe(parent);
|
||||
})
|
||||
|
||||
test("When giving the wrong userID for folder move, should not move folder", async() => {
|
||||
|
||||
const folderID = folder._id;
|
||||
const wrongUserID = "123456789012";
|
||||
const parent = "1234";
|
||||
const parentList = ["/", "1234"];
|
||||
|
||||
await utilsFolder.moveFolder(folderID, wrongUserID, parent, parentList);
|
||||
const updatedFolder = await Folder.findById(folderID);
|
||||
|
||||
expect(updatedFolder.parentList.length).toBe(1);
|
||||
expect(updatedFolder.parent).toBe(folder.parent);
|
||||
})
|
||||
|
||||
@@ -1,728 +0,0 @@
|
||||
import User from "../../dist/models/user";
|
||||
import mongoose from "../../dist/db/mongoose";
|
||||
const conn = mongoose.connection;
|
||||
const createUser = require("../fixtures/createUser");
|
||||
const createUser2 = require("../fixtures/createUser2");
|
||||
const createFile = require("../fixtures/createFile");
|
||||
const crypto = require("crypto");
|
||||
const path = require("path");
|
||||
import env from "../../dist/enviroment/env";
|
||||
import createThumbnail from "../../dist/services/ChunkService/utils/createThumbailAny";
|
||||
const request = require("supertest");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const ObjectID = require('mongodb').ObjectID
|
||||
import servers from "../../dist/server/server";
|
||||
import Folder from "../../dist/models/folder";
|
||||
const temp = require("temp").track();
|
||||
const binaryPhraser = require("superagent-binary-parser");
|
||||
const session = require("supertest-session");
|
||||
const loginUser = require("../fixtures/loginUser");
|
||||
const createUserNotEmailVerified = require("../fixtures/createUserNotEmailVerified");
|
||||
const Thumbnail = require("../../dist/models/thumbnail");
|
||||
|
||||
const {server, serverHttps} = servers;
|
||||
|
||||
const app = server;
|
||||
|
||||
let user;
|
||||
let user2;
|
||||
let userData;
|
||||
let userData2;
|
||||
let file;
|
||||
|
||||
process.env.KEY = "1234";
|
||||
env.key = "1234";
|
||||
|
||||
|
||||
const waitForDatabase = () => {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (conn.readyState !== 1) {
|
||||
|
||||
conn.once("open", () => {
|
||||
|
||||
resolve();
|
||||
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
resolve();
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(async(done) => {
|
||||
|
||||
await waitForDatabase();
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
const {user: gotUser, userData: gotUserData} = await createUser();
|
||||
user = gotUser;
|
||||
userData = gotUserData;
|
||||
|
||||
const {user: gotUser2, userData: gotUserData2} = await createUser2();
|
||||
user2 = gotUser2;
|
||||
userData2 = gotUserData2;
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../fixtures/media/folder.png")
|
||||
const metadata = {
|
||||
owner: user._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
// filePath: filepath
|
||||
}
|
||||
|
||||
file = await createFile(filename, filepath, metadata, user);
|
||||
|
||||
done();
|
||||
|
||||
})
|
||||
|
||||
afterEach(async(done) => {
|
||||
|
||||
console.log("After each")
|
||||
|
||||
//const gfs = Grid(conn.db, mongoose.mongo);
|
||||
let bucket = new mongoose.mongo.GridFSBucket(conn.db);
|
||||
|
||||
await User.deleteMany({});
|
||||
|
||||
await Thumbnail.deleteMany({});
|
||||
|
||||
const allFiles = await conn.db.collection("fs.files").find({}).toArray();
|
||||
|
||||
for (let i = 0; i < allFiles.length; i++) {
|
||||
|
||||
const currentFileID = allFiles[i]._id;
|
||||
await bucket.delete(ObjectID(currentFileID));
|
||||
}
|
||||
|
||||
done();
|
||||
})
|
||||
|
||||
test("When giving ID, should send thumbnail data", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const thumbnailFile = await createThumbnail(file, file.filename, user);
|
||||
const thumbnailID = thumbnailFile.metadata.thumbnailID;
|
||||
|
||||
const response = await appSession
|
||||
.get(`/file-service/thumbnail/${thumbnailID}`)
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.length).not.toBe(0);
|
||||
})
|
||||
|
||||
test("When giving no authorization for thumbnail data, should return error", async() => {
|
||||
|
||||
const thumbnailFile = await createThumbnail(file, file.filename, user);
|
||||
const thumbnailID = thumbnailFile.metadata.thumbnailID;
|
||||
|
||||
const response = await request(app)
|
||||
.get(`/file-service/thumbnail/${thumbnailID}`)
|
||||
.send()
|
||||
.expect(401);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When giving wrong auth data for thumbnail, should return 403 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const thumbnailFile = await createThumbnail(file, file.filename, user);
|
||||
const thumbnailID = thumbnailFile.metadata.thumbnailID;
|
||||
|
||||
const appSession2 = session(app);
|
||||
await loginUser(appSession2, userData2);
|
||||
|
||||
const response = await appSession2
|
||||
.get(`/file-service/thumbnail/${thumbnailID}`)
|
||||
.send()
|
||||
.expect(403);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When not email verified should not get thumbnail data, and return 401", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
const {userData: userData3, user: user3} = await createUserNotEmailVerified();
|
||||
await loginUser(appSession, userData3);
|
||||
|
||||
const thumbnailFile = await createThumbnail(file, file.filename, user3);
|
||||
const thumbnailID = thumbnailFile.metadata.thumbnailID;
|
||||
|
||||
const response = await appSession
|
||||
.get(`/file-service/thumbnail/${thumbnailID}`)
|
||||
.send()
|
||||
.expect(401);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When not email verified but email verification disabled should get thumbnail data", async() => {
|
||||
|
||||
env.disableEmailVerification = true;
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
const {userData: userData3, user: user3} = await createUserNotEmailVerified();
|
||||
await loginUser(appSession, userData3);
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../fixtures/media/folder.png")
|
||||
const metadata = {
|
||||
owner: user3._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user3);
|
||||
|
||||
const thumbnailFile = await createThumbnail(file2, file2.filename, user3);
|
||||
const thumbnailID = thumbnailFile.metadata.thumbnailID;
|
||||
|
||||
const response = await appSession
|
||||
.get(`/file-service/thumbnail/${thumbnailID}`)
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.length).not.toBe(0);
|
||||
|
||||
env.disableEmailVerification = undefined;
|
||||
})
|
||||
|
||||
test("When trying to create thumbnail from others users file should not return thumbnail", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
const thumbnailFile = await createThumbnail(file, file.filename, user2);
|
||||
const thumbnailID = thumbnailFile.metadata.thumbnailID;
|
||||
|
||||
expect(thumbnailID).toEqual(undefined)
|
||||
})
|
||||
// // Needs Work, cannot phrase binary data?
|
||||
|
||||
// // test("When giving public ID, should return public file download", async() => {
|
||||
|
||||
// // const userID = user._id;
|
||||
// // const fileID = file._id.toString();
|
||||
// // const token = jwt.sign({_id: userID.toString()}, env.password);
|
||||
// // await conn.db.collection("fs.files")
|
||||
// // .findOneAndUpdate({"_id": ObjectID(fileID),
|
||||
// // "metadata.owner": userID},
|
||||
// // {"$set": {"metadata.linkType": "public", "metadata.link": token}})
|
||||
|
||||
// // const response = await request(app)
|
||||
// // .get(`/file-service/public/download/${fileID}`)
|
||||
// // .parse(binaryPhraser)
|
||||
// // .buffer()
|
||||
// // .end();
|
||||
|
||||
|
||||
// // //expect(response.body._id).toEqual(fileID);
|
||||
|
||||
// // // console.log("public", token.token);
|
||||
|
||||
// // // const url = "/file-service/public/download/" + fileID;
|
||||
// // // console.log("url", url);
|
||||
// // // const response = await request(app).get(url)
|
||||
// // // .set("Authorization", `Bearer ${userToken}`)
|
||||
// // // .set('content-type', 'application/octet-stream')
|
||||
// // // .send()
|
||||
// // // .expect(203)
|
||||
|
||||
// // // const writeStream = temp.createWriteStream();
|
||||
|
||||
// // //response.pipe(writeStream);
|
||||
// // })
|
||||
|
||||
test("When giving public id, should return public info", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const fileID = file._id.toString();
|
||||
const token = jwt.sign({_id: userID.toString()}, env.password).toString();
|
||||
await conn.db.collection("fs.files")
|
||||
.findOneAndUpdate({"_id": ObjectID(fileID),
|
||||
"metadata.owner": userID},
|
||||
{"$set": {"metadata.linkType": "public", "metadata.link": token}})
|
||||
|
||||
const response = await request(app)
|
||||
.get(`/file-service/public/info/${fileID}/${token}`)
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
expect(response.body._id).toEqual(fileID);
|
||||
})
|
||||
|
||||
test("When giving ID for non public file, should return 404 error", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const fileID = file._id.toString();
|
||||
const token = jwt.sign({_id: userID.toString()}, env.password).toString();
|
||||
const response = await request(app)
|
||||
.get(`/file-service/public/info/${fileID}/${token}`)
|
||||
.send()
|
||||
.expect(404);
|
||||
|
||||
expect(response.data).toBe(undefined);
|
||||
})
|
||||
|
||||
test("When giving fileID, should return file info", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
const response = await appSession
|
||||
.get(`/file-service/info/${fileID}`)
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
expect(response.body._id).toEqual(fileID.toString());
|
||||
})
|
||||
|
||||
test("When not authorized for file info, should return 401 error", async() => {
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
const response = await request(app)
|
||||
.get(`/file-service/info/${fileID}`)
|
||||
.send()
|
||||
.expect(401);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When giving wrong auth token for file info, should return 404 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
const response = await appSession
|
||||
.get(`/file-service/info/${fileID}`)
|
||||
.send()
|
||||
.expect(404);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When not email verified should not get file info, and should return 401", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
const {userData: userData3, user: user3} = await createUserNotEmailVerified();
|
||||
await loginUser(appSession, userData3);
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../fixtures/media/folder.png")
|
||||
const metadata = {
|
||||
owner: user3._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user3);
|
||||
|
||||
const fileID = file2._id;
|
||||
|
||||
const response = await appSession
|
||||
.get(`/file-service/info/${fileID}`)
|
||||
.send()
|
||||
.expect(401);
|
||||
|
||||
expect(response.body).toEqual({})
|
||||
})
|
||||
|
||||
test("When not email verified but email verification disabled should return file info", async() => {
|
||||
|
||||
env.disableEmailVerification = true;
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
const {userData: userData3, user: user3} = await createUserNotEmailVerified();
|
||||
await loginUser(appSession, userData3);
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../fixtures/media/folder.png")
|
||||
const metadata = {
|
||||
owner: user3._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user3);
|
||||
|
||||
const fileID = file2._id;
|
||||
|
||||
const response = await appSession
|
||||
.get(`/file-service/info/${fileID}`)
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
expect(response.body._id).toEqual(fileID.toString());
|
||||
|
||||
env.disableEmailVerification = undefined;
|
||||
})
|
||||
|
||||
test("When giving the wrong tempToken for public file info, should return 404 error", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const fileID = file._id.toString();
|
||||
const token = jwt.sign({_id: userID.toString()}, env.password).toString();
|
||||
const wrongToken = "12345"
|
||||
await conn.db.collection("fs.files")
|
||||
.findOneAndUpdate({"_id": ObjectID(fileID),
|
||||
"metadata.owner": userID},
|
||||
{"$set": {"metadata.linkType": "public", "metadata.link": token}})
|
||||
|
||||
const response = await request(app)
|
||||
.get(`/file-service/public/info/${fileID}/${wrongToken}`)
|
||||
.send()
|
||||
.expect(404);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When giving authorization, should get user quicklist", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const response = await appSession
|
||||
.get(`/file-service/quick-list`)
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.length).toBe(1);
|
||||
})
|
||||
|
||||
test("When giving no authoization for quicklist, should return 401 error", async() => {
|
||||
|
||||
const response = await request(app)
|
||||
.get(`/file-service/quick-list`)
|
||||
.send()
|
||||
.expect(401);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When giving default query, should return file list", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const response = await appSession
|
||||
.get(`/file-service/list`)
|
||||
.send({})
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.length).toBe(1);
|
||||
})
|
||||
|
||||
test("When giving no authoization for file list, should return 401 error", async() => {
|
||||
|
||||
const response = await request(app)
|
||||
.get(`/file-service/list`)
|
||||
.send({})
|
||||
.expect(401);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When giving wrong auth for list, should return empty list", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
const response = await appSession
|
||||
.get(`/file-service/list`)
|
||||
.send({})
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.length).toBe(0);
|
||||
})
|
||||
|
||||
test("When authorized should get video cookie", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
await appSession
|
||||
.get(`/file-service/list`)
|
||||
.send("/file-service/download/access-token-stream-video")
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When not authorized should not get video token and return 401 error", async() => {
|
||||
|
||||
await request(app)
|
||||
.get(`/file-service/list`)
|
||||
.send("/file-service/download/access-token-stream-video")
|
||||
.expect(401);
|
||||
})
|
||||
|
||||
test("When authorized should return suggested list", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
await appSession
|
||||
.get(`/file-service/suggested-list`)
|
||||
.send()
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When not authorized should not return suggested list", async() => {
|
||||
|
||||
const response =await request(app)
|
||||
.get(`/file-service/suggested-list`)
|
||||
.send()
|
||||
.expect(401);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When giving fileID and title, should rename file", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
await appSession
|
||||
.patch(`/file-service/rename`)
|
||||
.send({
|
||||
id: fileID,
|
||||
title: "new name"
|
||||
})
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When not authoized for rename file, should return 401 error", async() => {
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
await request(app)
|
||||
.patch(`/file-service/rename`)
|
||||
.send({
|
||||
id: fileID,
|
||||
title: "new name"
|
||||
})
|
||||
.expect(401);
|
||||
})
|
||||
|
||||
test("When giving wrong authorization token for rename file, should return 404 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
await appSession
|
||||
.patch(`/file-service/rename`)
|
||||
.send({
|
||||
id: fileID,
|
||||
title: "new name"
|
||||
})
|
||||
.expect(404);
|
||||
})
|
||||
|
||||
test("When giving fileID and parent, should move file", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const fileID = file._id;
|
||||
const userID = user._id;
|
||||
|
||||
const folder = new Folder({
|
||||
owner: userID,
|
||||
name: "folder",
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
await folder.save();
|
||||
|
||||
const folderID = folder._id;
|
||||
|
||||
await appSession
|
||||
.patch(`/file-service/move`)
|
||||
.send({
|
||||
id: fileID,
|
||||
parent: folderID
|
||||
})
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When not authorized should not move file and return 401", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
const fileID = file._id;
|
||||
const userID = user._id;
|
||||
|
||||
const folder = new Folder({
|
||||
owner: userID,
|
||||
name: "folder",
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
await folder.save();
|
||||
|
||||
const folderID = folder._id;
|
||||
|
||||
await appSession
|
||||
.patch(`/file-service/move`)
|
||||
.send({
|
||||
id: fileID,
|
||||
parent: folderID
|
||||
})
|
||||
.expect(401);
|
||||
})
|
||||
|
||||
test("When giving wrong authorization should not move file and return 404", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
const fileID = file._id;
|
||||
const userID = user._id;
|
||||
|
||||
const folder = new Folder({
|
||||
owner: userID,
|
||||
name: "folder",
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
await folder.save();
|
||||
|
||||
const folderID = folder._id;
|
||||
|
||||
await appSession
|
||||
.patch(`/file-service/move`)
|
||||
.send({
|
||||
id: fileID,
|
||||
parent: folderID
|
||||
})
|
||||
.expect(404);
|
||||
|
||||
})
|
||||
|
||||
test("When giving a parentID that does not exist, should return 404 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
await appSession
|
||||
.patch(`/file-service/move`)
|
||||
.send({
|
||||
id: fileID,
|
||||
parent: "123456789012"
|
||||
})
|
||||
.expect(404);
|
||||
})
|
||||
|
||||
test("When giving fileID should remove file", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
await appSession
|
||||
.delete(`/file-service/remove`)
|
||||
.send({
|
||||
id: fileID,
|
||||
})
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When giving fileID that does not exist for remove file, should return 404 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const fileID = "123456789012";
|
||||
|
||||
await appSession
|
||||
.delete(`/file-service/remove`)
|
||||
.send({
|
||||
id: fileID,
|
||||
})
|
||||
.expect(404);
|
||||
})
|
||||
|
||||
test("When not authorized should not remove file and return 401", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
await appSession
|
||||
.delete(`/file-service/remove`)
|
||||
.send({
|
||||
id: fileID,
|
||||
})
|
||||
.expect(401);
|
||||
})
|
||||
|
||||
test("When giving wrong authorization should not remove file and return 404", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
await appSession
|
||||
.delete(`/file-service/remove`)
|
||||
.send({
|
||||
id: fileID,
|
||||
})
|
||||
.expect(404);
|
||||
})
|
||||
@@ -1,396 +0,0 @@
|
||||
import User from "../../dist/models/user";
|
||||
import mongoose from "../../dist/db/mongoose";
|
||||
const conn = mongoose.connection;
|
||||
const createUser = require("../fixtures/createUser");
|
||||
const createUser2 = require("../fixtures/createUser2");
|
||||
const createFile = require("../fixtures/createFile");
|
||||
const crypto = require("crypto");
|
||||
const path = require("path");
|
||||
import env from "../../dist/enviroment/env";
|
||||
const request = require("supertest");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const ObjectID = require('mongodb').ObjectID
|
||||
import servers from "../../dist/server/server";
|
||||
import Folder from "../../dist/models/folder";
|
||||
const temp = require("temp").track();
|
||||
const binaryPhraser = require("superagent-binary-parser");
|
||||
const session = require("supertest-session");
|
||||
const loginUser = require("../fixtures/loginUser");
|
||||
const createUserNotEmailVerified = require("../fixtures/createUserNotEmailVerified");
|
||||
|
||||
|
||||
const {server, serverHttps} = servers;
|
||||
|
||||
const app = server;
|
||||
|
||||
let user;
|
||||
let user2;
|
||||
let userData;
|
||||
let userData2;
|
||||
let file;
|
||||
let folder;
|
||||
|
||||
process.env.KEY = "1234";
|
||||
env.key = "1234";
|
||||
|
||||
const waitForDatabase = () => {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (conn.readyState !== 1) {
|
||||
|
||||
conn.once("open", () => {
|
||||
|
||||
resolve();
|
||||
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
resolve();
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(async(done) => {
|
||||
|
||||
await waitForDatabase();
|
||||
|
||||
const {user: gotUser, userData: gotUserData} = await createUser();
|
||||
user = gotUser;
|
||||
userData = gotUserData;
|
||||
|
||||
const {user: gotUser2, userData: gotUserData2} = await createUser2();
|
||||
user2 = gotUser2;
|
||||
userData2 = gotUserData2;
|
||||
|
||||
const folderData = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user._id,
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
folder = new Folder(folderData);
|
||||
await folder.save();
|
||||
|
||||
done();
|
||||
|
||||
// if (conn.readyState === 0) {
|
||||
|
||||
// conn.on("open", async() => {
|
||||
|
||||
// // user = await createUser();
|
||||
// // userToken = user.tokens[0].token;
|
||||
|
||||
// // user2 = await createUser2();
|
||||
// // userToken2 = user2.tokens[0].token;
|
||||
|
||||
// const {user: gotUser, token: gotToken} = await createUser();
|
||||
// user = gotUser;
|
||||
// userToken = gotToken;
|
||||
|
||||
// const {user: gotUser2, token: gotToken2} = await createUser2();
|
||||
// user2 = gotUser2;
|
||||
// userToken2 = gotToken2;
|
||||
|
||||
// const folderData = {
|
||||
// name: "bunny",
|
||||
// parent: "/",
|
||||
// owner: user._id,
|
||||
// parentList: ["/"]
|
||||
// }
|
||||
|
||||
// folder = new Folder(folderData);
|
||||
// await folder.save();
|
||||
|
||||
// done();
|
||||
|
||||
// })
|
||||
|
||||
// } else {
|
||||
|
||||
// // user = await createUser();
|
||||
// // userToken = user.tokens[0].token;
|
||||
|
||||
// // user2 = await createUser2();
|
||||
// // userToken2 = user2.tokens[0].token;
|
||||
// const {user: gotUser, token: gotToken} = await createUser();
|
||||
// user = gotUser;
|
||||
// userToken = gotToken;
|
||||
|
||||
// const {user: gotUser2, token: gotToken2} = await createUser2();
|
||||
// user2 = gotUser2;
|
||||
// userToken2 = gotToken2;
|
||||
|
||||
|
||||
// const folderData = {
|
||||
// name: "bunny",
|
||||
// parent: "/",
|
||||
// owner: user._id,
|
||||
// parentList: ["/"]
|
||||
// }
|
||||
|
||||
// folder = new Folder(folderData);
|
||||
// await folder.save();
|
||||
|
||||
// done();
|
||||
|
||||
|
||||
// }
|
||||
})
|
||||
|
||||
afterEach(async(done) => {
|
||||
|
||||
let bucket = new mongoose.mongo.GridFSBucket(conn.db);
|
||||
|
||||
await User.deleteMany({});
|
||||
await Folder.deleteMany({});
|
||||
|
||||
const allFiles = await conn.db.collection("fs.files").find({}).toArray();
|
||||
|
||||
for (let i = 0; i < allFiles.length; i++) {
|
||||
|
||||
const currentFileID = allFiles[i]._id;
|
||||
await bucket.delete(ObjectID(currentFileID));
|
||||
}
|
||||
|
||||
done();
|
||||
})
|
||||
|
||||
test("When giving folderID, should return folder info", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const folderID = folder._id;
|
||||
|
||||
await appSession
|
||||
.get(`/folder-service/info/${folderID}`)
|
||||
.send()
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When not authorized for folder info, should return 401 error", async() => {
|
||||
|
||||
const folderID = folder._id;
|
||||
|
||||
await request(app)
|
||||
.get(`/folder-service/info/${folderID}`)
|
||||
.send()
|
||||
.expect(401);
|
||||
})
|
||||
|
||||
test("When giving wrong authorization for folder info, should return 404 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
const folderID = folder._id;
|
||||
|
||||
await appSession
|
||||
.get(`/folder-service/info/${folderID}`)
|
||||
.send()
|
||||
.expect(404);
|
||||
})
|
||||
|
||||
test("When giving folderID, should return subfolder list", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const folderID = folder._id;
|
||||
|
||||
await appSession
|
||||
.get(`/folder-service/subfolder-list?id=${folderID}`)
|
||||
.send()
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When giving no folderID for subfolder list, should return 404 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
await appSession
|
||||
.get(`/folder-service/subfolder-list`)
|
||||
.send()
|
||||
.expect(404);
|
||||
})
|
||||
|
||||
test("When giving no authorization for subfolder list, should return 401 error", async() => {
|
||||
|
||||
const folderID = folder._id;
|
||||
|
||||
await request(app)
|
||||
.get(`/folder-service/subfolder-list?id=${folderID}`)
|
||||
.send()
|
||||
.expect(401);
|
||||
})
|
||||
|
||||
test("When giving wrong authorization for subfolder list, should return 404 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
const folderID = folder._id;
|
||||
|
||||
await appSession
|
||||
.get(`/folder-service/subfolder-list?id=${folderID}`)
|
||||
.send()
|
||||
.expect(404);
|
||||
|
||||
})
|
||||
|
||||
test("When giving default query, should return folder list", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const query = {}
|
||||
|
||||
await appSession
|
||||
.get(`/folder-service/list?query=${query}`)
|
||||
.send()
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When giving no authorization for folder list, should return 401 error", async() => {
|
||||
|
||||
const query = {}
|
||||
|
||||
await request(app)
|
||||
.get(`/folder-service/list?query=${query}`)
|
||||
.send()
|
||||
.expect(401);
|
||||
})
|
||||
|
||||
test("When giving ID and parent, should move folder", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const folderData = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user._id,
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
const folder2 = new Folder(folderData);
|
||||
await folder2.save();
|
||||
const parentID = folder2._id;
|
||||
|
||||
const folderID = folder._id;
|
||||
|
||||
await appSession
|
||||
.patch(`/folder-service/move`)
|
||||
.send({
|
||||
id: folderID,
|
||||
parent: parentID
|
||||
})
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When giving a folder id that does not exist for move folder, should return 500 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const folderData = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user._id,
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
const folder2 = new Folder(folderData);
|
||||
await folder2.save();
|
||||
const parentID = folder2._id;
|
||||
|
||||
await appSession
|
||||
.patch(`/folder-service/move`)
|
||||
.send({
|
||||
id: "1234",
|
||||
parent: parentID
|
||||
})
|
||||
.expect(500);
|
||||
|
||||
})
|
||||
|
||||
test("When giving parent id that does not exist for move folder, should return 500 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const folderID = folder._id;
|
||||
|
||||
await appSession
|
||||
.patch(`/folder-service/move`)
|
||||
.send({
|
||||
id: folderID,
|
||||
parent: "1234"
|
||||
})
|
||||
.expect(500);
|
||||
})
|
||||
|
||||
test("When giving folder id and title, should rename folder", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const folderID = folder._id;
|
||||
const title = "new name";
|
||||
|
||||
await appSession
|
||||
.patch(`/folder-service/rename`)
|
||||
.send({
|
||||
id: folderID,
|
||||
title
|
||||
})
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When giving not authorization for rename folder, should return 401 error", async() => {
|
||||
|
||||
const folderID = folder._id;
|
||||
const title = "new name";
|
||||
|
||||
await request(app)
|
||||
.patch(`/folder-service/rename`)
|
||||
.send({
|
||||
id: folderID,
|
||||
title
|
||||
})
|
||||
.expect(401);
|
||||
})
|
||||
|
||||
test("When giving id for folder that does not exist for rename, should return 404 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const wrongFolderID = "123456789012";
|
||||
const title = "new name";
|
||||
|
||||
await appSession
|
||||
.patch(`/folder-service/rename`)
|
||||
.send({
|
||||
id: wrongFolderID,
|
||||
title
|
||||
})
|
||||
.expect(404);
|
||||
|
||||
})
|
||||
@@ -1,504 +0,0 @@
|
||||
import User from "../../dist/models/user";
|
||||
import mongoose from "../../dist/db/mongoose";
|
||||
const conn = mongoose.connection;
|
||||
const createUser = require("../fixtures/createUser");
|
||||
import servers from "../../dist/server/server";
|
||||
const request = require("supertest");
|
||||
import env from "../../dist/enviroment/env";
|
||||
const session = require("supertest-session");
|
||||
const loginUser = require("../fixtures/loginUser");
|
||||
const createUserNotEmailVerified = require("../fixtures/createUserNotEmailVerified");
|
||||
|
||||
const {server, serverHttps} = servers;
|
||||
|
||||
const app = server;
|
||||
|
||||
let user;
|
||||
let userToken;
|
||||
let userData;
|
||||
|
||||
const waitForDatabase = () => {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (conn.readyState !== 1) {
|
||||
|
||||
conn.once("open", () => {
|
||||
|
||||
resolve();
|
||||
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
resolve();
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(async(done) => {
|
||||
|
||||
await waitForDatabase();
|
||||
|
||||
const {user: gotUser, userData: gotUserData} = await createUser();
|
||||
user = gotUser;
|
||||
userData = gotUserData;
|
||||
|
||||
done();
|
||||
// if (conn.readyState === 0) {
|
||||
|
||||
// // user = await createUser();
|
||||
// // userToken = user.tokens[0].token;
|
||||
// const {user: gotUser, token: gotToken} = await createUser();
|
||||
// user = gotUser;
|
||||
// userToken = gotToken;
|
||||
|
||||
// done()
|
||||
|
||||
// } else {
|
||||
|
||||
// // user = await createUser();
|
||||
// // userToken = user.tokens[0].token;
|
||||
// const {user: gotUser, token: gotToken} = await createUser();
|
||||
// user = gotUser;
|
||||
// userToken = gotToken;
|
||||
|
||||
// done();
|
||||
// }
|
||||
})
|
||||
|
||||
afterEach(async(done) => {
|
||||
|
||||
await User.deleteMany({});
|
||||
done();
|
||||
})
|
||||
|
||||
test("When authorized, should return user, with no sensitive data", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const response = await appSession
|
||||
.get(`/user-service/user`)
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.password).toEqual(undefined);
|
||||
expect(response.body.privateKey).toEqual(undefined);
|
||||
expect(response.body.publicKey).toEqual(undefined);
|
||||
expect(response.body.tokens).toEqual(undefined);
|
||||
expect(response.body.tempTokens).toEqual(undefined);
|
||||
expect(response.body.email).not.toEqual(undefined);
|
||||
})
|
||||
|
||||
test("When not authorized should return 401 for user", async() => {
|
||||
|
||||
const response = await request(app)
|
||||
.get(`/user-service/user`)
|
||||
.send()
|
||||
.expect(401);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When giving credentials, should login user, and not return sensitive info", async() => {
|
||||
|
||||
const response = await request(app)
|
||||
.post(`/user-service/login`)
|
||||
.send({
|
||||
email: user.email,
|
||||
password: "12345678"
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
expect(response.body.user.password).toEqual(undefined);
|
||||
expect(response.body.user.privateKey).toEqual(undefined);
|
||||
expect(response.body.user.publicKey).toEqual(undefined);
|
||||
expect(response.body.user.tokens).toEqual(undefined);
|
||||
expect(response.body.user.tempTokens).toEqual(undefined);
|
||||
})
|
||||
|
||||
test("When giving wrong creditentials, should return 500 error", async() => {
|
||||
|
||||
const response = await request(app)
|
||||
.post(`/user-service/login`)
|
||||
.send({
|
||||
email: user.email,
|
||||
password: "1454524"
|
||||
})
|
||||
.expect(500);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When authorized should logout user", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
await appSession
|
||||
.post(`/user-service/logout`)
|
||||
.send()
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When not authorized for logout, should return 401 error", async() => {
|
||||
|
||||
const response = await request(app)
|
||||
.post(`/user-service/logout`)
|
||||
.send()
|
||||
.expect(401);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When authoized should logout all sessions of a user", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
await appSession
|
||||
.post(`/user-service/logout-all`)
|
||||
.send()
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When not authorized for logout all, should return 401 error", async() => {
|
||||
|
||||
const response = await request(app)
|
||||
.post(`/user-service/logout-all`)
|
||||
.send()
|
||||
.expect(401);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When giving user data, should create account without returning sensitive data", async() => {
|
||||
|
||||
const response = await request(app)
|
||||
.post(`/user-service/create`)
|
||||
.send({
|
||||
email: "test55@gmail.com",
|
||||
password: "12345678"
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
expect(response.body.password).toEqual(undefined);
|
||||
expect(response.body.privateKey).toEqual(undefined);
|
||||
expect(response.body.publicKey).toEqual(undefined);
|
||||
expect(response.body.tokens).toEqual(undefined);
|
||||
expect(response.body.tempTokens).toEqual(undefined);
|
||||
})
|
||||
|
||||
test("When env variable is set to block accounts, should return 401 error", async() => {
|
||||
|
||||
env.createAcctBlocked = true;
|
||||
|
||||
await request(app)
|
||||
.post(`/user-service/create`)
|
||||
.send({
|
||||
email: "test55@gmail.com",
|
||||
password: "12345678"
|
||||
})
|
||||
.expect(401);
|
||||
|
||||
env.createAcctBlocked = false;
|
||||
})
|
||||
|
||||
test("When giving old password, and new password, should change password", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const oldPassword = "12345678";
|
||||
const newPassword = "987654321";
|
||||
|
||||
await appSession
|
||||
.post(`/user-service/change-password`)
|
||||
.send({
|
||||
oldPassword,
|
||||
newPassword
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
await request(app)
|
||||
.post(`/user-service/login`)
|
||||
.send({
|
||||
email: user.email,
|
||||
password: oldPassword
|
||||
})
|
||||
.expect(500);
|
||||
|
||||
await request(app)
|
||||
.post(`/user-service/login`)
|
||||
.send({
|
||||
email: user.email,
|
||||
password: newPassword
|
||||
})
|
||||
.expect(200);
|
||||
})
|
||||
|
||||
test("When giving wrong old password for change password, should return 500 error", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const wrongOldPassword = "12342345";
|
||||
const newPassword = "987654321";
|
||||
|
||||
await appSession
|
||||
.post(`/user-service/change-password`)
|
||||
.send({
|
||||
wrongOldPassword,
|
||||
newPassword
|
||||
})
|
||||
.expect(500);
|
||||
})
|
||||
|
||||
test("When not authorized for change password, should return 401 error", async() => {
|
||||
|
||||
const oldPassword = "12345678";
|
||||
const newPassword = "987654321";
|
||||
|
||||
const response = await request(app)
|
||||
.post(`/user-service/change-password`)
|
||||
.send({
|
||||
oldPassword,
|
||||
newPassword
|
||||
})
|
||||
.expect(401);
|
||||
|
||||
expect(response.body).toEqual({});
|
||||
})
|
||||
|
||||
test("When not email verified should not change password", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
const {userData: userData2} = await createUserNotEmailVerified()
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
const oldPassword = "12345678";
|
||||
const newPassword = "987654321";
|
||||
|
||||
await appSession
|
||||
.post(`/user-service/change-password`)
|
||||
.send({
|
||||
oldPassword,
|
||||
newPassword
|
||||
})
|
||||
.expect(401);
|
||||
})
|
||||
|
||||
test("When not email verified, but email verification disabled, should change password", async() => {
|
||||
|
||||
env.disableEmailVerification = true;
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
const {userData: userData2} = await createUserNotEmailVerified();
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
const oldPassword = "12345678";
|
||||
const newPassword = "987654321";
|
||||
|
||||
await appSession
|
||||
.post(`/user-service/change-password`)
|
||||
.send({
|
||||
oldPassword,
|
||||
newPassword
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
await request(app)
|
||||
.post(`/user-service/login`)
|
||||
.send({
|
||||
email: userData2.email,
|
||||
password: oldPassword
|
||||
})
|
||||
.expect(500);
|
||||
|
||||
await request(app)
|
||||
.post(`/user-service/login`)
|
||||
.send({
|
||||
email: userData2.email,
|
||||
password: newPassword
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
env.disableEmailVerification = undefined;
|
||||
})
|
||||
|
||||
test("When not giving email, should not create user", async() => {
|
||||
|
||||
await request(app)
|
||||
.post(`/user-service/create`)
|
||||
.send({
|
||||
email: "",
|
||||
password: "12345678"
|
||||
})
|
||||
.expect(500);
|
||||
})
|
||||
|
||||
test("When giving not a valid email, should not create user", async() => {
|
||||
|
||||
await request(app)
|
||||
.post(`/user-service/create`)
|
||||
.send({
|
||||
email: "imnotvalid",
|
||||
password: "12345678"
|
||||
})
|
||||
.expect(500);
|
||||
})
|
||||
|
||||
test("When not giving long enouph password, should not create user", async() => {
|
||||
|
||||
await request(app)
|
||||
.post(`/user-service/create`)
|
||||
.send({
|
||||
email: "test12341@email.com",
|
||||
password: "123"
|
||||
})
|
||||
.expect(500);
|
||||
})
|
||||
|
||||
test("When giving duplicate email, should not create user", async() => {
|
||||
|
||||
await request(app)
|
||||
.post(`/user-service/create`)
|
||||
.send({
|
||||
email: "test55@gmail.com",
|
||||
password: "12345678"
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
|
||||
await request(app)
|
||||
.post(`/user-service/create`)
|
||||
.send({
|
||||
email: "test55@gmail.com",
|
||||
password: "12345678"
|
||||
})
|
||||
.expect(500);
|
||||
})
|
||||
|
||||
test("When authenticated should get refresh token", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
await appSession.post("/user-service/get-token").send().expect(201);
|
||||
})
|
||||
|
||||
test("When authenticated should get detailed user", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
const response = await appSession.get("/user-service/user-detailed").send().expect(200);
|
||||
|
||||
const responseData = response.body;
|
||||
const email = responseData.email;
|
||||
const username = responseData.username;
|
||||
const password = responseData.password;
|
||||
const emailVerified = responseData.emailVerified;
|
||||
const tokens = responseData.tokens;
|
||||
const publicKey = responseData.publicKey;
|
||||
const privateKey = responseData.privateKey;
|
||||
|
||||
expect(email).toEqual(userData.email);
|
||||
expect(username).toEqual(userData.username);
|
||||
expect(password).toEqual(undefined);
|
||||
expect(emailVerified).toEqual(true);
|
||||
expect(tokens).toEqual(undefined);
|
||||
expect(publicKey).toEqual(undefined);
|
||||
expect(privateKey).toEqual(undefined)
|
||||
})
|
||||
|
||||
test("When not authenticated should not get detailed user", async() => {
|
||||
|
||||
await request(app).get("/user-service/user-detailed").send().expect(401);
|
||||
})
|
||||
|
||||
test("When not email verified should not get detailed user", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
const {userData: userData2} = await createUserNotEmailVerified();
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
await request(app).get("/user-service/user-detailed").send().expect(401);
|
||||
})
|
||||
|
||||
test("When not email verified but email verification disabled should get detailed user", async() => {
|
||||
|
||||
env.disableEmailVerification = true;
|
||||
|
||||
const appSession = session(app);
|
||||
|
||||
const {userData: userData2} = await createUserNotEmailVerified();
|
||||
await loginUser(appSession, userData2);
|
||||
|
||||
const response = await appSession.get("/user-service/user-detailed").send().expect(200);
|
||||
|
||||
const responseData = response.body;
|
||||
const email = responseData.email;
|
||||
const username = responseData.username;
|
||||
const password = responseData.password;
|
||||
const emailVerified = responseData.emailVerified;
|
||||
const tokens = responseData.tokens;
|
||||
const publicKey = responseData.publicKey;
|
||||
const privateKey = responseData.privateKey;
|
||||
|
||||
expect(email).toEqual(userData2.email);
|
||||
expect(username).toEqual(userData2.username);
|
||||
expect(password).toEqual(undefined);
|
||||
expect(emailVerified).toEqual(false);
|
||||
expect(tokens).toEqual(undefined);
|
||||
expect(publicKey).toEqual(undefined);
|
||||
expect(privateKey).toEqual(undefined)
|
||||
|
||||
env.disableEmailVerification = undefined;
|
||||
})
|
||||
|
||||
test("When giving existing email should send password reset email", async() => {
|
||||
|
||||
await request(app).post("/user-service/send-password-reset").send({email: userData.email}).expect(200);
|
||||
})
|
||||
|
||||
test("When giving not existing email should return 404", async() => {
|
||||
|
||||
await request(app).post("/user-service/send-password-reset").send({email: "idontexist@void.com"}).expect(404);
|
||||
})
|
||||
|
||||
test("When autheniticated should set users name", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
await appSession.patch("/user-service/add-name").send({name: "testname"}).expect(200);
|
||||
})
|
||||
|
||||
test("When giving a not valid name length should not set users name", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
await appSession.patch("/user-service/add-name").send({name: ""}).expect(403);
|
||||
})
|
||||
|
||||
test("When not giving name should not set users name", async() => {
|
||||
|
||||
const appSession = session(app);
|
||||
await loginUser(appSession, userData);
|
||||
|
||||
await appSession.patch("/user-service/add-name").send().expect(403);
|
||||
})
|
||||
|
||||
Vendored
-32
@@ -1,32 +0,0 @@
|
||||
import mongoose from "../../dist/db/mongoose";
|
||||
const conn = mongoose.connection;
|
||||
const crypto = require("crypto");
|
||||
const fs = require("fs");
|
||||
|
||||
const createFile = (filename, filepath, metadata, user) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
const password = user.getEncryptionKey(); //process.env.KEY;
|
||||
|
||||
const initVect = metadata.IV || crypto.randomBytes(16);
|
||||
|
||||
const CIPHER_KEY = crypto.createHash('sha256').update(password).digest()
|
||||
|
||||
const cipher = crypto.createCipheriv('aes256', CIPHER_KEY, initVect);
|
||||
|
||||
const fileReadStream = fs.createReadStream(filepath);
|
||||
|
||||
let bucket = new mongoose.mongo.GridFSBucket(conn.db, {
|
||||
chunkSizeBytes: 1024 * 255
|
||||
});
|
||||
|
||||
const uploadStream = bucket.openUploadStream(filename, {metadata});
|
||||
|
||||
fileReadStream.pipe(cipher).pipe(uploadStream).on("finish", (file) => {
|
||||
|
||||
resolve(file);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = createFile;
|
||||
Vendored
-33
@@ -1,33 +0,0 @@
|
||||
const jwt = require("jsonwebtoken");
|
||||
import mongoose from "../../dist/db/mongoose";
|
||||
import User from "../../dist/models/user";
|
||||
import env from "../../dist/enviroment/env";
|
||||
|
||||
const createUser = async() => {
|
||||
|
||||
env.key = "1234";
|
||||
env.password = "1234";
|
||||
process.env.KEY = "1234";
|
||||
process.env.PASSWORD = "1234";
|
||||
|
||||
const userID = new mongoose.Types.ObjectId();
|
||||
const userData = {
|
||||
_id: userID,
|
||||
name: "Test User",
|
||||
email: "test2@test.com",
|
||||
password: "12345678",
|
||||
emailVerified: true,
|
||||
tokens: []
|
||||
}
|
||||
|
||||
let user = new User(userData);
|
||||
await user.save();
|
||||
|
||||
await user.generateEncryptionKeys();
|
||||
|
||||
await user.generateAuthToken("192.168.0.1");
|
||||
|
||||
return {user, userData};
|
||||
}
|
||||
|
||||
module.exports = createUser;
|
||||
Vendored
-36
@@ -1,36 +0,0 @@
|
||||
const jwt = require("jsonwebtoken");
|
||||
import mongoose from "../../dist/db/mongoose";
|
||||
import User from "../../dist/models/user";
|
||||
import env from "../../dist/enviroment/env";
|
||||
|
||||
const createUser2 = async() => {
|
||||
|
||||
env.key = "1234";
|
||||
env.password = "1234";
|
||||
process.env.KEY = "1234";
|
||||
process.env.PASSWORD = "1234";
|
||||
|
||||
const userID = new mongoose.Types.ObjectId();
|
||||
const userData = {
|
||||
_id: userID,
|
||||
name: "Test User",
|
||||
email: "test3@test.com",
|
||||
password: "123456789",
|
||||
emailVerified: true,
|
||||
}
|
||||
|
||||
let user = new User(userData);
|
||||
await user.save();
|
||||
|
||||
await user.generateEncryptionKeys();
|
||||
|
||||
const token = await user.generateAuthToken();
|
||||
|
||||
user.emailVerified = true;
|
||||
|
||||
await user.save();
|
||||
|
||||
return {user, userData};
|
||||
}
|
||||
|
||||
module.exports = createUser2;
|
||||
Vendored
-35
@@ -1,35 +0,0 @@
|
||||
const jwt = require("jsonwebtoken");
|
||||
import mongoose from "../../dist/db/mongoose";
|
||||
import User from "../../dist/models/user";
|
||||
import env from "../../dist/enviroment/env";
|
||||
|
||||
const createUser = async(s3Enabled = false, googleDriveEnabled = false) => {
|
||||
|
||||
env.key = "1234";
|
||||
env.password = "1234";
|
||||
process.env.KEY = "1234";
|
||||
process.env.PASSWORD = "1234";
|
||||
|
||||
const userID = new mongoose.Types.ObjectId();
|
||||
const userData = {
|
||||
_id: userID,
|
||||
name: "Test User",
|
||||
email: "test9@test.com",
|
||||
password: "12345678",
|
||||
emailVerified: true,
|
||||
tokens: [],
|
||||
s3Enabled,
|
||||
googleDriveEnabled
|
||||
}
|
||||
|
||||
let user = new User(userData);
|
||||
await user.save();
|
||||
|
||||
await user.generateEncryptionKeys();
|
||||
|
||||
await user.generateAuthToken("192.168.0.1");
|
||||
|
||||
return {user, userData};
|
||||
}
|
||||
|
||||
module.exports = createUser;
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
const jwt = require("jsonwebtoken");
|
||||
import mongoose from "../../dist/db/mongoose";
|
||||
import User from "../../dist/models/user";
|
||||
import env from "../../dist/enviroment/env";
|
||||
|
||||
const createUser = async() => {
|
||||
|
||||
env.key = "1234";
|
||||
env.password = "1234";
|
||||
process.env.KEY = "1234";
|
||||
process.env.PASSWORD = "1234";
|
||||
|
||||
const userID = new mongoose.Types.ObjectId();
|
||||
const userData = {
|
||||
_id: userID,
|
||||
name: "Test User",
|
||||
email: "test23@test.com",
|
||||
password: "12345678",
|
||||
emailVerified: false,
|
||||
tokens: []
|
||||
}
|
||||
|
||||
let user = new User(userData);
|
||||
await user.save();
|
||||
|
||||
await user.generateEncryptionKeys();
|
||||
|
||||
await user.generateAuthToken("192.168.0.1");
|
||||
|
||||
return {user, userData};
|
||||
}
|
||||
|
||||
module.exports = createUser;
|
||||
Vendored
-14
@@ -1,14 +0,0 @@
|
||||
import mongoose from "../../dist/db/mongoose";
|
||||
import User from "../../dist/models/user";
|
||||
import env from "../../dist/enviroment/env";
|
||||
const request = require("supertest");
|
||||
|
||||
const loginUser = async(appSession, userData) => {
|
||||
|
||||
const response = await appSession.post("/user-service/login")
|
||||
.send({email: userData.email, password: userData.password}).expect(200);
|
||||
|
||||
return response.body;
|
||||
}
|
||||
|
||||
module.exports = loginUser;
|
||||
Vendored
-23
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||
width="4156.000000pt" height="4156.000000pt" viewBox="0 0 4156.000000 4156.000000"
|
||||
preserveAspectRatio="xMidYMid meet">
|
||||
<metadata>
|
||||
Created by potrace 1.15, written by Peter Selinger 2001-2017
|
||||
</metadata>
|
||||
<g transform="translate(0.000000,4156.000000) scale(0.100000,-0.100000)"
|
||||
fill="#000000" stroke="none">
|
||||
<path d="M20105 38089 c-2808 -112 -5478 -875 -7900 -2256 -2690 -1534 -4944
|
||||
-3788 -6478 -6478 -1683 -2951 -2449 -6286 -2232 -9710 167 -2615 928 -5153
|
||||
2232 -7440 1534 -2690 3788 -4944 6478 -6478 2928 -1669 6244 -2439 9635
|
||||
-2237 4864 291 9381 2630 12449 6450 2194 2730 3495 6018 3760 9500 35 452 42
|
||||
619 48 1140 6 515 -3 892 -33 1345 -251 3876 -1799 7543 -4411 10443 -2122
|
||||
2357 -4863 4098 -7873 5001 -1429 428 -2828 660 -4355 721 -282 11 -1033 11
|
||||
-1320 -1z m11574 -9161 l1213 -1221 -7789 -7789 -7788 -7788 -4325 4325 -4325
|
||||
4325 1215 1215 c668 668 1218 1214 1222 1213 3 -2 1401 -1395 3106 -3095 1705
|
||||
-1701 3104 -3093 3108 -3093 5 0 2963 2954 6574 6565 3611 3611 6568 6565
|
||||
6571 6565 3 0 551 -550 1218 -1222z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.2 KiB |
Vendored
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB |
Vendored
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 2.4 KiB |
@@ -1,748 +0,0 @@
|
||||
import User from "../../../dist/models/user";
|
||||
import mongoose from "../../../dist/db/mongoose";
|
||||
const conn = mongoose.connection;
|
||||
const createUser = require("../../fixtures/createUser");
|
||||
const createUser2 = require("../../fixtures/createUser2");
|
||||
const path = require("path");
|
||||
const createFile = require("../../fixtures/createFile");
|
||||
const crypto = require("crypto");
|
||||
import createThumbnail from "../../../dist/services/ChunkService/utils/createThumbnail";
|
||||
import env from "../../../dist/enviroment/env";
|
||||
const jwt = require("jsonwebtoken");
|
||||
const ObjectID = require('mongodb').ObjectID
|
||||
import Folder from "../../../dist/models/folder";
|
||||
import FileService from "../../../dist/services/FileService";
|
||||
const fileService = new FileService();
|
||||
const createUserDbType = require("../../fixtures/createUserDbType");
|
||||
|
||||
let user;
|
||||
let file;
|
||||
|
||||
process.env.KEY = "1234";
|
||||
env.key = "1234";
|
||||
|
||||
const waitForDatabase = () => {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (conn.readyState !== 1) {
|
||||
|
||||
conn.once("open", () => {
|
||||
|
||||
resolve();
|
||||
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
resolve();
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(async(done) => {
|
||||
|
||||
await waitForDatabase();
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
// user = await createUser();
|
||||
const {user: gotUser} = await createUser();
|
||||
user = gotUser;
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect
|
||||
}
|
||||
|
||||
file = await createFile(filename, filepath, metadata, user);
|
||||
|
||||
done();
|
||||
|
||||
// if (conn.readyState === 0) {
|
||||
|
||||
// conn.once("open", async() => {
|
||||
|
||||
// const initVect = crypto.randomBytes(16);
|
||||
|
||||
// // user = await createUser();
|
||||
// const {user: gotUser} = await createUser();
|
||||
// user = gotUser;
|
||||
|
||||
// const filename = "bunny.png";
|
||||
// const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
// const metadata = {
|
||||
// owner: user._id,
|
||||
// parent: "/",
|
||||
// parentList: "/",
|
||||
// "IV": initVect
|
||||
// }
|
||||
|
||||
// file = await createFile(filename, filepath, metadata, user);
|
||||
|
||||
// done();
|
||||
// })
|
||||
// } else {
|
||||
|
||||
// const initVect = crypto.randomBytes(16);
|
||||
// //user = await createUser();
|
||||
// const {user: gotUser} = await createUser();
|
||||
// user = gotUser;
|
||||
|
||||
// const filename = "bunny.png";
|
||||
// const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
// const metadata = {
|
||||
// owner: user._id,
|
||||
// parent: "/",
|
||||
// parentList: "/",
|
||||
// "IV": initVect
|
||||
// }
|
||||
|
||||
// file = await createFile(filename, filepath, metadata, user);
|
||||
|
||||
// done();
|
||||
// }
|
||||
})
|
||||
|
||||
|
||||
afterEach( async(done) => {
|
||||
|
||||
//const gfs = Grid(conn.db, mongoose.mongo);
|
||||
let bucket = new mongoose.mongo.GridFSBucket(conn.db);
|
||||
|
||||
await User.deleteMany({});
|
||||
await Folder.deleteMany({});
|
||||
|
||||
const allFiles = await conn.db.collection("fs.files").find({}).toArray();
|
||||
|
||||
for (let i = 0; i < allFiles.length; i++) {
|
||||
|
||||
const currentFileID = allFiles[i]._id;
|
||||
await bucket.delete(ObjectID(currentFileID));
|
||||
}
|
||||
|
||||
done();
|
||||
|
||||
})
|
||||
|
||||
// test("When giving user, and thumbnail id, should get thumbnail" , async() => {
|
||||
|
||||
// const thumbnailFile = await createThumbnail(file, file.filename, user);
|
||||
// const thumbnailID = thumbnailFile.metadata.thumbnailID;
|
||||
|
||||
|
||||
// const recievedThumbnail = await fileService.getThumbnail(user, thumbnailID);
|
||||
|
||||
|
||||
// expect(recievedThumbnail.buffer.length).not.toBe(0);
|
||||
// })
|
||||
|
||||
// test("When giving the wrong user for thumbnail, should throw not authorized error", async() => {
|
||||
|
||||
// const thumbnailFile = await createThumbnail(file, file.filename, user);
|
||||
// const thumbnailID = thumbnailFile.metadata.thumbnailID;
|
||||
// const wrongUser = {
|
||||
// _id: "123456789012"
|
||||
// }
|
||||
|
||||
// await expect(fileService.getThumbnail(wrongUser, thumbnailID)).rejects.toThrow();
|
||||
// })
|
||||
|
||||
test("When giving file, should remove one time link", async() => {
|
||||
|
||||
await fileService.removePublicOneTimeLink(file);
|
||||
})
|
||||
|
||||
test("When giving userID, and fileID, should remove public link", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const fileID = file._id;
|
||||
|
||||
await fileService.removeLink(userID, fileID);
|
||||
})
|
||||
|
||||
test("When giving the wrong userID to remove public link, should throw not found error", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
const fileID = file._id;
|
||||
|
||||
await expect(fileService.removeLink(wrongUserID, fileID)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving user, and fileID, should make file public and return token", async() => {
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
const recievedToken = await fileService.makePublic(user._id, fileID);
|
||||
|
||||
expect(recievedToken.length).not.toBe(0);
|
||||
})
|
||||
|
||||
test("When giving the wrong user to make file public, should throw not found error", async() => {
|
||||
|
||||
const wrongUser = {
|
||||
_id: "123456789012"
|
||||
}
|
||||
const fileID = file._id;
|
||||
|
||||
await expect(fileService.makePublic(wrongUser, fileID)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving fileID, should return file info if public", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const fileID = file._id;
|
||||
const token = jwt.sign({_id: userID.toString()}, env.password);
|
||||
await conn.db.collection("fs.files")
|
||||
.findOneAndUpdate({"_id": ObjectID(fileID),
|
||||
"metadata.owner": userID},
|
||||
{"$set": {"metadata.linkType": "public", "metadata.link": token}})
|
||||
|
||||
|
||||
const receivedFile = await fileService.getPublicInfo(fileID, token);
|
||||
|
||||
expect(receivedFile).not.toBe(null);
|
||||
expect(receivedFile).not.toBe(undefined);
|
||||
})
|
||||
|
||||
test("When giving fileID of a file thats not public, should throw not found error", async() => {
|
||||
|
||||
const fileID = file._id;
|
||||
|
||||
await expect(fileService.getPublicInfo(fileID)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving wrong tempToken for public file, should throw not found error", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const fileID = file._id;
|
||||
const token = jwt.sign({_id: userID.toString()}, env.password);
|
||||
const wrongTempToken = "12345";
|
||||
await conn.db.collection("fs.files")
|
||||
.findOneAndUpdate({"_id": ObjectID(fileID),
|
||||
"metadata.owner": userID},
|
||||
{"$set": {"metadata.linkType": "public", "metadata.link": token}})
|
||||
|
||||
await expect(fileService.getPublicInfo(fileID, wrongTempToken)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving userID and fileID, should make one time public link", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const fileID = file._id;
|
||||
|
||||
await fileService.makeOneTimePublic(userID, fileID);
|
||||
})
|
||||
|
||||
test("When giving wrong userID for one time public link, should throw not found error", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
const fileID = file._id;
|
||||
|
||||
await expect(fileService.makeOneTimePublic(wrongUserID, fileID)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving userID and fileID, should return file info", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const fileID = file._id;
|
||||
|
||||
const receivedFile = await fileService.getFileInfo(userID, fileID);
|
||||
|
||||
expect(receivedFile).not.toBe(null);
|
||||
expect(receivedFile).not.toBe(undefined);
|
||||
})
|
||||
|
||||
test("When giving the wrong userID for file info, should throw not found error", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
const fileID = file._id;
|
||||
|
||||
await expect(fileService.getFileInfo(wrongUserID, fileID)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving userID, should return quicklist", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
|
||||
const receivedQuickList = await fileService.getQuickList(userID);
|
||||
|
||||
expect(receivedQuickList.length).toBe(1);
|
||||
})
|
||||
|
||||
test("When giving wrong userID for quicklist, should return list with 0 length", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
|
||||
const receivedQuickList = await fileService.getQuickList(wrongUserID);
|
||||
|
||||
expect(receivedQuickList.length).toBe(0);
|
||||
})
|
||||
|
||||
test("When giving userID, and default query, should get file list", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
|
||||
const receivedFileList = await fileService.getList(userID, {});
|
||||
|
||||
expect(receivedFileList.length).toBe(1);
|
||||
})
|
||||
|
||||
test("When giving wrong userID for file list, should return list with 0 length", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
|
||||
const receivedList = await fileService.getList(wrongUserID, {});
|
||||
|
||||
expect(receivedList.length).toBe(0);
|
||||
})
|
||||
|
||||
// test("When giving user, should create download token", async() => {
|
||||
|
||||
// const recievedToken = await fileService.getDownloadToken(user);
|
||||
|
||||
// expect(recievedToken.length).not.toBe(0);
|
||||
// })
|
||||
|
||||
// test("When giving user and cookie, should create video download token", async() => {
|
||||
|
||||
// const recievedToken = await fileService.getDownloadTokenVideo(user, {});
|
||||
|
||||
// expect(recievedToken.length).not.toBe(0);
|
||||
// })
|
||||
|
||||
// test("When giving user and tempToken, should remove temp token", async() => {
|
||||
|
||||
// const tempToken = await user.generateTempAuthToken();
|
||||
|
||||
// await fileService.removeTempToken(user, tempToken);
|
||||
// })
|
||||
|
||||
test("When giving userID and search query, should return suggested list", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const search = "bunn";
|
||||
|
||||
const {fileList} = await fileService.getSuggestedList(userID, search);
|
||||
|
||||
expect(fileList.length).toBe(1);
|
||||
})
|
||||
|
||||
test("When giving wrong userID for suggested list, should return list with length of 0", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
const search = "bunn";
|
||||
|
||||
const {fileList} = await fileService.getSuggestedList(wrongUserID, search);
|
||||
|
||||
expect(fileList.length).toBe(0);
|
||||
})
|
||||
|
||||
test("When giving userID, fileID, and title, should rename file", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const fileID = file._id;
|
||||
const title = "new name";
|
||||
|
||||
await fileService.renameFile(userID, fileID, title);
|
||||
})
|
||||
|
||||
test("When giving the wrong userID for rename file, should throw not found error", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
const fileID = file._id;
|
||||
const title = "new name";
|
||||
|
||||
await expect(fileService.renameFile(wrongUserID, fileID, title)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving the userID, fileID, and parentID should move file", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const fileID = file._id;
|
||||
const folder = new Folder({
|
||||
owner: user._id,
|
||||
parent: "/",
|
||||
parentList: ["/"],
|
||||
name: "folder"
|
||||
});
|
||||
|
||||
await folder.save();
|
||||
|
||||
await fileService.moveFile(userID, fileID, folder._id)
|
||||
})
|
||||
|
||||
test("When giving the wrong userID for move file should throw a not found error", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
const fileID = file._id;
|
||||
const folder = new Folder({
|
||||
owner: user._id,
|
||||
parent: "/",
|
||||
parentList: ["/"],
|
||||
name: "folder"
|
||||
});
|
||||
|
||||
await folder.save();
|
||||
|
||||
await expect(fileService.moveFile(wrongUserID, fileID, folder._id)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving an non existing folderID for file move, should throw not found error", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const fileID = file._id;
|
||||
const wrongFolderID = "123456789012";
|
||||
|
||||
await expect(fileService.moveFile(userID, fileID, wrongFolderID)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving user with personal data enabled, should return personal file when getting file list", async() => {
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
const {userData, user: user2} = await createUserDbType(true);
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true,
|
||||
}
|
||||
|
||||
const metadata2 = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user2);
|
||||
const file3 = await createFile(filename, filepath, metadata2, user2);
|
||||
|
||||
const receivedFileList = await fileService.getList(user2, {});
|
||||
|
||||
expect(receivedFileList.length).toBe(2);
|
||||
expect(receivedFileList[0].metadata.personalFile).toBe(undefined);
|
||||
expect(receivedFileList[1].metadata.personalFile).toBe(true);
|
||||
})
|
||||
|
||||
test("When user no longer has personal file enabled, should no longer show personal file", async() => {
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
const {userData, user: user2} = await createUserDbType();
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true,
|
||||
}
|
||||
|
||||
const metadata2 = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user2);
|
||||
const file3 = await createFile(filename, filepath, metadata2, user2);
|
||||
|
||||
const receivedFileList = await fileService.getList(user2, {});
|
||||
|
||||
expect(receivedFileList.length).toBe(1);
|
||||
expect(receivedFileList[0].metadata.personalFile).toBe(undefined);
|
||||
})
|
||||
|
||||
test("When user no longer has personal file enabled, and there is only personal files should return empty list", async() => {
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
const {userData, user: user2} = await createUserDbType();
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true,
|
||||
}
|
||||
|
||||
const metadata2 = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user2);
|
||||
const file3 = await createFile(filename, filepath, metadata2, user2);
|
||||
|
||||
const receivedFileList = await fileService.getList(user2, {});
|
||||
|
||||
expect(receivedFileList.length).toBe(0);
|
||||
})
|
||||
|
||||
test("When personal file enabled should return quicklist with personal file", async() => {
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
const {userData, user: user2} = await createUserDbType(true);
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true,
|
||||
}
|
||||
|
||||
const metadata2 = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user2);
|
||||
const file3 = await createFile(filename, filepath, metadata2, user2);
|
||||
|
||||
const receivedQuickList = await fileService.getQuickList(user2);
|
||||
|
||||
expect(receivedQuickList.length).toBe(2);
|
||||
expect(receivedQuickList[0].metadata.personalFile).toBe(undefined);
|
||||
expect(receivedQuickList[1].metadata.personalFile).toBe(true);
|
||||
})
|
||||
|
||||
test("When personal file is no longer enabled, should return quicklist without personal file", async() => {
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
const {userData, user: user2} = await createUserDbType();
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true,
|
||||
}
|
||||
|
||||
const metadata2 = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user2);
|
||||
const file3 = await createFile(filename, filepath, metadata2, user2);
|
||||
|
||||
const receivedQuickList = await fileService.getQuickList(user2);
|
||||
|
||||
expect(receivedQuickList.length).toBe(1);
|
||||
expect(receivedQuickList[0].metadata.personalFile).toBe(undefined);
|
||||
|
||||
})
|
||||
|
||||
test("When personal file is no longer enabled, and there are only files that are personal should return empty quicklist", async() => {
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
const {userData, user: user2} = await createUserDbType();
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true,
|
||||
}
|
||||
|
||||
const metadata2 = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user2);
|
||||
const file3 = await createFile(filename, filepath, metadata2, user2);
|
||||
|
||||
const receivedQuickList = await fileService.getQuickList(user2);
|
||||
|
||||
expect(receivedQuickList.length).toBe(0);
|
||||
|
||||
})
|
||||
|
||||
test("When giving search query should get searched list", async() => {
|
||||
|
||||
const {user: user2} = await createUser2()
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filename2 = "dog.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user2);
|
||||
const file3 = await createFile(filename, filepath, metadata, user2);
|
||||
const file4 = await createFile(filename2, filepath, metadata, user2);
|
||||
|
||||
const receivedFileList = await fileService.getList(user2, {search: "bunny"})
|
||||
|
||||
expect(receivedFileList.length).toBe(2);
|
||||
expect(receivedFileList[0].filename).toBe(filename);
|
||||
expect(receivedFileList[1].filename).toBe(filename);
|
||||
|
||||
})
|
||||
|
||||
test("When giving search query and having personal file should searched list with personal file", async() => {
|
||||
|
||||
const {user: user2} = await createUserDbType(true)
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filename2 = "dog.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
}
|
||||
|
||||
const metadata2 = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user2);
|
||||
const file3 = await createFile(filename, filepath, metadata2, user2);
|
||||
const file4 = await createFile(filename2, filepath, metadata, user2);
|
||||
|
||||
const receivedFileList = await fileService.getList(user2, {search: "bunny"})
|
||||
|
||||
expect(receivedFileList.length).toBe(2);
|
||||
expect(receivedFileList[0].filename).toBe(filename);
|
||||
expect(receivedFileList[1].filename).toBe(filename);
|
||||
expect(receivedFileList[0].metadata.personalFile).toBe(true)
|
||||
})
|
||||
|
||||
test("When giving search with user that has personal file disabled, should return empty list if all files are personal", async() => {
|
||||
|
||||
const {user: user2} = await createUserDbType()
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filename2 = "dog.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true
|
||||
}
|
||||
|
||||
const metadata2 = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user2);
|
||||
const file3 = await createFile(filename, filepath, metadata2, user2);
|
||||
const file4 = await createFile(filename2, filepath, metadata, user2);
|
||||
|
||||
const receivedFileList = await fileService.getList(user2, {search: "bunny"})
|
||||
|
||||
expect(receivedFileList.length).toBe(0);
|
||||
})
|
||||
|
||||
test("When giving search query with user that has disabled personal file should return list without personal file", async() => {
|
||||
|
||||
const {user: user2} = await createUser2()
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
|
||||
const filename = "bunny.png";
|
||||
const filename2 = "dog.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
}
|
||||
|
||||
const metadata2 = {
|
||||
owner: user2._id,
|
||||
parent: "/",
|
||||
parentList: "/",
|
||||
"IV": initVect,
|
||||
personalFile: true
|
||||
}
|
||||
|
||||
const file2 = await createFile(filename, filepath, metadata, user2);
|
||||
const file3 = await createFile(filename, filepath, metadata2, user2);
|
||||
const file4 = await createFile(filename2, filepath, metadata, user2);
|
||||
|
||||
const receivedFileList = await fileService.getList(user2, {search: "bunny"})
|
||||
|
||||
expect(receivedFileList.length).toBe(1);
|
||||
expect(receivedFileList[0].filename).toBe(filename);
|
||||
expect(receivedFileList[0].metadata.personalFile).toBe(undefined)
|
||||
|
||||
})
|
||||
// test("When giving userID, and fileID, should remove file", async() => {
|
||||
|
||||
// const userID = user._id;
|
||||
// const fileID = file._id;
|
||||
|
||||
// await fileService.deleteFile(userID, fileID);
|
||||
// })
|
||||
|
||||
// test("When giving the wrong userID for delete file, should throw not found error", async() => {
|
||||
|
||||
// const wrongUserID = "123456789012";
|
||||
// const fileID = file._id;
|
||||
|
||||
// await expect(fileService.deleteFile(wrongUserID, fileID)).rejects.toThrow();
|
||||
// })
|
||||
@@ -1,620 +0,0 @@
|
||||
import User from "../../../dist/models/user";
|
||||
const createUser = require("../../fixtures/createUser");
|
||||
import Folder from "../../../dist/models/folder";
|
||||
import mongoose from "../../../dist/db/mongoose"
|
||||
const conn = mongoose.connection;
|
||||
const crypto = require("crypto");
|
||||
const createFile = require("../../fixtures/createFile");
|
||||
const path = require("path");
|
||||
const ObjectID = require('mongodb').ObjectID
|
||||
import FolderService from "../../../dist/services/FolderService"
|
||||
const folderService = new FolderService();
|
||||
const createUserDbType = require("../../fixtures/createUserDbType");
|
||||
const createUser2 = require("../../fixtures/createUser2");
|
||||
|
||||
let user;
|
||||
let folder;
|
||||
|
||||
const waitForDatabase = () => {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (conn.readyState !== 1) {
|
||||
|
||||
conn.once("open", () => {
|
||||
|
||||
resolve();
|
||||
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
resolve();
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(async(done) => {
|
||||
|
||||
await waitForDatabase();
|
||||
|
||||
const {user: gotUser} = await createUser();
|
||||
user = gotUser;
|
||||
|
||||
const folderData = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user._id,
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
folder = new Folder(folderData);
|
||||
await folder.save();
|
||||
|
||||
done();
|
||||
|
||||
// if (conn.readyState === 0) {
|
||||
|
||||
// conn.once("open", async() => {
|
||||
|
||||
// const {user: gotUser} = await createUser();
|
||||
// user = gotUser;
|
||||
|
||||
// const folderData = {
|
||||
// name: "bunny",
|
||||
// parent: "/",
|
||||
// owner: user._id,
|
||||
// parentList: ["/"]
|
||||
// }
|
||||
|
||||
// folder = new Folder(folderData);
|
||||
// await folder.save();
|
||||
|
||||
// done();
|
||||
// })
|
||||
|
||||
// } else {
|
||||
|
||||
// // user = await createUser();
|
||||
// const {user: gotUser} = await createUser();
|
||||
// user = gotUser;
|
||||
|
||||
// const folderData = {
|
||||
// name: "bunny",
|
||||
// parent: "/",
|
||||
// owner: user._id,
|
||||
// parentList: ["/"]
|
||||
// }
|
||||
|
||||
// folder = new Folder(folderData);
|
||||
// await folder.save();
|
||||
|
||||
// done();
|
||||
// }
|
||||
|
||||
})
|
||||
|
||||
afterEach(async(done) => {
|
||||
|
||||
let bucket = new mongoose.mongo.GridFSBucket(conn.db);
|
||||
|
||||
await User.deleteMany({});
|
||||
await Folder.deleteMany({});
|
||||
|
||||
// const gfs = Grid(conn.db, mongoose.mongo);
|
||||
|
||||
const allFiles = await conn.db.collection("fs.files").find({}).toArray();
|
||||
|
||||
for (let i = 0; i < allFiles.length; i++) {
|
||||
|
||||
const currentFileID = allFiles[i]._id;
|
||||
await bucket.delete(ObjectID(currentFileID));
|
||||
}
|
||||
|
||||
done();
|
||||
})
|
||||
|
||||
test("When giving userID and folderID, should return folder info" , async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const folderID = folder._id;
|
||||
|
||||
const receivedFolder = await folderService.getFolderInfo(userID, folderID);
|
||||
|
||||
expect(receivedFolder._id).toEqual(folderID);
|
||||
})
|
||||
|
||||
test("When giving the wrong userID for folder info, should return not found error", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
const folderID = folder._id;
|
||||
|
||||
await expect(folderService.getFolderInfo(wrongUserID, folderID)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving userID and folderID, should return subfolder list", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const folderID = folder._id;
|
||||
|
||||
const {folderNameList, folderIDList} = await folderService.getFolderSublist(userID, folderID);
|
||||
|
||||
expect(folderNameList.length).toBe(2);
|
||||
expect(folderIDList.length).toBe(2);
|
||||
})
|
||||
|
||||
test("When giving the wrong userID for subfolder list, should throw not found error", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
const folderID = folder._id;
|
||||
|
||||
await expect(folderService.getFolderSublist(wrongUserID, folderID)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving userID and query with default values, should return folder list", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
|
||||
|
||||
const receivedFolderList = await folderService.getFolderList(userID, {});
|
||||
|
||||
|
||||
expect(receivedFolderList.length).toBe(1);
|
||||
})
|
||||
|
||||
test("When giving wrong userID for folder list, should return empty list", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
|
||||
|
||||
const receivedFolderList = await folderService.getFolderList(wrongUserID, {});
|
||||
|
||||
|
||||
expect(receivedFolderList.length).toBe(0);
|
||||
})
|
||||
|
||||
test("When giving userID, folderID, and title, should rename folder", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const folderID = folder._id;
|
||||
const title = "coconot";
|
||||
|
||||
await folderService.renameFolder(userID, folderID, title);
|
||||
const updatedFolder = await Folder.findById(folderID);
|
||||
|
||||
expect(updatedFolder.name).toBe(title);
|
||||
})
|
||||
|
||||
test("When giving wrong userID for rename folder, should throw not found error", async() => {
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
const folderID = folder._id;
|
||||
const title = "coconot";
|
||||
|
||||
|
||||
await expect(folderService.renameFolder(wrongUserID, folderID, title)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving userID, folderID, and parentID, should move folder", async() => {
|
||||
|
||||
const newFolder = new Folder({
|
||||
name: "new folder",
|
||||
owner: user._id,
|
||||
parent: "1234",
|
||||
parentList: ["/", "1234"]
|
||||
})
|
||||
|
||||
await newFolder.save();
|
||||
|
||||
const userID = user._id;
|
||||
const folderID = folder._id;
|
||||
const parentID = newFolder._id;
|
||||
|
||||
|
||||
await folderService.moveFolder(userID, folderID, parentID);
|
||||
const updatedFolder = await Folder.findById(folderID);
|
||||
|
||||
|
||||
expect(updatedFolder.parent.toString()).toBe(parentID.toString());
|
||||
})
|
||||
|
||||
test("When giving the wrong userID for move folder, should throw new found error", async() => {
|
||||
|
||||
const newFolder = new Folder({
|
||||
name: "new folder",
|
||||
owner: user._id,
|
||||
parent: "1234",
|
||||
parentList: ["/", "1234"]
|
||||
})
|
||||
|
||||
await newFolder.save();
|
||||
|
||||
const wrongUserID = "123456789012";
|
||||
const folderID = folder._id;
|
||||
const parentID = newFolder._id;
|
||||
|
||||
await expect(folderService.moveFolder(wrongUserID, folderID, parentID)).rejects.toThrow()
|
||||
})
|
||||
|
||||
test("When giving a parentID that does not exist for move folder, should throw not found error", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
const folderID = folder._id;
|
||||
const wrongParentID = "123456789012";
|
||||
|
||||
await expect(folderService.moveFolder(userID, folderID, wrongParentID)).rejects.toThrow()
|
||||
})
|
||||
|
||||
test("When giving userID, folderID, and parentID, for folder with subitems, should move all items", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
|
||||
const folderOne = new Folder({
|
||||
name: "new folder",
|
||||
owner: user._id,
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
const folderID = folderOne._id;
|
||||
|
||||
await folderOne.save();
|
||||
|
||||
const folderTwo = new Folder({
|
||||
name: "new folder 2",
|
||||
owner: user._id,
|
||||
parent: folderOne._id,
|
||||
parentList: ["/", folderOne._id.toString()]
|
||||
})
|
||||
|
||||
await folderTwo.save();
|
||||
|
||||
const folderThree = new Folder({
|
||||
name: "new folder3 ",
|
||||
owner: user._id,
|
||||
parent: folderTwo._id,
|
||||
parentList: ["/", folderOne._id.toString(), folderTwo._id.toString()]
|
||||
})
|
||||
|
||||
await folderThree.save();
|
||||
|
||||
const folderFour = new Folder({
|
||||
name: "new folder 4",
|
||||
owner: user._id,
|
||||
parent: "/",
|
||||
parentList: ["/"]
|
||||
})
|
||||
|
||||
const parentID = folderFour._id;
|
||||
|
||||
await folderFour.save();
|
||||
|
||||
process.env.KEY = "1234";
|
||||
|
||||
const initVect = crypto.randomBytes(16);
|
||||
const filename = "bunny.png";
|
||||
const filepath = path.join(__dirname, "../../fixtures/media/check.svg")
|
||||
const metadata = {
|
||||
owner: user._id,
|
||||
parent: folderOne._id.toString(),
|
||||
parentList: "/,"+folderOne._id.toString(),
|
||||
"IV": initVect
|
||||
}
|
||||
|
||||
const fileOne = await createFile(filename, filepath, metadata, user);
|
||||
|
||||
const metadataTwo = {
|
||||
owner: user._id,
|
||||
parent: folderTwo._id.toString(),
|
||||
parentList: "/,"+folderTwo._id.toString(),
|
||||
"IV": initVect
|
||||
}
|
||||
|
||||
const fileTwo = await createFile(filename, filepath, metadataTwo, user);
|
||||
|
||||
const metadataThree = {
|
||||
owner: user._id,
|
||||
parent: folderThree._id.toString(),
|
||||
parentList: "/,"+folderThree._id.toString(),
|
||||
"IV": initVect
|
||||
}
|
||||
|
||||
const fileThree = await createFile(filename, filepath, metadataThree, user);
|
||||
|
||||
|
||||
|
||||
await folderService.moveFolder(userID, folderID, parentID);
|
||||
const updatedFolderOne = await Folder.findById(folderOne._id);
|
||||
const updatedFolderTwo = await Folder.findById(folderTwo._id);
|
||||
const updatedFolderThree = await Folder.findById(folderThree._id);
|
||||
|
||||
|
||||
|
||||
expect(updatedFolderOne.parent.toString()).toBe(parentID.toString());
|
||||
expect(updatedFolderOne.parentList[0].toString()).toBe("/");
|
||||
expect(updatedFolderOne.parentList[1].toString()).toBe(parentID.toString());
|
||||
expect(updatedFolderOne.parentList.length).toBe(2);
|
||||
|
||||
expect(updatedFolderTwo.parentList[0].toString()).toBe("/");
|
||||
expect(updatedFolderTwo.parentList[1].toString()).toBe(parentID.toString());
|
||||
expect(updatedFolderTwo.parentList[2].toString()).toBe(folderOne._id.toString());
|
||||
expect(updatedFolderTwo.parentList.length).toBe(3);
|
||||
|
||||
expect(updatedFolderThree.parentList[0].toString()).toBe("/");
|
||||
expect(updatedFolderThree.parentList[1].toString()).toBe(parentID.toString());
|
||||
expect(updatedFolderThree.parentList[2].toString()).toBe(folderOne._id.toString());
|
||||
expect(updatedFolderThree.parentList[3].toString()).toBe(folderTwo._id.toString());
|
||||
expect(updatedFolderThree.parentList.length).toBe(4);
|
||||
})
|
||||
|
||||
test("When searching for folder should return list of searched items", async() => {
|
||||
|
||||
const {user: user2} = await createUser2();
|
||||
|
||||
const folderData2 = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
|
||||
const folderData3 = {
|
||||
name: "dog",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
|
||||
const folder2 = new Folder(folderData2);
|
||||
const folder3 = new Folder(folderData2);
|
||||
const folder4 = new Folder(folderData3);
|
||||
|
||||
await folder2.save();
|
||||
await folder3.save();
|
||||
await folder4.save();
|
||||
|
||||
const folderList = await folderService.getFolderList(user2, {search: "bunny"})
|
||||
|
||||
expect(folderList.length).toBe(2);
|
||||
})
|
||||
|
||||
test("When searching for list with personal folders should return list with personal folders", async() => {
|
||||
|
||||
const {user: user2} = await createUserDbType(true);
|
||||
|
||||
const folderData2 = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"],
|
||||
personalFolder: true
|
||||
}
|
||||
|
||||
|
||||
const folderData3 = {
|
||||
name: "dog",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
|
||||
const folder2 = new Folder(folderData2);
|
||||
const folder3 = new Folder(folderData2);
|
||||
const folder4 = new Folder(folderData3);
|
||||
|
||||
await folder2.save();
|
||||
await folder3.save();
|
||||
await folder4.save();
|
||||
|
||||
const folderList = await folderService.getFolderList(user2, {search: "bunny"})
|
||||
|
||||
expect(folderList.length).toBe(2);
|
||||
})
|
||||
|
||||
test("When user no longer has personal folders enabled, should return list with no personal folders when searching", async() => {
|
||||
|
||||
const {user: user2} = await createUserDbType();
|
||||
|
||||
const folderData2 = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"],
|
||||
personalFolder: true
|
||||
}
|
||||
|
||||
const folderData4 = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"],
|
||||
}
|
||||
|
||||
|
||||
const folderData3 = {
|
||||
name: "dog",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
|
||||
const folder2 = new Folder(folderData2);
|
||||
const folder3 = new Folder(folderData4);
|
||||
const folder4 = new Folder(folderData3);
|
||||
|
||||
await folder2.save();
|
||||
await folder3.save();
|
||||
await folder4.save();
|
||||
|
||||
const folderList = await folderService.getFolderList(user2, {search: "bunny"})
|
||||
|
||||
expect(folderList.length).toBe(1);
|
||||
|
||||
})
|
||||
|
||||
test("When user no longer has personal folders enabled, and only has personal folders should return empty list when searching", async() => {
|
||||
|
||||
const {user: user2} = await createUserDbType();
|
||||
|
||||
const folderData2 = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"],
|
||||
personalFolder: true
|
||||
}
|
||||
|
||||
const folderData4 = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"],
|
||||
personalFolder: true
|
||||
}
|
||||
|
||||
|
||||
const folderData3 = {
|
||||
name: "dog",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
|
||||
const folder2 = new Folder(folderData2);
|
||||
const folder3 = new Folder(folderData4);
|
||||
const folder4 = new Folder(folderData3);
|
||||
|
||||
await folder2.save();
|
||||
await folder3.save();
|
||||
await folder4.save();
|
||||
|
||||
const folderList = await folderService.getFolderList(user2, {search: "bunny"})
|
||||
|
||||
expect(folderList.length).toBe(0);
|
||||
})
|
||||
|
||||
test("When user has personal folder enabled should get folder list with personal folder", async() => {
|
||||
|
||||
const {user: user2} = await createUserDbType(true);
|
||||
|
||||
const folderData2 = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"],
|
||||
personalFolder: true
|
||||
}
|
||||
|
||||
|
||||
const folderData3 = {
|
||||
name: "dog",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
|
||||
const folder2 = new Folder(folderData2);
|
||||
const folder3 = new Folder(folderData2);
|
||||
const folder4 = new Folder(folderData3);
|
||||
|
||||
await folder2.save();
|
||||
await folder3.save();
|
||||
await folder4.save();
|
||||
|
||||
const folderList = await folderService.getFolderList(user2, {})
|
||||
|
||||
expect(folderList.length).toBe(3);
|
||||
|
||||
})
|
||||
|
||||
test("When user no longer has personal folders enabled should return list without personal folders", async() => {
|
||||
|
||||
const {user: user2} = await createUserDbType();
|
||||
|
||||
const folderData2 = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"],
|
||||
personalFolder: true
|
||||
}
|
||||
|
||||
const folderData4 = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"],
|
||||
}
|
||||
|
||||
|
||||
const folderData3 = {
|
||||
name: "dog",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"]
|
||||
}
|
||||
|
||||
|
||||
const folder2 = new Folder(folderData2);
|
||||
const folder3 = new Folder(folderData4);
|
||||
const folder4 = new Folder(folderData3);
|
||||
|
||||
await folder2.save();
|
||||
await folder3.save();
|
||||
await folder4.save();
|
||||
|
||||
const folderList = await folderService.getFolderList(user2, {})
|
||||
|
||||
expect(folderList.length).toBe(2);
|
||||
})
|
||||
|
||||
test("When user no longer has personal folders enabled, and there are only personal folders should return empty list", async() => {
|
||||
|
||||
const {user: user2} = await createUserDbType();
|
||||
|
||||
const folderData2 = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"],
|
||||
personalFolder: true
|
||||
}
|
||||
|
||||
const folderData4 = {
|
||||
name: "bunny",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"],
|
||||
personalFolder: true
|
||||
}
|
||||
|
||||
|
||||
const folderData3 = {
|
||||
name: "dog",
|
||||
parent: "/",
|
||||
owner: user2._id,
|
||||
parentList: ["/"],
|
||||
personalFolder: true
|
||||
}
|
||||
|
||||
|
||||
const folder2 = new Folder(folderData2);
|
||||
const folder3 = new Folder(folderData4);
|
||||
const folder4 = new Folder(folderData3);
|
||||
|
||||
await folder2.save();
|
||||
await folder3.save();
|
||||
await folder4.save();
|
||||
|
||||
const folderList = await folderService.getFolderList(user2, {})
|
||||
|
||||
expect(folderList.length).toBe(0);
|
||||
|
||||
})
|
||||
@@ -1,136 +0,0 @@
|
||||
import User from "../../../dist/models/user";
|
||||
import mongoose from "../../../dist/db/mongoose";
|
||||
const conn = mongoose.connection;
|
||||
const createUser = require("../../fixtures/createUser");
|
||||
import UserService from "../../../dist/services/UserService";
|
||||
const userService = new UserService();
|
||||
|
||||
let user;
|
||||
|
||||
|
||||
const waitForDatabase = () => {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (conn.readyState !== 1) {
|
||||
|
||||
conn.once("open", () => {
|
||||
|
||||
resolve();
|
||||
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
resolve();
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(async(done) => {
|
||||
|
||||
await waitForDatabase();
|
||||
// user = await createUser();
|
||||
const {user: gotUser} = await createUser();
|
||||
user = gotUser;
|
||||
done();
|
||||
|
||||
})
|
||||
|
||||
afterEach(async(done) => {
|
||||
|
||||
await User.deleteMany({});
|
||||
done();
|
||||
})
|
||||
|
||||
test("When giving email and password for login, should return user and token", async() => {
|
||||
|
||||
const email = user.email;
|
||||
const password = "12345678";
|
||||
|
||||
const userData = {
|
||||
email,
|
||||
password
|
||||
}
|
||||
|
||||
const {user: receivedUser} = await userService.login(userData);
|
||||
|
||||
expect(receivedUser._id.toString()).toBe(user._id.toString());
|
||||
})
|
||||
|
||||
test("When giving wrong password for login, throw error", async() => {
|
||||
|
||||
const email = user.email;
|
||||
const password = "87654321";
|
||||
|
||||
const userData = {
|
||||
email,
|
||||
password
|
||||
}
|
||||
|
||||
await expect(userService.login(userData)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving user should logout and not throw error", async() => {
|
||||
|
||||
await userService.logout(user);
|
||||
})
|
||||
|
||||
test("When giving user, should logout all, show 0 tokens, and not throw error", async() => {
|
||||
|
||||
const userID = user._id;
|
||||
|
||||
await userService.logoutAll(user);
|
||||
const updatedUser = await User.findById(userID);
|
||||
|
||||
expect(updatedUser.tokens.length).toBe(0);
|
||||
})
|
||||
|
||||
test("When giving user data, should create new user", async() => {
|
||||
|
||||
const userData = {
|
||||
name: "Test User",
|
||||
email: "test3@test.com",
|
||||
password: "12345678",
|
||||
}
|
||||
|
||||
const {user: createdUser} = await userService.create(userData);
|
||||
|
||||
expect(createdUser.email).toBe(userData.email);
|
||||
})
|
||||
|
||||
test("When creating user with duplicate email, should throw an error", async() => {
|
||||
|
||||
const userData = {
|
||||
name: "Test User",
|
||||
email: "test2@test.com",
|
||||
password: "12345678",
|
||||
}
|
||||
|
||||
await expect(userService.create(userData)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving user, token, old password, and new password. Should change password", async() => {
|
||||
|
||||
const oldPassword = "12345678";
|
||||
const newPassword = "87654321";
|
||||
|
||||
await userService.changePassword(user, oldPassword, newPassword);
|
||||
})
|
||||
|
||||
test("When giving wrong old password for change password, should throw an error", async() => {
|
||||
|
||||
const wrongOldPassword = "1649560569";
|
||||
const newPassword = "87654321";
|
||||
|
||||
await expect(userService.changePassword(user._id, wrongOldPassword, newPassword)).rejects.toThrow();
|
||||
})
|
||||
|
||||
test("When giving new password with insufficent length, should throw an error", async() => {
|
||||
|
||||
const oldPassword = "12345678";
|
||||
const newPassword = "8765";
|
||||
|
||||
await expect(userService.changePassword(user._id, oldPassword, newPassword)).rejects.toThrow();
|
||||
})
|
||||
@@ -1,10 +0,0 @@
|
||||
// import Enzyme from "enzyme"
|
||||
// import Adapter from "enzyme-adapter-react-16"
|
||||
// import DotEnv from "dotenv"
|
||||
// import "babel-polyfill";
|
||||
|
||||
// Enzyme.configure({
|
||||
// adapter: new Adapter()
|
||||
// })
|
||||
|
||||
// DotEnv.config({path: ".env.test"})
|
||||
@@ -1,37 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
|
||||
|
||||
<title>myDrive</title>
|
||||
<link rel="icon" href="/images/icon.png">
|
||||
<link rel="shortcut icon" type="image/png" href="/images/icon.png">
|
||||
<link rel="shortcut icon" sizes="192x192" href="/images/icon.png">
|
||||
<link rel="apple-touch-icon" href="/images/icon.png">
|
||||
<link rel="stylesheet" type="text/css" href="./src/styles.css">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main-div">
|
||||
|
||||
<div id="box-div">
|
||||
|
||||
<p id="title">Enter Encryption Password</p>
|
||||
<form id="form-submit">
|
||||
<input id="input-password" type="password" placeholder="Password"/>
|
||||
<button id="submit-button">Submit</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- <script src="/socket.io/socket.io.js"></script> -->
|
||||
<script src="./dist/bundle.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,26 +0,0 @@
|
||||
import axios from "axios";
|
||||
|
||||
const formElement = document.getElementById("form-submit")
|
||||
const inputElement = document.getElementById("input-password");
|
||||
const mainDiv = document.getElementById("main-div")
|
||||
|
||||
formElement.addEventListener("submit", async (e) => {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
const port = process.env.PORT || "3000";
|
||||
const fullURL = `http://localhost:${port}`;
|
||||
|
||||
const value = inputElement.value;
|
||||
|
||||
const data = {password: value}
|
||||
|
||||
axios.post("/submit", data).then(() => {
|
||||
|
||||
inputElement.value = "";
|
||||
mainDiv.style.display = "none";
|
||||
|
||||
}).catch((err) => {
|
||||
console.log("Error", err);
|
||||
});
|
||||
})
|
||||
@@ -1,79 +0,0 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 62.5%;
|
||||
}
|
||||
|
||||
#main-div {
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
/* background: blue; */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
#box-div {
|
||||
height: 30%;
|
||||
width: 90%;
|
||||
/* background: purple; */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
border: .5px;
|
||||
border-style: groove;
|
||||
}
|
||||
|
||||
@media (min-width:600px) {
|
||||
#box-div {
|
||||
|
||||
height: 30%;
|
||||
width: 400px;
|
||||
/* background: purple; */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
border: .5px;
|
||||
border-style: groove;
|
||||
}
|
||||
}
|
||||
|
||||
#input-password {
|
||||
border: 1px solid #cacccd;
|
||||
border-radius: 2px;
|
||||
height: 43px;
|
||||
font-size: 1.8rem;
|
||||
font-weight: 300;
|
||||
padding: 1.2rem;
|
||||
margin: 0 0 1.2rem 0;
|
||||
width: -webkit-fill-available;
|
||||
margin-top: -17px;
|
||||
}
|
||||
|
||||
#submit-button {
|
||||
color: #fff;
|
||||
background: #3c85ed;
|
||||
font-size: 1.8rem;
|
||||
padding: 1.2rem;
|
||||
border: none;
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
line-height: 1;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
#title {
|
||||
margin: 0 0 3rem 0;
|
||||
line-height: 1;
|
||||
font-family: Arial,Helvetica,sans-serif;
|
||||
font-weight: 500;
|
||||
color: #666;
|
||||
font-size: 2em;
|
||||
margin-top: 24px;
|
||||
}
|
||||
@@ -1,296 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
|
||||
|
||||
<title>myDrive</title>
|
||||
<link rel="icon" href="/images/icon.png">
|
||||
<link rel="shortcut icon" type="image/png" href="/images/icon.png">
|
||||
<link rel="shortcut icon" sizes="192x192" href="/images/icon.png">
|
||||
<link rel="apple-touch-icon" href="/images/icon.png">
|
||||
<link rel="stylesheet" type="text/css" href="./src/styles.css">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main-div">
|
||||
|
||||
<div id="box-div">
|
||||
|
||||
<div>
|
||||
<p id="title">Setup</p>
|
||||
</div>
|
||||
|
||||
<div class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Use Docker With myDrive?</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<select id="docker-select" name="docker" class="docker-select">
|
||||
<option value="no">No</option>
|
||||
<option value="yes">Yes</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="docker-hidden" class="docker-hidden">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Include MongoDB In The Docker Image? (Select No If You're Using MongoDB Atlas)</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<select id="docker-select-mongoURL" name="docker" class="docker-select">
|
||||
<option value="yes">Yes</option>
|
||||
<option value="no">No</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="docker-hidden-mongoURL" class="docker-hidden">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter MongoDB URL</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="mongoURL-input-docker" class="mongo-input" placeholder="MongoDB URL"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="mongoURL-wrapper" class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter MongoDB URL</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="mongoURL-input" class="mongo-input" placeholder="MongoDB URL"/>
|
||||
</form>
|
||||
</div>
|
||||
<div class="button-wrapper-mongo">
|
||||
<button id="mongo-default-button" class="button-mongo">Use Local URL</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Use WebUI For Encryption Key (Recommended, Selecting No Will Require You To Enter An Encryption Key Now, Which Is Less Secure)</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<select id="encryption-select" name="encryption-key" class="docker-select">
|
||||
<option value="yes">Yes</option>
|
||||
<option value="no">No</option>
|
||||
</select>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="encryption-input" class="encryption-key-input" placeholder="Encryption Key" disabled type="password"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="section-wrapper-ports" class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Use default ports? (http port: 3000, https port: 8080</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<select id="port-select" name="port" class="docker-select">
|
||||
<option value="yes">Yes</option>
|
||||
<option value="no">No</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="ports-wrapper" class="docker-hidden">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter ports</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="http-port-input" class="mongo-input" placeholder="HTTP port"/>
|
||||
<input id="https-port-input" class="mongo-input" placeholder="HTTPS port"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter The Client URL/IP Address (Must Be A Valid Link and Must Start With "http://" or "https://", Include Port With IP Address If Needed, Do Not End The URL In a Slash "/")</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="client-input" class="mongo-input" placeholder="Client URL"/>
|
||||
</form>
|
||||
</div>
|
||||
<p id="client-input-invalid-text" class="invalid-input-text-hidden">Error: URL Cannot End In a Slash ("/")</p>
|
||||
<p id="client-input-invalid-text2" class="invalid-input-text-hidden">Error: URL Must Start With "http://" or "https://"</p>
|
||||
</div>
|
||||
|
||||
<div class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Pick A Database To Store File Chunks</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<select id="db-select" name="docker" class="docker-select">
|
||||
<option value="fs">FileSystem</option>
|
||||
<option value="s3">Amazon S3</option>
|
||||
<option value="mongo">MongoDB (Not Recommended)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="filesystem-wrapper" class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter The FileSyem Path</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="fs-input" class="mongo-input" placeholder="Path"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="s3-wrapper" class="docker-hidden">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter The S3 ID</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="db-form">
|
||||
<input id="s3-id-input" class="mongo-input" placeholder="S3 ID"/>
|
||||
</form>
|
||||
</div>
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter The S3 Key</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="db-form">
|
||||
<input id="s3-key-input" class="mongo-input" placeholder="S3 Key" type="password"/>
|
||||
</form>
|
||||
</div>
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter The S3 Bucket</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="db-form">
|
||||
<input id="s3-bucket-input" class="mongo-input" placeholder="S3 Bucket"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <div id="filesystem-wrapper" class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter JWT Secret</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="jwt-input" class="mongo-input" placeholder="JWT Secret" type="password"/>
|
||||
</form>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div id="filesystem-wrapper" class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter Access Token Secret</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="access-token-input" class="mongo-input" placeholder="Access Token Secret" type="password"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="filesystem-wrapper" class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter Refresh Token Secret</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="refresh-token-input" class="mongo-input" placeholder="Refresh Token Secret" type="password"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="filesystem-wrapper" class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter Cookie Secret</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="cookie-input" class="mongo-input" placeholder="Cookie Secret" type="password"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="ssl-select-wrapper" class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Use Secure Cookies? (You Can Only Use Secure Cookies If You Are Using HTTPS/SSL, Do Not Select This Option If You Do Not Have HTTPS or else Cookies/Logging in Will Not Work At All. This is Highly Recommended if You Have HTTPS/SSL)</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<select id="secure-cookie-select" name="secure-cookie" class="docker-select">
|
||||
<option value="no">No</option>
|
||||
<option value="yes">Yes</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Use SendGrid To Send Emails? (For Account Email Verification And Password Resets)</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<select id="sendgrid-select" name="sendgrid" class="docker-select">
|
||||
<option value="no">No</option>
|
||||
<option value="yes">Yes</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="sendgrid-wrapper" class="docker-hidden">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter A SendGrid API Key</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="sendgrid-input" class="mongo-input" placeholder="Sendgrid API Key" type="password"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="sendgrid-wrapper2" class="docker-hidden">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Enter Email Address, This Will Be The Email Address For Sending Email Verifications, And Password Resets.</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<form id="mongo-form">
|
||||
<input id="sendgrid-input-email" class="mongo-input" placeholder="Sendgrid Email"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="ssl-select-wrapper" class="section-wrapper">
|
||||
<div id="docker-text__wrapper">
|
||||
<p id="docker-text">Use SSL? (Will Require SSL Certificate certificate.crt, certificate.ca-bundle, And certificate.key At Root Of The Project. If You Are Hosting On a Service That Already Provides HTTPS/SSL Select No)</p>
|
||||
</div>
|
||||
<div id="docker-select__wrapper">
|
||||
<select id="ssl-select" name="docker" class="docker-select">
|
||||
<option value="no">No</option>
|
||||
<option value="yes">Yes</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="button-wrapper">
|
||||
<button id="save-button" class="button">Save</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- <script src="/socket.io/socket.io.js"></script> -->
|
||||
<script src="./dist/bundle.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,247 +0,0 @@
|
||||
import Swal from "sweetalert2";
|
||||
import axios from "axios";
|
||||
|
||||
const dockerSelection = document.getElementById("docker-select");
|
||||
const dockerHidden = document.getElementById("docker-hidden")
|
||||
const dockerSelectionMongoURL = document.getElementById("docker-select-mongoURL")
|
||||
const dockerHiddenMongoURL = document.getElementById("docker-hidden-mongoURL")
|
||||
const mainMongoURLWrapper = document.getElementById("mongoURL-wrapper")
|
||||
const encryptionSelect = document.getElementById("encryption-select");
|
||||
const encryptionInput = document.getElementById("encryption-input")
|
||||
const dbSelect = document.getElementById("db-select")
|
||||
const fsWrapper = document.getElementById("filesystem-wrapper");
|
||||
const s3Wrapper = document.getElementById("s3-wrapper");
|
||||
const saveButton = document.getElementById("save-button")
|
||||
const clientInput = document.getElementById("client-input")
|
||||
const mongoURLInput = document.getElementById("mongoURL-input");
|
||||
const mongoURLInputDocker = document.getElementById("mongoURL-input-docker");
|
||||
const s3IDInput = document.getElementById("s3-id-input");
|
||||
const s3KeyInput = document.getElementById("s3-key-input");
|
||||
const s3BucketInput = document.getElementById("s3-bucket-input");
|
||||
const fsInput = document.getElementById("fs-input");
|
||||
const SSLSelect = document.getElementById("ssl-select");
|
||||
const sendGridInput = document.getElementById("sendgrid-input");
|
||||
const sendGridInputEmail = document.getElementById("sendgrid-input-email");
|
||||
// const stripeEmailWrapper = document.getElementById('stripe-wrapper-email');
|
||||
const sendGridSelect = document.getElementById("sendgrid-select")
|
||||
const sendGridWrapper = document.getElementById("sendgrid-wrapper");
|
||||
const sendGridWrapper2 = document.getElementById("sendgrid-wrapper2");
|
||||
const clientInvalidInputText = document.getElementById("client-input-invalid-text");
|
||||
const clientInvalidInputText2 = document.getElementById("client-input-invalid-text2");
|
||||
|
||||
const accessTokenInput = document.getElementById("access-token-input");
|
||||
const refreshTokenInput = document.getElementById("refresh-token-input")
|
||||
const cookieInput = document.getElementById("cookie-input");
|
||||
const secureCookieSelect = document.getElementById("secure-cookie-select");
|
||||
const mongoDefaultButton = document.getElementById("mongo-default-button");
|
||||
const portsSelect = document.getElementById("port-select");
|
||||
const httpPortInput = document.getElementById("http-port-input");
|
||||
const httpsPortInput = document.getElementById("https-port-input");
|
||||
const portsWrappers = document.getElementById("ports-wrapper");
|
||||
const customPortsWrapper = document.getElementById("section-wrapper-ports");
|
||||
//const stripeInputEmail = document.getElementById('stripe-input-email');
|
||||
|
||||
dockerSelection.addEventListener("change", (e) => {
|
||||
|
||||
const docker = dockerSelection.value === "yes";
|
||||
|
||||
if (docker) {
|
||||
dockerHidden.className = "section-wrapper"
|
||||
mainMongoURLWrapper.className = "docker-hidden";
|
||||
customPortsWrapper.className = "docker-hidden"
|
||||
portsWrappers.className = "docker-hidden";
|
||||
} else {
|
||||
dockerHidden.className = "docker-hidden"
|
||||
mainMongoURLWrapper.className = "section-wrapper"
|
||||
dockerHiddenMongoURL.className = "docker-hidden"
|
||||
customPortsWrapper.className = "section-wrapper";
|
||||
}
|
||||
})
|
||||
|
||||
dockerSelectionMongoURL.addEventListener("change", () => {
|
||||
|
||||
const includeMongoDB = dockerSelectionMongoURL.value === "yes";
|
||||
|
||||
if (!includeMongoDB) {
|
||||
dockerHiddenMongoURL.className = "section-wrapper"
|
||||
} else {
|
||||
dockerHiddenMongoURL.className = "docker-hidden"
|
||||
}
|
||||
})
|
||||
|
||||
encryptionSelect.addEventListener("change", () => {
|
||||
|
||||
const useWebUIForEncryption = encryptionSelect.value === "yes";
|
||||
|
||||
if (!useWebUIForEncryption) {
|
||||
encryptionInput.disabled = false;
|
||||
encryptionInput.className = "mongo-input"
|
||||
} else {
|
||||
encryptionInput.disabled = true;
|
||||
encryptionInput.className = "encryption-key-input"
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
dbSelect.addEventListener("change", () => {
|
||||
|
||||
console.log("db select on change")
|
||||
|
||||
const storageType = dbSelect.value;
|
||||
|
||||
if (storageType === "s3") {
|
||||
|
||||
s3Wrapper.className = "section-wrapper"
|
||||
fsWrapper.className = "docker-hidden";
|
||||
|
||||
} else if (storageType === "fs") {
|
||||
|
||||
s3Wrapper.className = "docker-hidden";
|
||||
fsWrapper.className = "section-wrapper";
|
||||
|
||||
} else {
|
||||
|
||||
s3Wrapper.className = "docker-hidden";
|
||||
fsWrapper.className = "docker-hidden";
|
||||
}
|
||||
})
|
||||
|
||||
sendGridSelect.addEventListener("change", () => {
|
||||
|
||||
//section-wrapper
|
||||
|
||||
const sendGridEnabled = sendGridSelect.value === "yes";
|
||||
|
||||
if (sendGridEnabled) {
|
||||
|
||||
sendGridWrapper.className = 'section-wrapper'
|
||||
sendGridWrapper2.className = 'section-wrapper'
|
||||
|
||||
} else {
|
||||
|
||||
sendGridWrapper.classList = "docker-hidden";
|
||||
sendGridWrapper2.classList = "docker-hidden";
|
||||
}
|
||||
})
|
||||
|
||||
clientInput.addEventListener("input", () => {
|
||||
|
||||
const value = clientInput.value;
|
||||
|
||||
if (value && value.length !== 0) {
|
||||
|
||||
const lastCharacter = value[value.length - 1];
|
||||
|
||||
if (lastCharacter === "/") {
|
||||
|
||||
clientInput.className = "mongo-input input-invalid"
|
||||
clientInvalidInputText.className = "invalid-input-text"
|
||||
|
||||
} else {
|
||||
|
||||
clientInput.className = "mongo-input";
|
||||
clientInvalidInputText.className = "invalid-input-text-hidden"
|
||||
}
|
||||
|
||||
} else {
|
||||
clientInput.className = "mongo-input"
|
||||
clientInvalidInputText.className = "invalid-input-text-hidden"
|
||||
}
|
||||
|
||||
if (value && value.length >= 8 || value && value.length >= 7) {
|
||||
|
||||
const firstChactersHttp = value.substring(0, 7);
|
||||
const firstChactersHttps = value.substring(0, 8);
|
||||
|
||||
if (firstChactersHttps !== "https://" && firstChactersHttp !== "http://") {
|
||||
clientInput.className = "mongo-input input-invalid"
|
||||
clientInvalidInputText2.className = "invalid-input-text"
|
||||
} else {
|
||||
clientInvalidInputText2.className = "invalid-input-text-hidden"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
mongoDefaultButton.addEventListener("click", () => {
|
||||
|
||||
mongoURLInput.value = "mongodb://localhost:27017/mydrive-db"
|
||||
})
|
||||
|
||||
portsSelect.addEventListener("change", () => {
|
||||
|
||||
const value = portsSelect.value === "no";
|
||||
|
||||
if (value) {
|
||||
portsWrappers.className = "section-wrapper"
|
||||
} else {
|
||||
portsWrappers.className = "docker-hidden";
|
||||
}
|
||||
})
|
||||
|
||||
saveButton.addEventListener("click", () => {
|
||||
|
||||
let clientObj = {}
|
||||
let serverObj = {}
|
||||
|
||||
// Client
|
||||
clientObj.REMOTE_URL = clientInput.value;
|
||||
clientObj.DISABLE_STORAGE = true;
|
||||
//if (dbSelect.value !== "fs") clientObj.DISABLE_STORAGE = true;
|
||||
|
||||
// Server
|
||||
|
||||
portsSelect.value === "no" ? serverObj.HTTP_PORT = httpPortInput.value : serverObj.HTTP_PORT = 3000;
|
||||
portsSelect.value === "no" ? serverObj.HTTPS_PORT = httpsPortInput.value : serverObj.HTTPS_PORT = 8080;
|
||||
if (dockerSelection.value === "yes") serverObj.HTTP_PORT = 3000;
|
||||
if (dockerSelection.value === "yes") serverObj.HTTPS_PORT = 8080;
|
||||
serverObj.NODE_ENV = "production";
|
||||
serverObj.MONGODB_URL = dockerSelection.value !== "yes" ? mongoURLInput.value :
|
||||
dockerSelectionMongoURL.value !== "yes" ? mongoURLInputDocker.value : "mongodb://mongo:27017/mydrive"
|
||||
if (encryptionSelect.value !== "yes") serverObj.KEY = encryptionInput.value;
|
||||
if (dockerSelection.value === "yes") serverObj.DOCKER = true;
|
||||
if (SSLSelect.value === "yes") serverObj.SSL = true;
|
||||
if (secureCookieSelect.value === "yes") serverObj.SECURE_COOKIES = true;
|
||||
if (sendGridSelect.value === "no") serverObj.DISABLE_EMAIL_VERIFICATION = true;
|
||||
if (sendGridSelect.value === "yes") serverObj.SENDGRID_KEY = sendGridInput.value;
|
||||
if (sendGridSelect.value === "yes") serverObj.SENDGRID_EMAIL = sendGridInputEmail.value
|
||||
serverObj.DB_TYPE = dbSelect.value;
|
||||
serverObj.REMOTE_URL = clientInput.value;
|
||||
serverObj.PASSWORD_ACCESS = accessTokenInput.value;
|
||||
serverObj.PASSWORD_REFRESH = refreshTokenInput.value;
|
||||
serverObj.PASSWORD_COOKIE = cookieInput.value;
|
||||
|
||||
if (dbSelect.value === "s3") {
|
||||
|
||||
serverObj.S3_ID = s3IDInput.value;
|
||||
serverObj.S3_KEY = s3KeyInput.value;
|
||||
serverObj.S3_BUCKET = s3BucketInput.value;
|
||||
|
||||
} else if (dbSelect.value === "fs") {
|
||||
|
||||
serverObj.FS_DIRECTORY = fsInput.value;
|
||||
serverObj.ROOT = fsInput.value;
|
||||
}
|
||||
|
||||
const data = {
|
||||
clientObj,
|
||||
serverObj
|
||||
}
|
||||
|
||||
axios.post("/submit", data).then((result) => {
|
||||
console.log("Submitted");
|
||||
|
||||
Swal.fire(
|
||||
'Environment Variables Created',
|
||||
'The Environment Variables were successfully created.',
|
||||
'success'
|
||||
)
|
||||
|
||||
}).catch((err) => {
|
||||
console.log("Axios Err", err);
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Error',
|
||||
text: 'Error Creating Enviroment Variables, please check the logs.',
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,233 +0,0 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 62.5%;
|
||||
}
|
||||
|
||||
#main-div {
|
||||
/* height: 100vh;
|
||||
width: 100vw; */
|
||||
/* background: blue; */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
#box-div {
|
||||
height: 30%;
|
||||
width: 90%;
|
||||
/* background: purple; */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
border: .5px;
|
||||
border-style: groove;
|
||||
}
|
||||
|
||||
@media (min-width:600px) {
|
||||
#box-div {
|
||||
width: 70%;
|
||||
/* background: purple; */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: space-around;
|
||||
border: .5px;
|
||||
border-style: groove;
|
||||
border-radius: 11px;
|
||||
height: fit-content;
|
||||
}
|
||||
}
|
||||
|
||||
#input-password {
|
||||
border: 1px solid #cacccd;
|
||||
border-radius: 2px;
|
||||
height: 43px;
|
||||
font-size: 1.8rem;
|
||||
font-weight: 300;
|
||||
padding: 1.2rem;
|
||||
margin: 0 0 1.2rem 0;
|
||||
width: -webkit-fill-available;
|
||||
margin-top: -17px;
|
||||
}
|
||||
|
||||
#submit-button {
|
||||
color: #fff;
|
||||
background: #3c85ed;
|
||||
font-size: 1.8rem;
|
||||
padding: 1.2rem;
|
||||
border: none;
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
line-height: 1;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
#title {
|
||||
font-size: 58px;
|
||||
font-family: sans-serif;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
#docker-text {
|
||||
color: #373737;
|
||||
/* margin-right: 2px; */
|
||||
/* margin-top: 25px; */
|
||||
/* margin-left: 4px; */
|
||||
/* text-overflow: ellipsis; */
|
||||
/* white-space: nowrap; */
|
||||
/* overflow: hidden; */
|
||||
/* width: 77%; */
|
||||
/* max-width: 50vw; */
|
||||
font-weight: 300;
|
||||
/* text-transform: capitalize; */
|
||||
font-size: 17px;
|
||||
text-align: center;
|
||||
max-width: 78%;
|
||||
}
|
||||
|
||||
.docker-select {
|
||||
background: none;
|
||||
border: none;
|
||||
-moz-appearance: none;
|
||||
-webkit-appearance: none;
|
||||
color: #5f6368;
|
||||
font-size: 18px;
|
||||
outline: none;
|
||||
font-weight: 500;
|
||||
padding-left: 3px;
|
||||
padding-right: 4px;
|
||||
margin-top: 19px;
|
||||
}
|
||||
|
||||
#docker-select__wrapper {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.mongo-input {
|
||||
border: 1px solid #f1f3f4;
|
||||
/* height: 50px; */
|
||||
font-size: 15px;
|
||||
font-weight: 300;
|
||||
/* padding: 7px; */
|
||||
/* margin: 10px 0 10px 0; */
|
||||
/* width: 100%; */
|
||||
/* margin: 3px; */
|
||||
height: 32px;
|
||||
padding-left: 8px;
|
||||
border-radius: 3px;
|
||||
background: #f1f3f4;
|
||||
width: 286px;
|
||||
}
|
||||
|
||||
.input-invalid {
|
||||
border: 1px solid red;
|
||||
outline: 1px solid red;
|
||||
}
|
||||
|
||||
.invalid-input-text {
|
||||
text-align: center;
|
||||
font-size: 17px;
|
||||
margin-top: 5px;
|
||||
color: red;
|
||||
}
|
||||
|
||||
.invalid-input-text-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.encryption-key-input {
|
||||
border: 1px solid #f1f3f4;
|
||||
/* height: 50px; */
|
||||
font-size: 15px;
|
||||
font-weight: 300;
|
||||
/* padding: 7px; */
|
||||
/* margin: 10px 0 10px 0; */
|
||||
/* width: 100%; */
|
||||
/* margin: 3px; */
|
||||
height: 32px;
|
||||
padding-left: 8px;
|
||||
border-radius: 3px;
|
||||
background: #f1f3f4;
|
||||
width: 286px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
#mongo-form {
|
||||
margin-top: 13px;
|
||||
}
|
||||
|
||||
#db-form {
|
||||
margin-top: 13px;
|
||||
margin-bottom: 13px;
|
||||
}
|
||||
|
||||
.section-wrapper {
|
||||
margin-top: 29px;
|
||||
width: 100%;
|
||||
border-bottom: 1px solid #dadce0;
|
||||
/* margin-bottom: -3px; */
|
||||
padding-bottom: 24px;
|
||||
}
|
||||
|
||||
#docker-text__wrapper {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.docker-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.button-wrapper {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 30px;
|
||||
}
|
||||
|
||||
.button-wrapper-mongo {
|
||||
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 30px;
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.button {
|
||||
color: #fff;
|
||||
background: #3c85ed;
|
||||
font-size: 1.8rem;
|
||||
padding: 1.2rem;
|
||||
border: none;
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
line-height: 1;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.button-mongo {
|
||||
color: #fff;
|
||||
background: #3c85ed;
|
||||
font-size: 16px;
|
||||
padding: 9px;
|
||||
border: none;
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
line-height: 1;
|
||||
border-radius: 2px;
|
||||
}
|
||||
Reference in New Issue
Block a user