From 70eb273581e8962ba1555735f6f041b5ee570b03 Mon Sep 17 00:00:00 2001 From: Lutfa Ibtihaji Ilham Date: Tue, 10 Jan 2023 19:31:09 +0700 Subject: [PATCH 1/4] CI: add node v18.x & disable curl cache --- .github/workflows/ci.yml | 76 ++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36a9806..e55b93d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - node-version: [14.x, 15.x, 16.x] + node-version: [14.x, 16.x, 18.x] steps: - uses: actions/checkout@v2 @@ -37,43 +37,43 @@ jobs: - name: Get sample files run: |- mkdir tmp \ - && curl -sLko tmp/sample-0.mp3 https://filesamples.com/samples/audio/mp3/sample3.mp3 \ - && curl -sLko tmp/sample-0.wav https://freewavesamples.com/files/Ensoniq-ZR-76-01-Dope-77.wav \ - && curl -sLko tmp/sample-0.ogg https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg \ - && curl -sLko tmp/sample-0.doc https://filesamples.com/samples/document/doc/sample1.doc \ - && curl -sLko tmp/sample-0.docx https://filesamples.com/samples/document/docx/sample3.docx \ - && curl -sLko tmp/sample-0.xls https://filesamples.com/samples/document/xls/sample1.xls \ - && curl -sLko tmp/sample-0.xlsx https://filesamples.com/samples/document/xlsx/sample1.xlsx \ - && curl -sLko tmp/sample-0.ppt https://filesamples.com/samples/document/ppt/sample2.ppt \ - && curl -sLko tmp/sample-0.odt https://filesamples.com/samples/document/odt/sample1.odt \ - && curl -sLko tmp/sample-0.pdf https://filesamples.com/samples/document/pdf/sample2.pdf \ - && curl -sLko tmp/sample-0.rtf https://filesamples.com/samples/document/rtf/sample3.rtf \ - && curl -sLko tmp/sample-0.mpg https://filesamples.com/samples/video/mpg/sample_640x360.mpg \ - && curl -sLko tmp/sample-0.flv https://filesamples.com/samples/video/flv/sample_640x360.flv \ - && curl -sLko tmp/sample-0.3gp https://filesamples.com/samples/video/3gp/sample_640x360.3gp \ - && curl -sLko tmp/sample-0.mkv https://filesamples.com/samples/video/mkv/sample_640x360.mkv \ - && curl -sLko tmp/sample-0.swf https://filesamples.com/samples/video/swf/sample_640x360.swf \ - && curl -sLko tmp/sample-0.mp4 https://filesamples.com/samples/video/mp4/sample_640x360.mp4 \ - && curl -sLko tmp/sample-0.webm https://filesamples.com/samples/video/webm/sample_640x360.webm \ - && curl -sLko tmp/sample-0.wmv https://filesamples.com/samples/video/wmv/sample_640x360.wmv \ - && curl -sLko tmp/sample-0.avi https://filesamples.com/samples/video/avi/sample_640x360.avi \ - && curl -sLko tmp/sample-0.mov https://filesamples.com/samples/video/mov/sample_640x360.mov \ - && curl -sLko tmp/sample-0.bmp https://filesamples.com/samples/image/bmp/sample_640%C3%97426.bmp \ - && curl -sLko tmp/sample-0.avif http://sample-file.bazadanni.com/download/images/avif/sample.avif \ - && curl -sLko tmp/sample-0.webp https://filesamples.com/samples/image/webp/sample1.webp \ - && curl -sLko tmp/sample-0.png https://filesamples.com/samples/image/png/sample_640%C3%97426.png \ - && curl -sLko tmp/sample-0.jpg https://filesamples.com/samples/image/jpg/sample_640%C3%97426.jpg \ - && curl -sLko tmp/sample-0.tiff https://filesamples.com/samples/image/tiff/sample_640%C3%97426.tiff \ - && curl -sLko tmp/sample-0.gif https://filesamples.com/samples/image/gif/sample_640%C3%97426.gif \ - && curl -sLko tmp/sample-0.svg https://filesamples.com/samples/image/svg/sample_640%C3%97426.svg \ - && curl -sLko tmp/sample-0.ico https://filesamples.com/samples/image/ico/sample_640%C3%97426.ico \ - && curl -sLko tmp/sample-0.dib https://raw.githubusercontent.com/filestar/File-Type-Sample-Repository/master/dib/sample.dib \ - && curl -sLko tmp/sample-0.apk https://raw.githubusercontent.com/appium-boneyard/sample-code/master/sample-code/apps/ContactManager/ContactManager.apk \ - && curl -sLko tmp/sample-0.zip https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-zip-file.zip \ - && curl -sLko tmp/sample-0.rar https://getsamplefiles.com/download/rar/sample.rar \ - && curl -sLko tmp/sample-0.tgz https://getsamplefiles.com/download/gzip/sample.tgz \ - && curl -sLko tmp/sample-0.tar https://getsamplefiles.com/download/tar/sample.tar \ - && curl -sLko tmp/sample-0.jar.zip http://www.java2s.com/Code/JarDownload/sample/sample.jar.zip \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.mp3 https://filesamples.com/samples/audio/mp3/sample3.mp3 \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.wav https://freewavesamples.com/files/Ensoniq-ZR-76-01-Dope-77.wav \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.ogg https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.doc https://filesamples.com/samples/document/doc/sample1.doc \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.docx https://filesamples.com/samples/document/docx/sample3.docx \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.xls https://filesamples.com/samples/document/xls/sample1.xls \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.xlsx https://filesamples.com/samples/document/xlsx/sample1.xlsx \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.ppt https://filesamples.com/samples/document/ppt/sample2.ppt \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.odt https://filesamples.com/samples/document/odt/sample1.odt \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.pdf https://filesamples.com/samples/document/pdf/sample2.pdf \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.rtf https://filesamples.com/samples/document/rtf/sample3.rtf \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.mpg https://filesamples.com/samples/video/mpg/sample_640x360.mpg \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.flv https://filesamples.com/samples/video/flv/sample_640x360.flv \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.3gp https://filesamples.com/samples/video/3gp/sample_640x360.3gp \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.mkv https://filesamples.com/samples/video/mkv/sample_640x360.mkv \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.swf https://filesamples.com/samples/video/swf/sample_640x360.swf \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.mp4 https://filesamples.com/samples/video/mp4/sample_640x360.mp4 \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.webm https://filesamples.com/samples/video/webm/sample_640x360.webm \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.wmv https://filesamples.com/samples/video/wmv/sample_640x360.wmv \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.avi https://filesamples.com/samples/video/avi/sample_640x360.avi \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.mov https://filesamples.com/samples/video/mov/sample_640x360.mov \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.bmp https://filesamples.com/samples/image/bmp/sample_640%C3%97426.bmp \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.avif http://sample-file.bazadanni.com/download/images/avif/sample.avif \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.webp https://filesamples.com/samples/image/webp/sample1.webp \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.png https://filesamples.com/samples/image/png/sample_640%C3%97426.png \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.jpg https://filesamples.com/samples/image/jpg/sample_640%C3%97426.jpg \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.tiff https://filesamples.com/samples/image/tiff/sample_640%C3%97426.tiff \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.gif https://filesamples.com/samples/image/gif/sample_640%C3%97426.gif \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.svg https://filesamples.com/samples/image/svg/sample_640%C3%97426.svg \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.ico https://filesamples.com/samples/image/ico/sample_640%C3%97426.ico \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.dib https://raw.githubusercontent.com/filestar/File-Type-Sample-Repository/master/dib/sample.dib \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.apk https://raw.githubusercontent.com/appium-boneyard/sample-code/master/sample-code/apps/ContactManager/ContactManager.apk \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.zip https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-zip-file.zip \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.rar https://getsamplefiles.com/download/rar/sample.rar \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.tgz https://getsamplefiles.com/download/gzip/sample.tgz \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.tar https://getsamplefiles.com/download/tar/sample.tar \ + && curl -H 'Cache-Control: no-cache' -sLko tmp/sample-0.jar.zip http://www.java2s.com/Code/JarDownload/sample/sample.jar.zip \ && unzip tmp/sample-0.jar.zip -d tmp \ && mv tmp/sample.jar tmp/sample-0.jar \ && rm tmp/sample-0.jar.zip From 982e58e7d61729b61caadb889d7ae4ee290fa114 Mon Sep 17 00:00:00 2001 From: Lutfa Ibtihaji Ilham Date: Tue, 10 Jan 2023 19:34:31 +0700 Subject: [PATCH 2/4] Unit test: use readFileSync fn instead to avoid file closed by another fn --- test/3gp_test.js | 4 ++-- test/apk_test.js | 4 ++-- test/avif_test.js | 4 ++-- test/bmp_test.js | 4 ++-- test/dib_test.js | 4 ++-- test/flv_test.js | 4 ++-- test/gif_test.js | 4 ++-- test/gzip_test.js | 4 ++-- test/jar_test.js | 4 ++-- test/jpeg_test.js | 4 ++-- test/mkv_test.js | 4 ++-- test/mp3_test.js | 4 ++-- test/mp4_test.js | 4 ++-- test/mpg_test.js | 4 ++-- test/msoffice_test.js | 4 ++-- test/one_of_test.js | 10 +++++----- test/pdf_test.js | 4 ++-- test/png_test.js | 4 ++-- test/rar_test.js | 4 ++-- test/svg_test.js | 4 ++-- test/swf_test.js | 4 ++-- test/tiff_test.js | 4 ++-- test/webp_test.js | 4 ++-- test/zip_test.js | 4 ++-- 24 files changed, 51 insertions(+), 51 deletions(-) diff --git a/test/3gp_test.js b/test/3gp_test.js index a00e1c3..664f76f 100644 --- a/test/3gp_test.js +++ b/test/3gp_test.js @@ -9,14 +9,14 @@ describe('Test 3GP Validation', () => { assert.equal(valid, false); }); it('should return false when input buffer is invalid 3GP', () => { - fs.readFile('./tmp/sample-0.mkv', (error, invalid3gpBuffer) => { + fs.readFileSync('./tmp/sample-0.mkv', (error, invalid3gpBuffer) => { if (error) throw error; const valid = filesig.is3gp(invalid3gpBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid 3GP', () => { - fs.readFile('./tmp/sample-0.3gp', (error, valid3gpBuffer) => { + fs.readFileSync('./tmp/sample-0.3gp', (error, valid3gpBuffer) => { if (error) throw error; const valid = filesig.is3gp(valid3gpBuffer); assert.equal(valid, true); diff --git a/test/apk_test.js b/test/apk_test.js index 169c73f..cb9d1f6 100644 --- a/test/apk_test.js +++ b/test/apk_test.js @@ -4,7 +4,7 @@ const filesig = require('../index'); describe('Test APK Validation', () => { it('should return false when input buffer is invalid APK', () => { - fs.readFile('./tmp/sample-0.rar', (error, invalidApkBuffer) => { + fs.readFileSync('./tmp/sample-0.rar', (error, invalidApkBuffer) => { if (error) throw error; const valid = filesig.isApk(invalidApkBuffer); assert.equal(valid, false); @@ -12,7 +12,7 @@ describe('Test APK Validation', () => { }); it('should return true when input buffer is valid APK', () => { - fs.readFile('./tmp/sample-0.apk', (error, validApkBuffer) => { + fs.readFileSync('./tmp/sample-0.apk', (error, validApkBuffer) => { if (error) throw error; const valid = filesig.isApk(validApkBuffer); assert.equal(valid, true); diff --git a/test/avif_test.js b/test/avif_test.js index a19ed02..bc4c0d5 100644 --- a/test/avif_test.js +++ b/test/avif_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test AVIF Validation', () => { it('should return false when input buffer is invalid AVIF', () => { - fs.readFile('./tmp/sample-0.bmp', (error, invalidAvifBuffer) => { + fs.readFileSync('./tmp/sample-0.bmp', (error, invalidAvifBuffer) => { if (error) throw error; const valid = filesig.isAvif(invalidAvifBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid AVIF', () => { - fs.readFile('./tmp/sample-0.avif', (error, validAvifBuffer) => { + fs.readFileSync('./tmp/sample-0.avif', (error, validAvifBuffer) => { if (error) throw error; const valid = filesig.isAvif(validAvifBuffer); assert.equal(valid, true); diff --git a/test/bmp_test.js b/test/bmp_test.js index d96ee7e..f7daece 100644 --- a/test/bmp_test.js +++ b/test/bmp_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test BMP Validation', () => { it('should return false when input buffer is invalid BMP', () => { - fs.readFile('./tmp/sample-0.svg', (error, invalidBmpBuffer) => { + fs.readFileSync('./tmp/sample-0.svg', (error, invalidBmpBuffer) => { if (error) throw error; const valid = filesig.isBmp(invalidBmpBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid BMP', () => { - fs.readFile('./tmp/sample-0.bmp', (error, validBmpBuffer) => { + fs.readFileSync('./tmp/sample-0.bmp', (error, validBmpBuffer) => { if (error) throw error; const valid = filesig.isBmp(validBmpBuffer); assert.equal(valid, true); diff --git a/test/dib_test.js b/test/dib_test.js index 9b7e1c6..84c5d4b 100644 --- a/test/dib_test.js +++ b/test/dib_test.js @@ -9,14 +9,14 @@ describe('Test DIB Validation', () => { assert.equal(valid, false); }); it('should return false when input buffer is invalid DIB', () => { - fs.readFile('./tmp/sample-0.jpg', (error, invalidDibBuffer) => { + fs.readFileSync('./tmp/sample-0.jpg', (error, invalidDibBuffer) => { if (error) throw error; const valid = filesig.isDib(invalidDibBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid DIB', () => { - fs.readFile('./tmp/sample-0.dib', (error, validDibBuffer) => { + fs.readFileSync('./tmp/sample-0.dib', (error, validDibBuffer) => { if (error) throw error; const valid = filesig.isDib(validDibBuffer); assert.equal(valid, true); diff --git a/test/flv_test.js b/test/flv_test.js index 7a26675..564df0e 100644 --- a/test/flv_test.js +++ b/test/flv_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test FLV Validation', () => { it('should return false when input buffer is invalid FLV', () => { - fs.readFile('./tmp/sample-0.mp4', (error, invalidFlvBuffer) => { + fs.readFileSync('./tmp/sample-0.mp4', (error, invalidFlvBuffer) => { if (error) throw error; const valid = filesig.isFlv(invalidFlvBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid FLV', () => { - fs.readFile('./tmp/sample-0.flv', (error, validFlvBuffer) => { + fs.readFileSync('./tmp/sample-0.flv', (error, validFlvBuffer) => { if (error) throw error; const valid = filesig.isFlv(validFlvBuffer); assert.equal(valid, true); diff --git a/test/gif_test.js b/test/gif_test.js index 4e76797..803fc0e 100644 --- a/test/gif_test.js +++ b/test/gif_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test GIF Validation', () => { it('should return false when input buffer is invalid GIF', () => { - fs.readFile('./tmp/sample-0.png', (error, invalidGifBuffer) => { + fs.readFileSync('./tmp/sample-0.png', (error, invalidGifBuffer) => { if (error) throw error; const valid = filesig.isGif(invalidGifBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid GIF', () => { - fs.readFile('./tmp/sample-0.gif', (error, validGifBuffer) => { + fs.readFileSync('./tmp/sample-0.gif', (error, validGifBuffer) => { if (error) throw error; const valid = filesig.isGif(validGifBuffer); assert.equal(valid, true); diff --git a/test/gzip_test.js b/test/gzip_test.js index abc42f5..10cc4e8 100644 --- a/test/gzip_test.js +++ b/test/gzip_test.js @@ -4,7 +4,7 @@ const filesig = require('../index'); describe('Test GZIP Validation', () => { it('should return false when input buffer is invalid GZIP', () => { - fs.readFile('./tmp/sample-0.zip', (error, invalidGzipBuffer) => { + fs.readFileSync('./tmp/sample-0.zip', (error, invalidGzipBuffer) => { if (error) throw error; const valid = filesig.isGzip(invalidGzipBuffer); assert.equal(valid, false); @@ -12,7 +12,7 @@ describe('Test GZIP Validation', () => { }); it('should return true when input buffer is valid GZIP', () => { - fs.readFile('./tmp/sample-0.tgz', (error, validGzipBuffer) => { + fs.readFileSync('./tmp/sample-0.tgz', (error, validGzipBuffer) => { if (error) throw error; const valid = filesig.isGzip(validGzipBuffer); assert.equal(valid, true); diff --git a/test/jar_test.js b/test/jar_test.js index 84bb743..7559f24 100644 --- a/test/jar_test.js +++ b/test/jar_test.js @@ -4,7 +4,7 @@ const filesig = require('../index'); describe('Test JAR Validation', () => { it('should return false when input buffer is invalid JAR', () => { - fs.readFile('./tmp/sample-0.rar', (error, invalidJarBuffer) => { + fs.readFileSync('./tmp/sample-0.rar', (error, invalidJarBuffer) => { if (error) throw error; const valid = filesig.isJar(invalidJarBuffer); assert.equal(valid, false); @@ -12,7 +12,7 @@ describe('Test JAR Validation', () => { }); it('should return true when input buffer is valid JAR', () => { - fs.readFile('./tmp/sample-0.jar', (error, validJarBuffer) => { + fs.readFileSync('./tmp/sample-0.jar', (error, validJarBuffer) => { if (error) throw error; const valid = filesig.isJar(validJarBuffer); assert.equal(valid, true); diff --git a/test/jpeg_test.js b/test/jpeg_test.js index 90171c4..1df4595 100644 --- a/test/jpeg_test.js +++ b/test/jpeg_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test JPEG Validation', () => { it('should return false when input buffer is invalid JPEG', () => { - fs.readFile('./tmp/sample-0.webp', (error, invalidJpegBuffer) => { + fs.readFileSync('./tmp/sample-0.webp', (error, invalidJpegBuffer) => { if (error) throw error; const valid = filesig.isJpeg(invalidJpegBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid JPEG', () => { - fs.readFile('./tmp/sample-0.jpg', (error, validJpegBuffer) => { + fs.readFileSync('./tmp/sample-0.jpg', (error, validJpegBuffer) => { if (error) throw error; const valid = filesig.isJpeg(validJpegBuffer); assert.equal(valid, true); diff --git a/test/mkv_test.js b/test/mkv_test.js index 99386e4..a009be3 100644 --- a/test/mkv_test.js +++ b/test/mkv_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test MKV Validation', () => { it('should return false when input buffer is invalid MKV', () => { - fs.readFile('./tmp/sample-0.mp4', (error, invalidMkvBuffer) => { + fs.readFileSync('./tmp/sample-0.mp4', (error, invalidMkvBuffer) => { if (error) throw error; const valid = filesig.isMkv(invalidMkvBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid MKV', () => { - fs.readFile('./tmp/sample-0.mkv', (error, validMkvBuffer) => { + fs.readFileSync('./tmp/sample-0.mkv', (error, validMkvBuffer) => { if (error) throw error; const valid = filesig.isMkv(validMkvBuffer); assert.equal(valid, true); diff --git a/test/mp3_test.js b/test/mp3_test.js index f7dda40..f7be4d1 100644 --- a/test/mp3_test.js +++ b/test/mp3_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test MP3 Validation', () => { it('should return false when input buffer is invalid MP3', () => { - fs.readFile('./tmp/sample-0.ogg', (error, invalidMp3Buffer) => { + fs.readFileSync('./tmp/sample-0.ogg', (error, invalidMp3Buffer) => { if (error) throw error; const valid = filesig.isMp3(invalidMp3Buffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid MP3', () => { - fs.readFile('./tmp/sample-0.mp3', (error, validMp3Buffer) => { + fs.readFileSync('./tmp/sample-0.mp3', (error, validMp3Buffer) => { if (error) throw error; const valid = filesig.isMp3(validMp3Buffer); assert.equal(valid, true); diff --git a/test/mp4_test.js b/test/mp4_test.js index 518460d..3925879 100644 --- a/test/mp4_test.js +++ b/test/mp4_test.js @@ -9,14 +9,14 @@ describe('Test MP4 Validation', () => { assert.equal(valid, false); }); it('should return false when input buffer is invalid MP4', () => { - fs.readFile('./tmp/sample-0.mpg', (error, invalidMp4Buffer) => { + fs.readFileSync('./tmp/sample-0.mpg', (error, invalidMp4Buffer) => { if (error) throw error; const valid = filesig.isMp4(invalidMp4Buffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid MP4', () => { - fs.readFile('./tmp/sample-0.mp4', (error, validMp4Buffer) => { + fs.readFileSync('./tmp/sample-0.mp4', (error, validMp4Buffer) => { if (error) throw error; const valid = filesig.isMp4(validMp4Buffer); assert.equal(valid, true); diff --git a/test/mpg_test.js b/test/mpg_test.js index 3459050..17577ab 100644 --- a/test/mpg_test.js +++ b/test/mpg_test.js @@ -9,14 +9,14 @@ describe('Test MPG Validation', () => { assert.equal(valid, false); }); it('should return false when input buffer is invalid MPG', () => { - fs.readFile('./tmp/sample-0.3gp', (error, invalidMpgBuffer) => { + fs.readFileSync('./tmp/sample-0.3gp', (error, invalidMpgBuffer) => { if (error) throw error; const valid = filesig.isMpg(invalidMpgBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid MPG', () => { - fs.readFile('./tmp/sample-0.mpg', (error, validMpgBuffer) => { + fs.readFileSync('./tmp/sample-0.mpg', (error, validMpgBuffer) => { if (error) throw error; const valid = filesig.isMpg(validMpgBuffer); assert.equal(valid, true); diff --git a/test/msoffice_test.js b/test/msoffice_test.js index 92d4733..21bc245 100644 --- a/test/msoffice_test.js +++ b/test/msoffice_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test MS Office Validation', () => { it('should return false when input buffer is invalid MS Office', () => { - fs.readFile('./tmp/sample-0.pdf', (error, invalidMsOfficeBuffer) => { + fs.readFileSync('./tmp/sample-0.pdf', (error, invalidMsOfficeBuffer) => { if (error) throw error; const valid = filesig.isMsOffice(invalidMsOfficeBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid MS Office', () => { - fs.readFile('./tmp/sample-0.docx', (error, validMsOfficeBuffer) => { + fs.readFileSync('./tmp/sample-0.docx', (error, validMsOfficeBuffer) => { if (error) throw error; const valid = filesig.isMsOffice(validMsOfficeBuffer); assert.equal(valid, true); diff --git a/test/one_of_test.js b/test/one_of_test.js index acf51f5..efb11fd 100644 --- a/test/one_of_test.js +++ b/test/one_of_test.js @@ -4,7 +4,7 @@ const filesig = require('../index'); describe('Test One Of Validation', () => { it('should return true when input buffer is valid', () => { - fs.readFile('./tmp/sample-0.png', (error, validPngBuffer) => { + fs.readFileSync('./tmp/sample-0.png', (error, validPngBuffer) => { if (error) throw error; const valid = filesig.oneOf( validPngBuffer, @@ -18,7 +18,7 @@ describe('Test One Of Validation', () => { }); it('should return false when input buffer is valid, but one of the proper functions supplied is not available', () => { - fs.readFile('./tmp/sample-0.png', (error, validPngBuffer) => { + fs.readFileSync('./tmp/sample-0.png', (error, validPngBuffer) => { if (error) throw error; const valid = filesig.oneOf( validPngBuffer, @@ -32,7 +32,7 @@ describe('Test One Of Validation', () => { }); it('should return false when input buffer is valid, but one of the proper functions supplied is not available', () => { - fs.readFile('./tmp/sample-0.png', (error, validPngBuffer) => { + fs.readFileSync('./tmp/sample-0.png', (error, validPngBuffer) => { if (error) throw error; const valid = filesig.oneOf( validPngBuffer, @@ -46,7 +46,7 @@ describe('Test One Of Validation', () => { }); it('should throw error when some functions are invalid', () => { - fs.readFile('./tmp/sample-0.jpg', (error, invalidPngBuffer) => { + fs.readFileSync('./tmp/sample-0.jpg', (error, invalidPngBuffer) => { if (error) throw error; const valid = () => { filesig.oneOf( @@ -63,7 +63,7 @@ describe('Test One Of Validation', () => { }); it('should return false when input buffer is invalid', () => { - fs.readFile('./tmp/sample-0.jpg', (error, invalidPngBuffer) => { + fs.readFileSync('./tmp/sample-0.jpg', (error, invalidPngBuffer) => { if (error) throw error; const valid = filesig.oneOf( invalidPngBuffer, diff --git a/test/pdf_test.js b/test/pdf_test.js index c422299..8c5a734 100644 --- a/test/pdf_test.js +++ b/test/pdf_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test PDF Validation', () => { it('should return false when input buffer is invalid PDF', () => { - fs.readFile('./tmp/sample-0.rtf', (error, invalidPdfBuffer) => { + fs.readFileSync('./tmp/sample-0.rtf', (error, invalidPdfBuffer) => { if (error) throw error; const valid = filesig.isPdf(invalidPdfBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid PDF', () => { - fs.readFile('./tmp/sample-0.pdf', (error, validPdfBuffer) => { + fs.readFileSync('./tmp/sample-0.pdf', (error, validPdfBuffer) => { if (error) throw error; const valid = filesig.isPdf(validPdfBuffer); assert.equal(valid, true); diff --git a/test/png_test.js b/test/png_test.js index 5267d1c..7861b63 100644 --- a/test/png_test.js +++ b/test/png_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test PNG Validation', () => { it('should return false when input buffer is invalid PNG', () => { - fs.readFile('./tmp/sample-0.ico', (error, invalidPngBuffer) => { + fs.readFileSync('./tmp/sample-0.ico', (error, invalidPngBuffer) => { if (error) throw error; const valid = filesig.isPng(invalidPngBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid PNG', () => { - fs.readFile('./tmp/sample-0.png', (error, validPngBuffer) => { + fs.readFileSync('./tmp/sample-0.png', (error, validPngBuffer) => { if (error) throw error; const valid = filesig.isPng(validPngBuffer); assert.equal(valid, true); diff --git a/test/rar_test.js b/test/rar_test.js index 94cb530..0d2b84b 100644 --- a/test/rar_test.js +++ b/test/rar_test.js @@ -4,7 +4,7 @@ const filesig = require('../index'); describe('Test RAR Validation', () => { it('should return false when input buffer is invalid RAR', () => { - fs.readFile('./tmp/sample-0.tgz', (error, invalidRarBuffer) => { + fs.readFileSync('./tmp/sample-0.tgz', (error, invalidRarBuffer) => { if (error) throw error; const valid = filesig.isRar(invalidRarBuffer); assert.equal(valid, false); @@ -12,7 +12,7 @@ describe('Test RAR Validation', () => { }); it('should return true when input buffer is valid RAR', () => { - fs.readFile('./tmp/sample-0.rar', (error, validRarBuffer) => { + fs.readFileSync('./tmp/sample-0.rar', (error, validRarBuffer) => { if (error) throw error; const valid = filesig.isRar(validRarBuffer); assert.equal(valid, true); diff --git a/test/svg_test.js b/test/svg_test.js index 549a766..74a370a 100644 --- a/test/svg_test.js +++ b/test/svg_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test SVG Validation', () => { it('should return false when input buffer is invalid SVG', () => { - fs.readFile('./tmp/sample-0.jpg', (error, invalidSvgBuffer) => { + fs.readFileSync('./tmp/sample-0.jpg', (error, invalidSvgBuffer) => { if (error) throw error; const valid = filesig.isSvg(invalidSvgBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid SVG', () => { - fs.readFile('./tmp/sample-0.svg', (error, validSvgBuffer) => { + fs.readFileSync('./tmp/sample-0.svg', (error, validSvgBuffer) => { if (error) throw error; const valid = filesig.isSvg(validSvgBuffer); assert.equal(valid, true); diff --git a/test/swf_test.js b/test/swf_test.js index 877fd25..e71c5e4 100644 --- a/test/swf_test.js +++ b/test/swf_test.js @@ -9,14 +9,14 @@ describe('Test SWF Validation', () => { assert.equal(valid, false); }); it('should return false when input buffer is invalid SWF', () => { - fs.readFile('./tmp/sample-0.3gp', (error, invalidSwfBuffer) => { + fs.readFileSync('./tmp/sample-0.3gp', (error, invalidSwfBuffer) => { if (error) throw error; const valid = filesig.isSwf(invalidSwfBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid SWF', () => { - fs.readFile('./tmp/sample-0.swf', (error, validSwfBuffer) => { + fs.readFileSync('./tmp/sample-0.swf', (error, validSwfBuffer) => { if (error) throw error; const valid = filesig.isSwf(validSwfBuffer); assert.equal(valid, true); diff --git a/test/tiff_test.js b/test/tiff_test.js index 21855a8..beaa2ef 100644 --- a/test/tiff_test.js +++ b/test/tiff_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test TIFF Validation', () => { it('should return false when input buffer is invalid TIFF', () => { - fs.readFile('./tmp/sample-0.png', (error, invalidTiffBuffer) => { + fs.readFileSync('./tmp/sample-0.png', (error, invalidTiffBuffer) => { if (error) throw error; const valid = filesig.isTiff(invalidTiffBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid TIFF', () => { - fs.readFile('./tmp/sample-0.tiff', (error, validTiffBuffer) => { + fs.readFileSync('./tmp/sample-0.tiff', (error, validTiffBuffer) => { if (error) throw error; const valid = filesig.isTiff(validTiffBuffer); assert.equal(valid, true); diff --git a/test/webp_test.js b/test/webp_test.js index dc23640..0a8a09c 100644 --- a/test/webp_test.js +++ b/test/webp_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test WEBP Validation', () => { it('should return false when input buffer is invalid WEBP', () => { - fs.readFile('./tmp/sample-0.tiff', (error, invalidWebpBuffer) => { + fs.readFileSync('./tmp/sample-0.tiff', (error, invalidWebpBuffer) => { if (error) throw error; const valid = filesig.isWebp(invalidWebpBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid WEBP', () => { - fs.readFile('./tmp/sample-0.webp', (error, validWebpBuffer) => { + fs.readFileSync('./tmp/sample-0.webp', (error, validWebpBuffer) => { if (error) throw error; const valid = filesig.isWebp(validWebpBuffer); assert.equal(valid, true); diff --git a/test/zip_test.js b/test/zip_test.js index 50a2bbf..68124d3 100644 --- a/test/zip_test.js +++ b/test/zip_test.js @@ -10,7 +10,7 @@ describe('Test ZIP Validation', () => { }); it('should return false when input buffer is invalid ZIP', () => { - fs.readFile('./tmp/sample-0.rar', (error, invalidZipBuffer) => { + fs.readFileSync('./tmp/sample-0.rar', (error, invalidZipBuffer) => { if (error) throw error; const valid = filesig.isZip(invalidZipBuffer); assert.equal(valid, false); @@ -18,7 +18,7 @@ describe('Test ZIP Validation', () => { }); it('should return true when input buffer is valid ZIP', () => { - fs.readFile('./tmp/sample-0.zip', (error, validZipBuffer) => { + fs.readFileSync('./tmp/sample-0.zip', (error, validZipBuffer) => { if (error) throw error; const valid = filesig.isZip(validZipBuffer); assert.equal(valid, true); From 1dd4beadd93b8a2a8ea925da3ccd83705c2570f9 Mon Sep 17 00:00:00 2001 From: Lutfa Ibtihaji Ilham Date: Wed, 11 Jan 2023 08:48:46 +0700 Subject: [PATCH 3/4] Revert "Unit test: use readFileSync fn instead to avoid file closed by another fn" This reverts commit 982e58e7d61729b61caadb889d7ae4ee290fa114. --- test/3gp_test.js | 4 ++-- test/apk_test.js | 4 ++-- test/avif_test.js | 4 ++-- test/bmp_test.js | 4 ++-- test/dib_test.js | 4 ++-- test/flv_test.js | 4 ++-- test/gif_test.js | 4 ++-- test/gzip_test.js | 4 ++-- test/jar_test.js | 4 ++-- test/jpeg_test.js | 4 ++-- test/mkv_test.js | 4 ++-- test/mp3_test.js | 4 ++-- test/mp4_test.js | 4 ++-- test/mpg_test.js | 4 ++-- test/msoffice_test.js | 4 ++-- test/one_of_test.js | 10 +++++----- test/pdf_test.js | 4 ++-- test/png_test.js | 4 ++-- test/rar_test.js | 4 ++-- test/svg_test.js | 4 ++-- test/swf_test.js | 4 ++-- test/tiff_test.js | 4 ++-- test/webp_test.js | 4 ++-- test/zip_test.js | 4 ++-- 24 files changed, 51 insertions(+), 51 deletions(-) diff --git a/test/3gp_test.js b/test/3gp_test.js index 664f76f..a00e1c3 100644 --- a/test/3gp_test.js +++ b/test/3gp_test.js @@ -9,14 +9,14 @@ describe('Test 3GP Validation', () => { assert.equal(valid, false); }); it('should return false when input buffer is invalid 3GP', () => { - fs.readFileSync('./tmp/sample-0.mkv', (error, invalid3gpBuffer) => { + fs.readFile('./tmp/sample-0.mkv', (error, invalid3gpBuffer) => { if (error) throw error; const valid = filesig.is3gp(invalid3gpBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid 3GP', () => { - fs.readFileSync('./tmp/sample-0.3gp', (error, valid3gpBuffer) => { + fs.readFile('./tmp/sample-0.3gp', (error, valid3gpBuffer) => { if (error) throw error; const valid = filesig.is3gp(valid3gpBuffer); assert.equal(valid, true); diff --git a/test/apk_test.js b/test/apk_test.js index cb9d1f6..169c73f 100644 --- a/test/apk_test.js +++ b/test/apk_test.js @@ -4,7 +4,7 @@ const filesig = require('../index'); describe('Test APK Validation', () => { it('should return false when input buffer is invalid APK', () => { - fs.readFileSync('./tmp/sample-0.rar', (error, invalidApkBuffer) => { + fs.readFile('./tmp/sample-0.rar', (error, invalidApkBuffer) => { if (error) throw error; const valid = filesig.isApk(invalidApkBuffer); assert.equal(valid, false); @@ -12,7 +12,7 @@ describe('Test APK Validation', () => { }); it('should return true when input buffer is valid APK', () => { - fs.readFileSync('./tmp/sample-0.apk', (error, validApkBuffer) => { + fs.readFile('./tmp/sample-0.apk', (error, validApkBuffer) => { if (error) throw error; const valid = filesig.isApk(validApkBuffer); assert.equal(valid, true); diff --git a/test/avif_test.js b/test/avif_test.js index bc4c0d5..a19ed02 100644 --- a/test/avif_test.js +++ b/test/avif_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test AVIF Validation', () => { it('should return false when input buffer is invalid AVIF', () => { - fs.readFileSync('./tmp/sample-0.bmp', (error, invalidAvifBuffer) => { + fs.readFile('./tmp/sample-0.bmp', (error, invalidAvifBuffer) => { if (error) throw error; const valid = filesig.isAvif(invalidAvifBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid AVIF', () => { - fs.readFileSync('./tmp/sample-0.avif', (error, validAvifBuffer) => { + fs.readFile('./tmp/sample-0.avif', (error, validAvifBuffer) => { if (error) throw error; const valid = filesig.isAvif(validAvifBuffer); assert.equal(valid, true); diff --git a/test/bmp_test.js b/test/bmp_test.js index f7daece..d96ee7e 100644 --- a/test/bmp_test.js +++ b/test/bmp_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test BMP Validation', () => { it('should return false when input buffer is invalid BMP', () => { - fs.readFileSync('./tmp/sample-0.svg', (error, invalidBmpBuffer) => { + fs.readFile('./tmp/sample-0.svg', (error, invalidBmpBuffer) => { if (error) throw error; const valid = filesig.isBmp(invalidBmpBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid BMP', () => { - fs.readFileSync('./tmp/sample-0.bmp', (error, validBmpBuffer) => { + fs.readFile('./tmp/sample-0.bmp', (error, validBmpBuffer) => { if (error) throw error; const valid = filesig.isBmp(validBmpBuffer); assert.equal(valid, true); diff --git a/test/dib_test.js b/test/dib_test.js index 84c5d4b..9b7e1c6 100644 --- a/test/dib_test.js +++ b/test/dib_test.js @@ -9,14 +9,14 @@ describe('Test DIB Validation', () => { assert.equal(valid, false); }); it('should return false when input buffer is invalid DIB', () => { - fs.readFileSync('./tmp/sample-0.jpg', (error, invalidDibBuffer) => { + fs.readFile('./tmp/sample-0.jpg', (error, invalidDibBuffer) => { if (error) throw error; const valid = filesig.isDib(invalidDibBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid DIB', () => { - fs.readFileSync('./tmp/sample-0.dib', (error, validDibBuffer) => { + fs.readFile('./tmp/sample-0.dib', (error, validDibBuffer) => { if (error) throw error; const valid = filesig.isDib(validDibBuffer); assert.equal(valid, true); diff --git a/test/flv_test.js b/test/flv_test.js index 564df0e..7a26675 100644 --- a/test/flv_test.js +++ b/test/flv_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test FLV Validation', () => { it('should return false when input buffer is invalid FLV', () => { - fs.readFileSync('./tmp/sample-0.mp4', (error, invalidFlvBuffer) => { + fs.readFile('./tmp/sample-0.mp4', (error, invalidFlvBuffer) => { if (error) throw error; const valid = filesig.isFlv(invalidFlvBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid FLV', () => { - fs.readFileSync('./tmp/sample-0.flv', (error, validFlvBuffer) => { + fs.readFile('./tmp/sample-0.flv', (error, validFlvBuffer) => { if (error) throw error; const valid = filesig.isFlv(validFlvBuffer); assert.equal(valid, true); diff --git a/test/gif_test.js b/test/gif_test.js index 803fc0e..4e76797 100644 --- a/test/gif_test.js +++ b/test/gif_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test GIF Validation', () => { it('should return false when input buffer is invalid GIF', () => { - fs.readFileSync('./tmp/sample-0.png', (error, invalidGifBuffer) => { + fs.readFile('./tmp/sample-0.png', (error, invalidGifBuffer) => { if (error) throw error; const valid = filesig.isGif(invalidGifBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid GIF', () => { - fs.readFileSync('./tmp/sample-0.gif', (error, validGifBuffer) => { + fs.readFile('./tmp/sample-0.gif', (error, validGifBuffer) => { if (error) throw error; const valid = filesig.isGif(validGifBuffer); assert.equal(valid, true); diff --git a/test/gzip_test.js b/test/gzip_test.js index 10cc4e8..abc42f5 100644 --- a/test/gzip_test.js +++ b/test/gzip_test.js @@ -4,7 +4,7 @@ const filesig = require('../index'); describe('Test GZIP Validation', () => { it('should return false when input buffer is invalid GZIP', () => { - fs.readFileSync('./tmp/sample-0.zip', (error, invalidGzipBuffer) => { + fs.readFile('./tmp/sample-0.zip', (error, invalidGzipBuffer) => { if (error) throw error; const valid = filesig.isGzip(invalidGzipBuffer); assert.equal(valid, false); @@ -12,7 +12,7 @@ describe('Test GZIP Validation', () => { }); it('should return true when input buffer is valid GZIP', () => { - fs.readFileSync('./tmp/sample-0.tgz', (error, validGzipBuffer) => { + fs.readFile('./tmp/sample-0.tgz', (error, validGzipBuffer) => { if (error) throw error; const valid = filesig.isGzip(validGzipBuffer); assert.equal(valid, true); diff --git a/test/jar_test.js b/test/jar_test.js index 7559f24..84bb743 100644 --- a/test/jar_test.js +++ b/test/jar_test.js @@ -4,7 +4,7 @@ const filesig = require('../index'); describe('Test JAR Validation', () => { it('should return false when input buffer is invalid JAR', () => { - fs.readFileSync('./tmp/sample-0.rar', (error, invalidJarBuffer) => { + fs.readFile('./tmp/sample-0.rar', (error, invalidJarBuffer) => { if (error) throw error; const valid = filesig.isJar(invalidJarBuffer); assert.equal(valid, false); @@ -12,7 +12,7 @@ describe('Test JAR Validation', () => { }); it('should return true when input buffer is valid JAR', () => { - fs.readFileSync('./tmp/sample-0.jar', (error, validJarBuffer) => { + fs.readFile('./tmp/sample-0.jar', (error, validJarBuffer) => { if (error) throw error; const valid = filesig.isJar(validJarBuffer); assert.equal(valid, true); diff --git a/test/jpeg_test.js b/test/jpeg_test.js index 1df4595..90171c4 100644 --- a/test/jpeg_test.js +++ b/test/jpeg_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test JPEG Validation', () => { it('should return false when input buffer is invalid JPEG', () => { - fs.readFileSync('./tmp/sample-0.webp', (error, invalidJpegBuffer) => { + fs.readFile('./tmp/sample-0.webp', (error, invalidJpegBuffer) => { if (error) throw error; const valid = filesig.isJpeg(invalidJpegBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid JPEG', () => { - fs.readFileSync('./tmp/sample-0.jpg', (error, validJpegBuffer) => { + fs.readFile('./tmp/sample-0.jpg', (error, validJpegBuffer) => { if (error) throw error; const valid = filesig.isJpeg(validJpegBuffer); assert.equal(valid, true); diff --git a/test/mkv_test.js b/test/mkv_test.js index a009be3..99386e4 100644 --- a/test/mkv_test.js +++ b/test/mkv_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test MKV Validation', () => { it('should return false when input buffer is invalid MKV', () => { - fs.readFileSync('./tmp/sample-0.mp4', (error, invalidMkvBuffer) => { + fs.readFile('./tmp/sample-0.mp4', (error, invalidMkvBuffer) => { if (error) throw error; const valid = filesig.isMkv(invalidMkvBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid MKV', () => { - fs.readFileSync('./tmp/sample-0.mkv', (error, validMkvBuffer) => { + fs.readFile('./tmp/sample-0.mkv', (error, validMkvBuffer) => { if (error) throw error; const valid = filesig.isMkv(validMkvBuffer); assert.equal(valid, true); diff --git a/test/mp3_test.js b/test/mp3_test.js index f7be4d1..f7dda40 100644 --- a/test/mp3_test.js +++ b/test/mp3_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test MP3 Validation', () => { it('should return false when input buffer is invalid MP3', () => { - fs.readFileSync('./tmp/sample-0.ogg', (error, invalidMp3Buffer) => { + fs.readFile('./tmp/sample-0.ogg', (error, invalidMp3Buffer) => { if (error) throw error; const valid = filesig.isMp3(invalidMp3Buffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid MP3', () => { - fs.readFileSync('./tmp/sample-0.mp3', (error, validMp3Buffer) => { + fs.readFile('./tmp/sample-0.mp3', (error, validMp3Buffer) => { if (error) throw error; const valid = filesig.isMp3(validMp3Buffer); assert.equal(valid, true); diff --git a/test/mp4_test.js b/test/mp4_test.js index 3925879..518460d 100644 --- a/test/mp4_test.js +++ b/test/mp4_test.js @@ -9,14 +9,14 @@ describe('Test MP4 Validation', () => { assert.equal(valid, false); }); it('should return false when input buffer is invalid MP4', () => { - fs.readFileSync('./tmp/sample-0.mpg', (error, invalidMp4Buffer) => { + fs.readFile('./tmp/sample-0.mpg', (error, invalidMp4Buffer) => { if (error) throw error; const valid = filesig.isMp4(invalidMp4Buffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid MP4', () => { - fs.readFileSync('./tmp/sample-0.mp4', (error, validMp4Buffer) => { + fs.readFile('./tmp/sample-0.mp4', (error, validMp4Buffer) => { if (error) throw error; const valid = filesig.isMp4(validMp4Buffer); assert.equal(valid, true); diff --git a/test/mpg_test.js b/test/mpg_test.js index 17577ab..3459050 100644 --- a/test/mpg_test.js +++ b/test/mpg_test.js @@ -9,14 +9,14 @@ describe('Test MPG Validation', () => { assert.equal(valid, false); }); it('should return false when input buffer is invalid MPG', () => { - fs.readFileSync('./tmp/sample-0.3gp', (error, invalidMpgBuffer) => { + fs.readFile('./tmp/sample-0.3gp', (error, invalidMpgBuffer) => { if (error) throw error; const valid = filesig.isMpg(invalidMpgBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid MPG', () => { - fs.readFileSync('./tmp/sample-0.mpg', (error, validMpgBuffer) => { + fs.readFile('./tmp/sample-0.mpg', (error, validMpgBuffer) => { if (error) throw error; const valid = filesig.isMpg(validMpgBuffer); assert.equal(valid, true); diff --git a/test/msoffice_test.js b/test/msoffice_test.js index 21bc245..92d4733 100644 --- a/test/msoffice_test.js +++ b/test/msoffice_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test MS Office Validation', () => { it('should return false when input buffer is invalid MS Office', () => { - fs.readFileSync('./tmp/sample-0.pdf', (error, invalidMsOfficeBuffer) => { + fs.readFile('./tmp/sample-0.pdf', (error, invalidMsOfficeBuffer) => { if (error) throw error; const valid = filesig.isMsOffice(invalidMsOfficeBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid MS Office', () => { - fs.readFileSync('./tmp/sample-0.docx', (error, validMsOfficeBuffer) => { + fs.readFile('./tmp/sample-0.docx', (error, validMsOfficeBuffer) => { if (error) throw error; const valid = filesig.isMsOffice(validMsOfficeBuffer); assert.equal(valid, true); diff --git a/test/one_of_test.js b/test/one_of_test.js index efb11fd..acf51f5 100644 --- a/test/one_of_test.js +++ b/test/one_of_test.js @@ -4,7 +4,7 @@ const filesig = require('../index'); describe('Test One Of Validation', () => { it('should return true when input buffer is valid', () => { - fs.readFileSync('./tmp/sample-0.png', (error, validPngBuffer) => { + fs.readFile('./tmp/sample-0.png', (error, validPngBuffer) => { if (error) throw error; const valid = filesig.oneOf( validPngBuffer, @@ -18,7 +18,7 @@ describe('Test One Of Validation', () => { }); it('should return false when input buffer is valid, but one of the proper functions supplied is not available', () => { - fs.readFileSync('./tmp/sample-0.png', (error, validPngBuffer) => { + fs.readFile('./tmp/sample-0.png', (error, validPngBuffer) => { if (error) throw error; const valid = filesig.oneOf( validPngBuffer, @@ -32,7 +32,7 @@ describe('Test One Of Validation', () => { }); it('should return false when input buffer is valid, but one of the proper functions supplied is not available', () => { - fs.readFileSync('./tmp/sample-0.png', (error, validPngBuffer) => { + fs.readFile('./tmp/sample-0.png', (error, validPngBuffer) => { if (error) throw error; const valid = filesig.oneOf( validPngBuffer, @@ -46,7 +46,7 @@ describe('Test One Of Validation', () => { }); it('should throw error when some functions are invalid', () => { - fs.readFileSync('./tmp/sample-0.jpg', (error, invalidPngBuffer) => { + fs.readFile('./tmp/sample-0.jpg', (error, invalidPngBuffer) => { if (error) throw error; const valid = () => { filesig.oneOf( @@ -63,7 +63,7 @@ describe('Test One Of Validation', () => { }); it('should return false when input buffer is invalid', () => { - fs.readFileSync('./tmp/sample-0.jpg', (error, invalidPngBuffer) => { + fs.readFile('./tmp/sample-0.jpg', (error, invalidPngBuffer) => { if (error) throw error; const valid = filesig.oneOf( invalidPngBuffer, diff --git a/test/pdf_test.js b/test/pdf_test.js index 8c5a734..c422299 100644 --- a/test/pdf_test.js +++ b/test/pdf_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test PDF Validation', () => { it('should return false when input buffer is invalid PDF', () => { - fs.readFileSync('./tmp/sample-0.rtf', (error, invalidPdfBuffer) => { + fs.readFile('./tmp/sample-0.rtf', (error, invalidPdfBuffer) => { if (error) throw error; const valid = filesig.isPdf(invalidPdfBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid PDF', () => { - fs.readFileSync('./tmp/sample-0.pdf', (error, validPdfBuffer) => { + fs.readFile('./tmp/sample-0.pdf', (error, validPdfBuffer) => { if (error) throw error; const valid = filesig.isPdf(validPdfBuffer); assert.equal(valid, true); diff --git a/test/png_test.js b/test/png_test.js index 7861b63..5267d1c 100644 --- a/test/png_test.js +++ b/test/png_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test PNG Validation', () => { it('should return false when input buffer is invalid PNG', () => { - fs.readFileSync('./tmp/sample-0.ico', (error, invalidPngBuffer) => { + fs.readFile('./tmp/sample-0.ico', (error, invalidPngBuffer) => { if (error) throw error; const valid = filesig.isPng(invalidPngBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid PNG', () => { - fs.readFileSync('./tmp/sample-0.png', (error, validPngBuffer) => { + fs.readFile('./tmp/sample-0.png', (error, validPngBuffer) => { if (error) throw error; const valid = filesig.isPng(validPngBuffer); assert.equal(valid, true); diff --git a/test/rar_test.js b/test/rar_test.js index 0d2b84b..94cb530 100644 --- a/test/rar_test.js +++ b/test/rar_test.js @@ -4,7 +4,7 @@ const filesig = require('../index'); describe('Test RAR Validation', () => { it('should return false when input buffer is invalid RAR', () => { - fs.readFileSync('./tmp/sample-0.tgz', (error, invalidRarBuffer) => { + fs.readFile('./tmp/sample-0.tgz', (error, invalidRarBuffer) => { if (error) throw error; const valid = filesig.isRar(invalidRarBuffer); assert.equal(valid, false); @@ -12,7 +12,7 @@ describe('Test RAR Validation', () => { }); it('should return true when input buffer is valid RAR', () => { - fs.readFileSync('./tmp/sample-0.rar', (error, validRarBuffer) => { + fs.readFile('./tmp/sample-0.rar', (error, validRarBuffer) => { if (error) throw error; const valid = filesig.isRar(validRarBuffer); assert.equal(valid, true); diff --git a/test/svg_test.js b/test/svg_test.js index 74a370a..549a766 100644 --- a/test/svg_test.js +++ b/test/svg_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test SVG Validation', () => { it('should return false when input buffer is invalid SVG', () => { - fs.readFileSync('./tmp/sample-0.jpg', (error, invalidSvgBuffer) => { + fs.readFile('./tmp/sample-0.jpg', (error, invalidSvgBuffer) => { if (error) throw error; const valid = filesig.isSvg(invalidSvgBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid SVG', () => { - fs.readFileSync('./tmp/sample-0.svg', (error, validSvgBuffer) => { + fs.readFile('./tmp/sample-0.svg', (error, validSvgBuffer) => { if (error) throw error; const valid = filesig.isSvg(validSvgBuffer); assert.equal(valid, true); diff --git a/test/swf_test.js b/test/swf_test.js index e71c5e4..877fd25 100644 --- a/test/swf_test.js +++ b/test/swf_test.js @@ -9,14 +9,14 @@ describe('Test SWF Validation', () => { assert.equal(valid, false); }); it('should return false when input buffer is invalid SWF', () => { - fs.readFileSync('./tmp/sample-0.3gp', (error, invalidSwfBuffer) => { + fs.readFile('./tmp/sample-0.3gp', (error, invalidSwfBuffer) => { if (error) throw error; const valid = filesig.isSwf(invalidSwfBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid SWF', () => { - fs.readFileSync('./tmp/sample-0.swf', (error, validSwfBuffer) => { + fs.readFile('./tmp/sample-0.swf', (error, validSwfBuffer) => { if (error) throw error; const valid = filesig.isSwf(validSwfBuffer); assert.equal(valid, true); diff --git a/test/tiff_test.js b/test/tiff_test.js index beaa2ef..21855a8 100644 --- a/test/tiff_test.js +++ b/test/tiff_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test TIFF Validation', () => { it('should return false when input buffer is invalid TIFF', () => { - fs.readFileSync('./tmp/sample-0.png', (error, invalidTiffBuffer) => { + fs.readFile('./tmp/sample-0.png', (error, invalidTiffBuffer) => { if (error) throw error; const valid = filesig.isTiff(invalidTiffBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid TIFF', () => { - fs.readFileSync('./tmp/sample-0.tiff', (error, validTiffBuffer) => { + fs.readFile('./tmp/sample-0.tiff', (error, validTiffBuffer) => { if (error) throw error; const valid = filesig.isTiff(validTiffBuffer); assert.equal(valid, true); diff --git a/test/webp_test.js b/test/webp_test.js index 0a8a09c..dc23640 100644 --- a/test/webp_test.js +++ b/test/webp_test.js @@ -4,14 +4,14 @@ const filesig = require('../index'); describe('Test WEBP Validation', () => { it('should return false when input buffer is invalid WEBP', () => { - fs.readFileSync('./tmp/sample-0.tiff', (error, invalidWebpBuffer) => { + fs.readFile('./tmp/sample-0.tiff', (error, invalidWebpBuffer) => { if (error) throw error; const valid = filesig.isWebp(invalidWebpBuffer); assert.equal(valid, false); }); }); it('should return true when input buffer is valid WEBP', () => { - fs.readFileSync('./tmp/sample-0.webp', (error, validWebpBuffer) => { + fs.readFile('./tmp/sample-0.webp', (error, validWebpBuffer) => { if (error) throw error; const valid = filesig.isWebp(validWebpBuffer); assert.equal(valid, true); diff --git a/test/zip_test.js b/test/zip_test.js index 68124d3..50a2bbf 100644 --- a/test/zip_test.js +++ b/test/zip_test.js @@ -10,7 +10,7 @@ describe('Test ZIP Validation', () => { }); it('should return false when input buffer is invalid ZIP', () => { - fs.readFileSync('./tmp/sample-0.rar', (error, invalidZipBuffer) => { + fs.readFile('./tmp/sample-0.rar', (error, invalidZipBuffer) => { if (error) throw error; const valid = filesig.isZip(invalidZipBuffer); assert.equal(valid, false); @@ -18,7 +18,7 @@ describe('Test ZIP Validation', () => { }); it('should return true when input buffer is valid ZIP', () => { - fs.readFileSync('./tmp/sample-0.zip', (error, validZipBuffer) => { + fs.readFile('./tmp/sample-0.zip', (error, validZipBuffer) => { if (error) throw error; const valid = filesig.isZip(validZipBuffer); assert.equal(valid, true); From d227dd5958f885a28004f401cdeb76a5402ece50 Mon Sep 17 00:00:00 2001 From: Lutfa Ibtihaji Ilham Date: Wed, 11 Jan 2023 08:50:34 +0700 Subject: [PATCH 4/4] Unit test: use readFileSync fn instead to avoid file closed by another fn --- test/zip_test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/zip_test.js b/test/zip_test.js index 50a2bbf..68124d3 100644 --- a/test/zip_test.js +++ b/test/zip_test.js @@ -10,7 +10,7 @@ describe('Test ZIP Validation', () => { }); it('should return false when input buffer is invalid ZIP', () => { - fs.readFile('./tmp/sample-0.rar', (error, invalidZipBuffer) => { + fs.readFileSync('./tmp/sample-0.rar', (error, invalidZipBuffer) => { if (error) throw error; const valid = filesig.isZip(invalidZipBuffer); assert.equal(valid, false); @@ -18,7 +18,7 @@ describe('Test ZIP Validation', () => { }); it('should return true when input buffer is valid ZIP', () => { - fs.readFile('./tmp/sample-0.zip', (error, validZipBuffer) => { + fs.readFileSync('./tmp/sample-0.zip', (error, validZipBuffer) => { if (error) throw error; const valid = filesig.isZip(validZipBuffer); assert.equal(valid, true);