Skip to content

Commit 72c4593

Browse files
authored
test: add encrypted download tests (#641)
* test: add encrypted download tests * chore: update bee-js * test: adjust single file encrypted download test
1 parent ca0003d commit 72c4593

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"dependencies": {
6565
"@ethereumjs/wallet": "^2.0.4",
66-
"@ethersphere/bee-js": "^9.6.0",
66+
"@ethersphere/bee-js": "^9.6.1",
6767
"cafe-utility": "^27.14.0",
6868
"chalk": "^2.4.2",
6969
"cli-progress": "^3.11.2",

test/command/download.spec.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { mkdtempSync } from 'node:fs'
1+
import { Binary } from 'cafe-utility'
2+
import { existsSync, mkdtempSync, readdirSync, readFileSync } from 'node:fs'
23
import { tmpdir } from 'node:os'
34
import { join } from 'node:path'
5+
import { Addresses } from '../../src/command/addresses'
46
import { Upload } from '../../src/command/upload'
57
import { describeCommand, invokeTestCli } from '../utility'
68
import { getStampOption } from '../utility/stamp'
7-
import { Addresses } from '../../src/command/addresses'
89

910
function makeTmpDir(): string {
1011
return mkdtempSync(join(tmpdir(), 'swarm-cli-testrun-'))
@@ -63,4 +64,30 @@ describeCommand('Test Download command', ({ consoleMessages }) => {
6364
expect(consoleMessages.some(x => x.includes('index.html'))).toBe(true)
6465
expect(consoleMessages.some(x => x.includes('swarm.bzz'))).toBe(true)
6566
})
67+
68+
it('should download an encrypted file', async () => {
69+
const invocation = await invokeTestCli(['upload', 'docs/upload.gif', '--encrypt', ...getStampOption()])
70+
const hash = (invocation.runnable as Upload).result.getOrThrow()
71+
expect(hash.toHex()).toHaveLength(128)
72+
expect(existsSync(hash.toHex())).toBe(false)
73+
await invokeTestCli(['download', hash.toHex()])
74+
expect(existsSync(hash.toHex() + '/upload.gif')).toBe(true)
75+
const data1 = readFileSync(hash.toHex() + '/upload.gif')
76+
const data2 = readFileSync('docs/upload.gif')
77+
expect(Binary.equals(data1, data2)).toBe(true)
78+
})
79+
80+
it('should download an encrypted folder', async () => {
81+
const invocation = await invokeTestCli(['upload', 'docs', '--encrypt', ...getStampOption()])
82+
const hash = (invocation.runnable as Upload).result.getOrThrow()
83+
expect(hash.toHex()).toHaveLength(128)
84+
await invokeTestCli(['download', hash.toHex()])
85+
expect(existsSync(hash.toHex())).toBe(true)
86+
const content = readdirSync(hash.toHex())
87+
expect(content.length).toBe(4)
88+
expect(content.includes('upload.gif')).toBe(true)
89+
expect(content.includes('stamp-buy.gif')).toBe(true)
90+
expect(content.includes('identity-create.gif')).toBe(true)
91+
expect(content.includes('feed-upload.gif')).toBe(true)
92+
})
6693
})

0 commit comments

Comments
 (0)