diff --git a/package-lock.json b/package-lock.json index 48a6f27e..76f7afbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,11 +6,11 @@ "packages": { "": { "name": "@ethersphere/swarm-cli", - "version": "2.32.0", + "version": "2.33.0", "license": "BSD-3-Clause", "dependencies": { "@ethereumjs/wallet": "^2.0.4", - "@ethersphere/bee-js": "^9.6.0", + "@ethersphere/bee-js": "^9.6.1", "cafe-utility": "^27.14.0", "chalk": "^2.4.2", "cli-progress": "^3.11.2", @@ -1129,9 +1129,9 @@ } }, "node_modules/@ethersphere/bee-js": { - "version": "9.6.0", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-9.6.0.tgz", - "integrity": "sha512-nZ4PqEgqMd9PdBoAvVfYkqbyl8B8pHE9BOKIvnEaRheAI5WZ1bUswhReWUY7voUS+/iFKZpYI4XQeEPPYIhisQ==", + "version": "9.6.1", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-9.6.1.tgz", + "integrity": "sha512-YauFLtjY7ZXiO19HfM9vJaZOBxjKvwRN7dRfzh4FldP78SomK/8T9cT5hagrFJIgHr0MPQxvQRHvUKQifYRlvg==", "license": "BSD-3-Clause", "dependencies": { "axios": "^0.30.0", diff --git a/package.json b/package.json index c4fb81cb..dcaa43de 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ }, "dependencies": { "@ethereumjs/wallet": "^2.0.4", - "@ethersphere/bee-js": "^9.6.0", + "@ethersphere/bee-js": "^9.6.1", "cafe-utility": "^27.14.0", "chalk": "^2.4.2", "cli-progress": "^3.11.2", diff --git a/test/command/download.spec.ts b/test/command/download.spec.ts index b3e25200..b5f528ad 100644 --- a/test/command/download.spec.ts +++ b/test/command/download.spec.ts @@ -1,10 +1,11 @@ -import { mkdtempSync } from 'node:fs' +import { Binary } from 'cafe-utility' +import { existsSync, mkdtempSync, readdirSync, readFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' +import { Addresses } from '../../src/command/addresses' import { Upload } from '../../src/command/upload' import { describeCommand, invokeTestCli } from '../utility' import { getStampOption } from '../utility/stamp' -import { Addresses } from '../../src/command/addresses' function makeTmpDir(): string { return mkdtempSync(join(tmpdir(), 'swarm-cli-testrun-')) @@ -63,4 +64,30 @@ describeCommand('Test Download command', ({ consoleMessages }) => { expect(consoleMessages.some(x => x.includes('index.html'))).toBe(true) expect(consoleMessages.some(x => x.includes('swarm.bzz'))).toBe(true) }) + + it('should download an encrypted file', async () => { + const invocation = await invokeTestCli(['upload', 'docs/upload.gif', '--encrypt', ...getStampOption()]) + const hash = (invocation.runnable as Upload).result.getOrThrow() + expect(hash.toHex()).toHaveLength(128) + expect(existsSync(hash.toHex())).toBe(false) + await invokeTestCli(['download', hash.toHex()]) + expect(existsSync(hash.toHex() + '/upload.gif')).toBe(true) + const data1 = readFileSync(hash.toHex() + '/upload.gif') + const data2 = readFileSync('docs/upload.gif') + expect(Binary.equals(data1, data2)).toBe(true) + }) + + it('should download an encrypted folder', async () => { + const invocation = await invokeTestCli(['upload', 'docs', '--encrypt', ...getStampOption()]) + const hash = (invocation.runnable as Upload).result.getOrThrow() + expect(hash.toHex()).toHaveLength(128) + await invokeTestCli(['download', hash.toHex()]) + expect(existsSync(hash.toHex())).toBe(true) + const content = readdirSync(hash.toHex()) + expect(content.length).toBe(4) + expect(content.includes('upload.gif')).toBe(true) + expect(content.includes('stamp-buy.gif')).toBe(true) + expect(content.includes('identity-create.gif')).toBe(true) + expect(content.includes('feed-upload.gif')).toBe(true) + }) })