From 458c503019ee2df6dd19ba30730de6ea5f5931af Mon Sep 17 00:00:00 2001 From: Cafe137 Date: Wed, 30 Jul 2025 10:42:10 +0200 Subject: [PATCH 1/3] test: add encrypted download tests --- test/command/download.spec.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/test/command/download.spec.ts b/test/command/download.spec.ts index b3e25200..9c06606c 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('upload.gif')).toBe(false) + await invokeTestCli(['download', hash.toHex()]) + expect(existsSync('upload.gif')).toBe(true) + const data1 = readFileSync('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) + }) }) From cb56e02fc1592490efeac435ad63d8caf6789739 Mon Sep 17 00:00:00 2001 From: Cafe137 Date: Wed, 30 Jul 2025 15:35:39 +0200 Subject: [PATCH 2/3] chore: update bee-js --- package-lock.json | 10 +++++----- package.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) 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", From da694755b70f4ee171c2da7966872f754c5110a4 Mon Sep 17 00:00:00 2001 From: Cafe137 Date: Wed, 30 Jul 2025 16:14:51 +0200 Subject: [PATCH 3/3] test: adjust single file encrypted download test --- test/command/download.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/command/download.spec.ts b/test/command/download.spec.ts index 9c06606c..b5f528ad 100644 --- a/test/command/download.spec.ts +++ b/test/command/download.spec.ts @@ -69,10 +69,10 @@ describeCommand('Test Download command', ({ consoleMessages }) => { 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('upload.gif')).toBe(false) + expect(existsSync(hash.toHex())).toBe(false) await invokeTestCli(['download', hash.toHex()]) - expect(existsSync('upload.gif')).toBe(true) - const data1 = readFileSync('upload.gif') + 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) })