Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests. #21

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
data/*
!data/cc8/
docker-compose.override.yml
.idea

Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,5 @@ http.createServer((req, res) => {


}).listen(1234);

module.exports = server;
124 changes: 119 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"slug": "^0.9.1"
},
"devDependencies": {
"puppeteer": "^1.3.0"
"mocha": "^5.1.1",
"puppeteer": "^1.3.0",
"supertest": "^3.0.0"
},
"scripts": {
"test": "mocha"
Expand Down
7 changes: 4 additions & 3 deletions public/js/cipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ const encryptFiles = async ([files, hashKey]) => {
});
};

const decryptFile = async (file) => {
const decryptFile = async ([file, hashKey]) => {
const key = await window.crypto.subtle.importKey(
"jwk",
{
kty: "oct",
k: window.location.hash.slice(1),
k: hashKey,
alg: "A256GCM",
ext: true,
},
Expand All @@ -83,7 +83,8 @@ const decryptFile = async (file) => {
key,
data
);
resolve(window.URL.createObjectURL(new Blob([decryptedFileRaw])));
// resolve(window.URL.createObjectURL(new Blob([decryptedFileRaw])));
resolve(new Blob([decryptedFileRaw]));
}
reader.readAsArrayBuffer(file);
});
Expand Down
44 changes: 40 additions & 4 deletions public/js/dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
//TODO: avoid global variables...
let content = ''; //list of uploaded files.

/*#############################################################|
| TESTS
*##############################################################*/

const regressionTest = () => {
window.location.hash = '';
window.location.href = window.location.origin + '/dir/data/cc8/tluICx+fpoDNb+DsLMquWl+aai5sVg#NfF6mwHOSZire9yal1dlOMFn67RTD8tsL_mjlsPP_Is';
// Gian: we need the above reload for consecutive tests, since the page wont reload when the path doesn't change (only the hash is changing after the first test). We also need the delay since without it the reload happens before the url (with the new hash) is updated.
setTimeout(() => {
window.location.reload();
}, 500);
}

/*#############################################################|
| VALIDATION
Expand Down Expand Up @@ -41,6 +53,25 @@ if (window.location.protocol === 'http:') {

/* File download =========================================== */

const beforeDownload = blob => {
if (window.location.hash === '#NfF6mwHOSZire9yal1dlOMFn67RTD8tsL_mjlsPP_Is') {
return new Promise((resolve, reject) => {
let reader = new FileReader();
reader.onload = (e => {
if (e.target.result !== 'bar') {
throw new Error('Regression test failed.');
} else {
console.log('Success!');
}
resolve('#'); // this prevents page refresh on click
});
reader.readAsText(blob);
});
} else {
return window.URL.createObjectURL(blob);
}
}

const handleFileDownload = (e) => {

if (window.location.hash) {
Expand All @@ -50,7 +81,8 @@ const handleFileDownload = (e) => {
let fetchFilePath = function (filePath, filename) {
fetch(filePath)
.then(res => res.blob())
.then(blob => decryptFile(blob))
.then(blob => decryptFile([blob, window.location.hash.slice(1)]))
.then(beforeDownload)
.then(downloadLink => {
currentLink.setAttribute('href', downloadLink);
currentLink.setAttribute('download', filename);
Expand Down Expand Up @@ -84,7 +116,7 @@ const handleFileDownload = (e) => {
} else {
//TODO: better feedback?
let hashWarning = new Alert().showMessage("danger", "Error: no hash found.");
console.log('Error: no hash found.');
console.error('Error: no hash found.');
}
};

Expand Down Expand Up @@ -120,6 +152,10 @@ const addFilesDecrypt = () => {

}

/* Triggers regression test =========================================== */
if (window.location.hash === '#NfF6mwHOSZire9yal1dlOMFn67RTD8tsL_mjlsPP_Is') {
document.querySelector(".files-listing").firstElementChild.firstElementChild.children[1].click(); // trigger regression-control.txt
}
};


Expand Down Expand Up @@ -195,7 +231,7 @@ const listingFiles = () => {
.then(removeListItem(deleteItem, deleteItemName)) //remove item from file listing
.catch(error => {
let deleteError = new Alert().showMessage("danger", `Error while trying to delete your file: ${error}`);
console.log(error);
console.error(error);
});
}
});
Expand Down Expand Up @@ -463,4 +499,4 @@ shareLinkBtn.addEventListener('click', function (e) {

Display.copyLinkClipboard();

});
});
Loading