From 134b5b2dbd973b08708a46cbde9500a8dc35f2a6 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2019 14:07:32 +0000 Subject: [PATCH 1/5] Bump @types/node from 12.11.7 to 12.12.0 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 12.11.7 to 12.12.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Signed-off-by: dependabot-preview[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index ac64cad..4eb36a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -497,9 +497,9 @@ "dev": true }, "@types/node": { - "version": "12.11.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.11.7.tgz", - "integrity": "sha512-JNbGaHFCLwgHn/iCckiGSOZ1XYHsKFwREtzPwSGCVld1SGhOlmZw2D4ZI94HQCrBHbADzW9m4LER/8olJTRGHA==", + "version": "12.12.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.0.tgz", + "integrity": "sha512-6N8Sa5AaENRtJnpKXZgvc119PKxT1Lk9VPy4kfT8JF23tIe1qDfaGkBR2DRKJFIA7NptMz+fps//C6aLi1Uoug==", "dev": true }, "@types/rimraf": { From f94f842849654f188fecfeddc6ce90438890efb3 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2019 14:08:17 +0000 Subject: [PATCH 2/5] Bump @types/jest from 24.0.20 to 24.0.21 Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 24.0.20 to 24.0.21. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest) Signed-off-by: dependabot-preview[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index ac64cad..48c0829 100644 --- a/package-lock.json +++ b/package-lock.json @@ -470,9 +470,9 @@ } }, "@types/jest": { - "version": "24.0.20", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.20.tgz", - "integrity": "sha512-M8ebEkOpykGdLoRrmew7UowTZ1DANeeP0HiSIChl/4DGgmnSC1ntitNtkyNSXjMTsZvXuaxJrxjImEnRWNPsPw==", + "version": "24.0.21", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.21.tgz", + "integrity": "sha512-uyqFvx78Tuy0h5iLCPWRCvi5HhWwEqhIj30doitp191oYLqlCxUyAJHdWVm5+Nr271/vPnkyt6rWeEIjGowBTg==", "dev": true, "requires": { "@types/jest-diff": "*" From 3172ca022e064743ba40c8b32ffc39cc142851d2 Mon Sep 17 00:00:00 2001 From: oganexon Date: Sat, 2 Nov 2019 17:36:07 +0100 Subject: [PATCH 3/5] changed secure standard + fix unhandled promises --- .github/FUNDING.yml | 12 +++++++ .github/workflows/npmpublish.yml | 2 +- CHANGELOG.md | 10 +++++- src/rmdir.ts | 55 +++++++++++++++++++------------- src/secure-rm.ts | 4 +-- src/standards.ts | 4 +-- src/unlink.ts | 21 ++++++------ 7 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..cc177ab --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: [secure-rm, oganexon] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: secure_rm # Replace with a single Patreon username +# open_collective: # Replace with a single Open Collective username +# ko_fi: # Replace with a single Ko-fi username +# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +# liberapay: # Replace with a single Liberapay username +# issuehunt: # Replace with a single IssueHunt username +# otechie: # Replace with a single Otechie username +# custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/workflows/npmpublish.yml b/.github/workflows/npmpublish.yml index c7d5054..b6eceae 100644 --- a/.github/workflows/npmpublish.yml +++ b/.github/workflows/npmpublish.yml @@ -39,7 +39,7 @@ jobs: with: node-version: 12 registry-url: https://npm.pkg.github.com/ - scope: '@your-github-username' + scope: '@secure-rm' - run: npm ci - run: npm publish env: diff --git a/CHANGELOG.md b/CHANGELOG.md index da96151..3261847 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Security --> - +## [Unreleased] + +### Changed + +- `secure` standard now also rename folders. + +### Fixed + +- Unhandled errors. ## [4.1.0] - 2019-10-29 diff --git a/src/rmdir.ts b/src/rmdir.ts index 791c8f8..3e2a3b3 100644 --- a/src/rmdir.ts +++ b/src/rmdir.ts @@ -6,16 +6,11 @@ import { eventEmitter, eventError, tree } from './events' type StepFunction = (p: string, uuid: string) => Promise -interface FakeLogError { - (message?: string | undefined): Error - code: string -} - export default class RmDir { private steps: Array compile: (uuid: string) => typeof fs.rmdir - constructor () { + constructor() { this.steps = [] this.compile = (uuid) => { tree[uuid] = [] @@ -27,16 +22,20 @@ export default class RmDir { } this.steps.reduce((prev: Promise, next: StepFunction) => { return prev.then((p) => next(p, uuid)) - /* .catch((err: NodeJS.ErrnoException) => { - eventError(err, p as string) - callback!(err) - return Promise.reject(err) - }) */ + .catch((err: NodeJS.ErrnoException) => { + if (err.message !== 'handledPromise') { + eventError(err, p as string) + callback!(err) + } + return Promise.reject(new Error('handledPromise')) + }) }, this.init(p as string)) .then(() => callback!(null)) .catch((err: NodeJS.ErrnoException) => { - eventError(err, p as string) - callback!(err) + if (err.message !== 'handledPromise') { + eventError(err, p as string) + callback!(err) + } }) }, { __promisify__: util.promisify(fs.rmdir) } // FIXME @@ -44,19 +43,19 @@ export default class RmDir { } } - private init (p: string): Promise { + private init(p: string): Promise { return new Promise((resolve) => { eventEmitter.emit('start', p) resolve(p) }) } - then (fun: StepFunction) { + then(fun: StepFunction) { this.steps.push(fun) return this } - log () { + log() { this.steps.push( function (p: string, uuid: string) { return new Promise((resolve, reject) => { @@ -76,16 +75,26 @@ export default class RmDir { } // Rename to random string - rename () { + rename() { this.steps.push( function (p: string) { return new Promise((resolve, reject) => { - const newName = crypto.randomBytes(9).toString('base64').replace(/\//g, '0').replace(/\+/g, 'a') - const newPath = path.join(path.dirname(p), newName) - eventEmitter.emit('verbose', p, `Renaming to ${newName} `) - fs.rename(p, newPath, (err) => { + fs.readdir(p, (err, files) => { if (err) reject(err) - else resolve(newPath) + if (!files.length) { + // directory appears to be empty + const newName = crypto.randomBytes(9).toString('base64').replace(/\//g, '0').replace(/\+/g, 'a') + const newPath = path.join(path.dirname(p), newName) + eventEmitter.emit('verbose', p, `Renaming to ${newName} `) + fs.rename(p, newPath, (err) => { + if (err) reject(err) + else resolve(newPath) + }) + } else { + fs.rmdir(p, (err) => { + reject(err) + }) + } }) }) }) @@ -93,7 +102,7 @@ export default class RmDir { } // End function: remove the directory - rmdir () { + rmdir() { this.steps.push( function (p: string) { return new Promise((resolve, reject) => { diff --git a/src/secure-rm.ts b/src/secure-rm.ts index bfa1991..c9d01f2 100644 --- a/src/secure-rm.ts +++ b/src/secure-rm.ts @@ -18,7 +18,7 @@ interface Opts { } export interface Options extends Opts { - standard?: string + standard?: keyof typeof standards } export interface ParsedOptions extends Opts { @@ -47,8 +47,6 @@ export function remove (path: string, options?: Options | Callback, callback?: C else return removePromise(path, options as ParsedOptions, uuid) } -// (module).exports = secureRm - const defaultGlobOpts = { nosort: true, silent: true diff --git a/src/standards.ts b/src/standards.ts index 1151bb8..164c7e8 100644 --- a/src/standards.ts +++ b/src/standards.ts @@ -89,10 +89,10 @@ Pass 3: Truncating between 25% and 75% of the file.`, .random() .rename() .truncate() - .unlink()/* , + .unlink(), rmdirStandard: new RmDir() .rename() - .rmdir() */ + .rmdir() }), 'GOST_R50739-95': new Standard({ diff --git a/src/unlink.ts b/src/unlink.ts index 1057f85..8b36550 100644 --- a/src/unlink.ts +++ b/src/unlink.ts @@ -18,9 +18,6 @@ interface ForInterface { type StepFunction = (file: string, fileSize: number, uuid: string) => Promise -// Function to offset an array -// const offset = (arr: number[], offset: number) => [...arr.slice(offset), ...arr.slice(0, offset)] - export default class Unlink { private steps: Array compile: (token: string) => typeof fs.unlink @@ -33,16 +30,20 @@ export default class Unlink { (file: fs.PathLike, callback: (err: NodeJS.ErrnoException | null) => void) => { this.steps.reduce((prev: Promise, next: StepFunction) => { return prev.then(({ file, fileSize }) => next(file, fileSize, uuid)) - /* .catch((err: NodeJS.ErrnoException) => { - eventError(err, file as string) - callback(err) - return Promise.reject(err) - }) */ + .catch((err: NodeJS.ErrnoException) => { + if (err.message !== 'handledPromise') { + eventError(err, file as string) + callback(err) + } + return Promise.reject(new Error('handledPromise')) + }) }, this.init(file as string)) .then(() => callback(null)) .catch((err: NodeJS.ErrnoException) => { - eventError(err, file as string) - callback(err) + if (err.message !== 'handledPromise') { + eventError(err, file as string) + callback(err) + } }) }, { __promisify__: util.promisify(fs.unlink) } // FIXME From 788af20477f68d1da56e64c37764bb4755c4825b Mon Sep 17 00:00:00 2001 From: oganexon Date: Sat, 2 Nov 2019 19:18:06 +0100 Subject: [PATCH 4/5] changelog + doc --- CHANGELOG.md | 4 +++- README.md | 10 ++++++---- test/secure-rm.test.js | 2 ++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3261847..e5e5217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Security --> -## [Unreleased] + + +## [4.2.0] - 2019-11-02 ### Changed diff --git a/README.md b/README.md index 8689261..f3f8a90 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,12 @@ srm('./folder/*.js') [Visit the wiki](https://github.com/secure-rm/core/wiki) to discover all the possibilities secure-rm offers! -- Choose a standard, -- Customize your standard, -- Respond to events, -- etc. +- 📚 [Choose a standard](https://github.com/secure-rm/core/wiki/Standards) +- ⚙️ [Customize your standard](https://github.com/secure-rm/core/wiki/Custom-Standard) +- 📗 [Unlink Methods](https://github.com/secure-rm/core/wiki/Unlink-Methods) +- 📙 [RmDir Methods](https://github.com/secure-rm/core/wiki/RmDir-Methods) +- ✨ [Respond to events](https://github.com/secure-rm/core/wiki/Events) +- 🚩 [Troubleshooting - Common issues](https://github.com/secure-rm/core/wiki/Troubleshooting---Common-issues) ### Examples: ```javascript diff --git a/test/secure-rm.test.js b/test/secure-rm.test.js index 4d3176f..6f94cee 100644 --- a/test/secure-rm.test.js +++ b/test/secure-rm.test.js @@ -3,6 +3,8 @@ const srm = require('..') const { tools } = require('./tools.js')(__dirname, __filename) +test.todo('Predictable errors') + describe('Invalid IDs throw:', () => { const values = [-1, '1', 10e5, 'string', 'SECURE', ['secure']] for (let i = 0; i < values.length; i++) { From 7355f470a5db7fb2e0863607cc523611f98ec96d Mon Sep 17 00:00:00 2001 From: oganexon Date: Sat, 2 Nov 2019 19:18:18 +0100 Subject: [PATCH 5/5] 4.2.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index e8e5cf4..ad48ac2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "secure-rm", - "version": "4.1.0", + "version": "4.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3c107ff..a24c1a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "secure-rm", - "version": "4.1.0", + "version": "4.2.0", "description": "Completely erases files by making recovery impossible.", "main": "./dist/index.js", "types": "./dist/index.d.ts",