Removing server encryption

This commit is contained in:
Fabian Stamm 2018-06-14 16:42:30 +02:00
parent ffd1bd09be
commit 0db2a025e0
6 changed files with 11 additions and 58 deletions

2
index.d.ts vendored
View File

@ -27,7 +27,7 @@ export default class SecureFile {
test: true;
}>;
list(folder?: string): Promise<File[]>;
create(name: string, data: Buffer, type: "text" | "binary", folder?: string, encrypt?: boolean, preview?: Buffer): Promise<File>;
create(name: string, data: Buffer, type: "text" | "binary", folder?: string, preview?: Buffer): Promise<File>;
get(id: string, version?: string): Promise<Buffer>;
update(id: string, data: Buffer, preview?: Buffer): Promise<File>;
delete(id: string): Promise<boolean>;

View File

@ -157,7 +157,7 @@ var SecureFile = /** @class */ (function () {
return [4 /*yield*/, fetch(this.Server + endpoint + query_str, { method: method, body: body, headers: myHeaders })];
case 7:
res = _a.sent();
if (res.status === 418) {
if (res.status === 418) { // JWT invalid
this.JWT = undefined;
return [2 /*return*/, this.makeRequest(endpoint, method, query, body, jwt)];
}
@ -206,23 +206,19 @@ var SecureFile = /** @class */ (function () {
});
});
};
SecureFile.prototype.create = function (name, data, type, folder, encrypt, preview) {
if (encrypt === void 0) { encrypt = true; }
SecureFile.prototype.create = function (name, data, type, folder, preview) {
return __awaiter(this, void 0, void 0, function () {
var params, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
params = { type: type, name: name, no_encryption: !encrypt };
params = { type: type, name: name };
if (preview) {
params.preview = preview;
}
if (folder) {
params.folder = folder;
}
if (!encrypt) {
params.no_encryption = true;
}
return [4 /*yield*/, this.makeRequest("/files", "POST", params, data, this.jwt_enabled)];
case 1:
res = _a.sent();

View File

@ -113,17 +113,14 @@ export default class SecureFile {
return await res.json();
}
async create(name: string, data: Buffer, type: "text" | "binary", folder?: string, encrypt: boolean = true, preview?: Buffer): Promise<File> {
let params: any = { type: type, name: name, no_encryption: !encrypt };
async create(name: string, data: Buffer, type: "text" | "binary", folder?: string, preview?: Buffer): Promise<File> {
let params: any = { type: type, name: name };
if (preview) {
params.preview = preview;
}
if (folder) {
params.folder = folder;
}
if (!encrypt) {
params.no_encryption = true;
}
let res = await this.makeRequest("/files", "POST", params, data, this.jwt_enabled)
statusParser(res);
return res.json();

1
test.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

24
test.js
View File

@ -56,7 +56,7 @@ function test(sf) {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, sf.create(testname, testdata, "text", undefined, false, testprev)];
case 0: return [4 /*yield*/, sf.create(testname, testdata, "text", undefined, testprev)];
case 1:
res = _a.sent();
chai_1.assert.ok(res, "Res is not set");
@ -169,7 +169,7 @@ function test(sf) {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, sf.create(testname, testdata, "text", testfolder, false, testprev)];
case 0: return [4 /*yield*/, sf.create(testname, testdata, "text", testfolder, testprev)];
case 1:
res = _a.sent();
chai_1.assert.ok(res, "Res not set");
@ -214,26 +214,6 @@ function test(sf) {
});
}); });
});
// describe("encryption", () => {
// it("create", async () => {
// let res = await sf.create(testname, testdata, "text", undefined, true, testprev)
// assert.ok(res, "Res not set");
// assert.ok(res._id, "_id not set");
// e_testid = res._id;
// testver = res.version;
// })
// it("get", async () => {
// let r = new rsa(private_key, "pkcs1-pem");
// let res = await sf.get(e_testid);
// res = r.decrypt(res);
// assert.ok(res, "Res not set");
// assert.equal(res.toString(), testdata.toString(), "Unexpected data change");
// })
// it("delete", async () => {
// let res = await sf.delete(e_testid);
// assert.ok(res, "Res not set");
// })
// })
}
private_key = fs_1.readFileSync("./private.pem").toString("utf8");
describe("SecureFile Tests (request based auth)", function () {

25
test.ts
View File

@ -22,7 +22,7 @@ function test(sf: SecureFile) {
let testver2: string;
it("create", async () => {
let res = await sf.create(testname, testdata, "text", undefined, false, testprev)
let res = await sf.create(testname, testdata, "text", undefined, testprev)
assert.ok(res, "Res is not set");
assert.ok(res._id, "Res has not _id");
testid = res._id;
@ -84,7 +84,7 @@ function test(sf: SecureFile) {
describe("folder", () => {
it("create", async () => {
let res = await sf.create(testname, testdata, "text", testfolder, false, testprev)
let res = await sf.create(testname, testdata, "text", testfolder, testprev)
assert.ok(res, "Res not set");
assert.ok(res._id, "No _id field");
ftestid = res._id;
@ -110,27 +110,6 @@ function test(sf: SecureFile) {
assert.ok(res, "Res not set");
});
})
// describe("encryption", () => {
// it("create", async () => {
// let res = await sf.create(testname, testdata, "text", undefined, true, testprev)
// assert.ok(res, "Res not set");
// assert.ok(res._id, "_id not set");
// e_testid = res._id;
// testver = res.version;
// })
// it("get", async () => {
// let r = new rsa(private_key, "pkcs1-pem");
// let res = await sf.get(e_testid);
// res = r.decrypt(res);
// assert.ok(res, "Res not set");
// assert.equal(res.toString(), testdata.toString(), "Unexpected data change");
// })
// it("delete", async () => {
// let res = await sf.delete(e_testid);
// assert.ok(res, "Res not set");
// })
// })
}
private_key = readFileSync("./private.pem").toString("utf8");