|
1 | | -import { mkdtempSync } from 'node:fs' |
| 1 | +import { Binary } from 'cafe-utility' |
| 2 | +import { existsSync, mkdtempSync, readdirSync, readFileSync } from 'node:fs' |
2 | 3 | import { tmpdir } from 'node:os' |
3 | 4 | import { join } from 'node:path' |
| 5 | +import { Addresses } from '../../src/command/addresses' |
4 | 6 | import { Upload } from '../../src/command/upload' |
5 | 7 | import { describeCommand, invokeTestCli } from '../utility' |
6 | 8 | import { getStampOption } from '../utility/stamp' |
7 | | -import { Addresses } from '../../src/command/addresses' |
8 | 9 |
|
9 | 10 | function makeTmpDir(): string { |
10 | 11 | return mkdtempSync(join(tmpdir(), 'swarm-cli-testrun-')) |
@@ -63,4 +64,30 @@ describeCommand('Test Download command', ({ consoleMessages }) => { |
63 | 64 | expect(consoleMessages.some(x => x.includes('index.html'))).toBe(true) |
64 | 65 | expect(consoleMessages.some(x => x.includes('swarm.bzz'))).toBe(true) |
65 | 66 | }) |
| 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 | + }) |
66 | 93 | }) |
0 commit comments