forked from hibas123/SecureFileWrapper
Removing server encryption
This commit is contained in:
parent
ffd1bd09be
commit
0db2a025e0
2
index.d.ts
vendored
2
index.d.ts
vendored
@ -27,7 +27,7 @@ export default class SecureFile {
|
|||||||
test: true;
|
test: true;
|
||||||
}>;
|
}>;
|
||||||
list(folder?: string): Promise<File[]>;
|
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>;
|
get(id: string, version?: string): Promise<Buffer>;
|
||||||
update(id: string, data: Buffer, preview?: Buffer): Promise<File>;
|
update(id: string, data: Buffer, preview?: Buffer): Promise<File>;
|
||||||
delete(id: string): Promise<boolean>;
|
delete(id: string): Promise<boolean>;
|
||||||
|
10
index.js
10
index.js
@ -157,7 +157,7 @@ var SecureFile = /** @class */ (function () {
|
|||||||
return [4 /*yield*/, fetch(this.Server + endpoint + query_str, { method: method, body: body, headers: myHeaders })];
|
return [4 /*yield*/, fetch(this.Server + endpoint + query_str, { method: method, body: body, headers: myHeaders })];
|
||||||
case 7:
|
case 7:
|
||||||
res = _a.sent();
|
res = _a.sent();
|
||||||
if (res.status === 418) {
|
if (res.status === 418) { // JWT invalid
|
||||||
this.JWT = undefined;
|
this.JWT = undefined;
|
||||||
return [2 /*return*/, this.makeRequest(endpoint, method, query, body, jwt)];
|
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) {
|
SecureFile.prototype.create = function (name, data, type, folder, preview) {
|
||||||
if (encrypt === void 0) { encrypt = true; }
|
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
var params, res;
|
var params, res;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0:
|
case 0:
|
||||||
params = { type: type, name: name, no_encryption: !encrypt };
|
params = { type: type, name: name };
|
||||||
if (preview) {
|
if (preview) {
|
||||||
params.preview = preview;
|
params.preview = preview;
|
||||||
}
|
}
|
||||||
if (folder) {
|
if (folder) {
|
||||||
params.folder = folder;
|
params.folder = folder;
|
||||||
}
|
}
|
||||||
if (!encrypt) {
|
|
||||||
params.no_encryption = true;
|
|
||||||
}
|
|
||||||
return [4 /*yield*/, this.makeRequest("/files", "POST", params, data, this.jwt_enabled)];
|
return [4 /*yield*/, this.makeRequest("/files", "POST", params, data, this.jwt_enabled)];
|
||||||
case 1:
|
case 1:
|
||||||
res = _a.sent();
|
res = _a.sent();
|
||||||
|
7
index.ts
7
index.ts
@ -113,17 +113,14 @@ export default class SecureFile {
|
|||||||
return await res.json();
|
return await res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(name: string, data: Buffer, type: "text" | "binary", folder?: string, encrypt: boolean = true, preview?: Buffer): Promise<File> {
|
async create(name: string, data: Buffer, type: "text" | "binary", folder?: string, preview?: Buffer): Promise<File> {
|
||||||
let params: any = { type: type, name: name, no_encryption: !encrypt };
|
let params: any = { type: type, name: name };
|
||||||
if (preview) {
|
if (preview) {
|
||||||
params.preview = preview;
|
params.preview = preview;
|
||||||
}
|
}
|
||||||
if (folder) {
|
if (folder) {
|
||||||
params.folder = folder;
|
params.folder = folder;
|
||||||
}
|
}
|
||||||
if (!encrypt) {
|
|
||||||
params.no_encryption = true;
|
|
||||||
}
|
|
||||||
let res = await this.makeRequest("/files", "POST", params, data, this.jwt_enabled)
|
let res = await this.makeRequest("/files", "POST", params, data, this.jwt_enabled)
|
||||||
statusParser(res);
|
statusParser(res);
|
||||||
return res.json();
|
return res.json();
|
||||||
|
24
test.js
24
test.js
@ -56,7 +56,7 @@ function test(sf) {
|
|||||||
var res;
|
var res;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
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:
|
case 1:
|
||||||
res = _a.sent();
|
res = _a.sent();
|
||||||
chai_1.assert.ok(res, "Res is not set");
|
chai_1.assert.ok(res, "Res is not set");
|
||||||
@ -169,7 +169,7 @@ function test(sf) {
|
|||||||
var res;
|
var res;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
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:
|
case 1:
|
||||||
res = _a.sent();
|
res = _a.sent();
|
||||||
chai_1.assert.ok(res, "Res not set");
|
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");
|
private_key = fs_1.readFileSync("./private.pem").toString("utf8");
|
||||||
describe("SecureFile Tests (request based auth)", function () {
|
describe("SecureFile Tests (request based auth)", function () {
|
||||||
|
25
test.ts
25
test.ts
@ -22,7 +22,7 @@ function test(sf: SecureFile) {
|
|||||||
let testver2: string;
|
let testver2: string;
|
||||||
|
|
||||||
it("create", async () => {
|
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, "Res is not set");
|
||||||
assert.ok(res._id, "Res has not _id");
|
assert.ok(res._id, "Res has not _id");
|
||||||
testid = res._id;
|
testid = res._id;
|
||||||
@ -84,7 +84,7 @@ function test(sf: SecureFile) {
|
|||||||
|
|
||||||
describe("folder", () => {
|
describe("folder", () => {
|
||||||
it("create", async () => {
|
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, "Res not set");
|
||||||
assert.ok(res._id, "No _id field");
|
assert.ok(res._id, "No _id field");
|
||||||
ftestid = res._id;
|
ftestid = res._id;
|
||||||
@ -110,27 +110,6 @@ function test(sf: SecureFile) {
|
|||||||
assert.ok(res, "Res not set");
|
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");
|
private_key = readFileSync("./private.pem").toString("utf8");
|
||||||
|
Loading…
Reference in New Issue
Block a user