mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2024-12-22 16:26:28 +00:00
Compare commits
4 Commits
fdc2722fb9
...
a5809c216c
Author | SHA1 | Date | |
---|---|---|---|
a5809c216c | |||
fb95a68b0d | |||
b43b802221 | |||
2e89007c83 |
@ -7,7 +7,7 @@
|
|||||||
"docker:up": "docker compose -f docker-compose.dev.yaml up",
|
"docker:up": "docker compose -f docker-compose.dev.yaml up",
|
||||||
"docker:build": "docker compose -f docker-compose.dev.yaml build",
|
"docker:build": "docker compose -f docker-compose.dev.yaml build",
|
||||||
"test": "playwright test --project chrome firefox safari",
|
"test": "playwright test --project chrome firefox safari",
|
||||||
"test:local": "playwright test --project local",
|
"test:local": "playwright test --project chrome",
|
||||||
"test:server": "run-s docker:up",
|
"test:server": "run-s docker:up",
|
||||||
"test:prepare": "run-p build docker:build",
|
"test:prepare": "run-p build docker:build",
|
||||||
"build": "pnpm run --recursive --filter=!@cryptgeon/backend build"
|
"build": "pnpm run --recursive --filter=!@cryptgeon/backend build"
|
||||||
|
@ -7,7 +7,7 @@ import pretty from 'pretty-bytes'
|
|||||||
|
|
||||||
import { exit } from './utils'
|
import { exit } from './utils'
|
||||||
|
|
||||||
export async function download(url: URL) {
|
export async function download(url: URL, all: boolean, suggestedPassword?: string) {
|
||||||
setBase(url.origin)
|
setBase(url.origin)
|
||||||
const id = url.pathname.split('/')[2]
|
const id = url.pathname.split('/')[2]
|
||||||
const preview = await info(id).catch(() => exit('Note does not exist or is expired'))
|
const preview = await info(id).catch(() => exit('Note does not exist or is expired'))
|
||||||
@ -16,14 +16,18 @@ export async function download(url: URL) {
|
|||||||
let password: string
|
let password: string
|
||||||
const derivation = preview?.meta.derivation
|
const derivation = preview?.meta.derivation
|
||||||
if (derivation) {
|
if (derivation) {
|
||||||
const response = await inquirer.prompt([
|
if (suggestedPassword) {
|
||||||
{
|
password = suggestedPassword
|
||||||
type: 'password',
|
} else {
|
||||||
message: 'Note password',
|
const response = await inquirer.prompt([
|
||||||
name: 'password',
|
{
|
||||||
},
|
type: 'password',
|
||||||
])
|
message: 'Note password',
|
||||||
password = response.password
|
name: 'password',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
password = response.password
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
password = url.hash.slice(1)
|
password = url.hash.slice(1)
|
||||||
}
|
}
|
||||||
@ -39,25 +43,29 @@ export async function download(url: URL) {
|
|||||||
exit('No files found in note')
|
exit('No files found in note')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const { names } = await inquirer.prompt([
|
|
||||||
{
|
|
||||||
type: 'checkbox',
|
|
||||||
message: 'What files should be saved?',
|
|
||||||
name: 'names',
|
|
||||||
choices: files.map((file) => ({
|
|
||||||
value: file.name,
|
|
||||||
name: `${file.name} - ${file.type} - ${pretty(file.size, { binary: true })}`,
|
|
||||||
checked: true,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const selected = files.filter((file) => names.includes(file.name))
|
let selected: typeof files
|
||||||
|
if (all) {
|
||||||
|
selected = files
|
||||||
|
} else {
|
||||||
|
const { names } = await inquirer.prompt([
|
||||||
|
{
|
||||||
|
type: 'checkbox',
|
||||||
|
message: 'What files should be saved?',
|
||||||
|
name: 'names',
|
||||||
|
choices: files.map((file) => ({
|
||||||
|
value: file.name,
|
||||||
|
name: `${file.name} - ${file.type} - ${pretty(file.size, { binary: true })}`,
|
||||||
|
checked: true,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
])
|
||||||
|
selected = files.filter((file) => names.includes(file.name))
|
||||||
|
}
|
||||||
|
|
||||||
if (!selected.length) exit('No files selected')
|
if (!selected.length) exit('No files selected')
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
files.map(async (file) => {
|
selected.map(async (file) => {
|
||||||
let filename = resolve(file.name)
|
let filename = resolve(file.name)
|
||||||
try {
|
try {
|
||||||
// If exists -> prepend timestamp to not overwrite the current file
|
// If exists -> prepend timestamp to not overwrite the current file
|
||||||
@ -68,6 +76,7 @@ export async function download(url: URL) {
|
|||||||
console.log(`Saved: ${basename(filename)}`)
|
console.log(`Saved: ${basename(filename)}`)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
break
|
break
|
||||||
case 'text':
|
case 'text':
|
||||||
const plaintext = await Adapters.Text.decrypt(note.contents, key).catch(couldNotDecrypt)
|
const plaintext = await Adapters.Text.decrypt(note.contents, key).catch(couldNotDecrypt)
|
||||||
|
@ -15,6 +15,7 @@ const server = new Option('-s --server <url>', 'the cryptgeon server to use').de
|
|||||||
const files = new Argument('<file...>', 'Files to be sent').argParser(parseFile)
|
const files = new Argument('<file...>', 'Files to be sent').argParser(parseFile)
|
||||||
const text = new Argument('<text>', 'Text content of the note')
|
const text = new Argument('<text>', 'Text content of the note')
|
||||||
const password = new Option('-p --password <string>', 'manually set a password')
|
const password = new Option('-p --password <string>', 'manually set a password')
|
||||||
|
const all = new Option('-a --all', 'Save all files without prompt').default(false)
|
||||||
const url = new Argument('<url>', 'The url to open')
|
const url = new Argument('<url>', 'The url to open')
|
||||||
const views = new Option('-v --views <number>', 'Amount of views before getting destroyed').argParser(parseNumber)
|
const views = new Option('-v --views <number>', 'Amount of views before getting destroyed').argParser(parseNumber)
|
||||||
const minutes = new Option('-m --minutes <number>', 'Minutes before the note expires').argParser(parseNumber)
|
const minutes = new Option('-m --minutes <number>', 'Minutes before the note expires').argParser(parseNumber)
|
||||||
@ -86,10 +87,13 @@ send
|
|||||||
program
|
program
|
||||||
.command('open')
|
.command('open')
|
||||||
.addArgument(url)
|
.addArgument(url)
|
||||||
|
.addOption(password)
|
||||||
|
.addOption(all)
|
||||||
.action(async (note, options) => {
|
.action(async (note, options) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(note)
|
const url = new URL(note)
|
||||||
await download(url)
|
options.password ||= await getStdin()
|
||||||
|
await download(url, options.all, options.password)
|
||||||
} catch {
|
} catch {
|
||||||
exit('Invalid URL')
|
exit('Invalid URL')
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,23 @@ export function getStdin(timeout: number = 10): Promise<string> {
|
|||||||
return new Promise<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
// Store the data from stdin in a buffer
|
// Store the data from stdin in a buffer
|
||||||
let buffer = ''
|
let buffer = ''
|
||||||
process.stdin.on('data', (d) => (buffer += d.toString()))
|
let t: NodeJS.Timeout
|
||||||
|
|
||||||
|
const dataHandler = (d: Buffer) => (buffer += d.toString())
|
||||||
|
const endHandler = () => {
|
||||||
|
clearTimeout(t)
|
||||||
|
resolve(buffer.trim())
|
||||||
|
}
|
||||||
|
|
||||||
// Stop listening for data after the timeout, otherwise hangs indefinitely
|
// Stop listening for data after the timeout, otherwise hangs indefinitely
|
||||||
const t = setTimeout(() => {
|
t = setTimeout(() => {
|
||||||
process.stdin.destroy()
|
process.stdin.removeListener('data', dataHandler)
|
||||||
|
process.stdin.removeListener('end', endHandler)
|
||||||
|
process.stdin.pause()
|
||||||
resolve('')
|
resolve('')
|
||||||
}, timeout)
|
}, timeout)
|
||||||
|
|
||||||
// Listen for end and error events
|
process.stdin.on('data', dataHandler)
|
||||||
process.stdin.on('end', () => {
|
process.stdin.on('end', endHandler)
|
||||||
clearTimeout(t)
|
|
||||||
resolve(buffer.trim())
|
|
||||||
})
|
|
||||||
process.stdin.on('error', reject)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,13 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<Switch bind:value={customPassword} label={$t('home.advanced.custom_password')} />
|
<Switch
|
||||||
|
data-testid="custom-password"
|
||||||
|
bind:value={customPassword}
|
||||||
|
label={$t('home.advanced.custom_password')}
|
||||||
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
|
data-testid="password"
|
||||||
type="password"
|
type="password"
|
||||||
bind:value={note.password}
|
bind:value={note.password}
|
||||||
label={$t('common.password')}
|
label={$t('common.password')}
|
||||||
|
33
test/cli/file/simple.spec.ts
Normal file
33
test/cli/file/simple.spec.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { test } from '@playwright/test'
|
||||||
|
import { basename } from 'node:path'
|
||||||
|
import { Files, getFileChecksum, rm, tmpFile } from '../../files'
|
||||||
|
import { CLI, getLinkFromCLI } from '../../utils'
|
||||||
|
|
||||||
|
test.describe('file @cli', () => {
|
||||||
|
test('simple', async ({ page }) => {
|
||||||
|
const file = await tmpFile(Files.Image)
|
||||||
|
const checksum = await getFileChecksum(file)
|
||||||
|
const note = await CLI('send', 'file', file)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
await rm(file)
|
||||||
|
|
||||||
|
await CLI('open', link, '--all')
|
||||||
|
const c = await getFileChecksum(basename(file))
|
||||||
|
await rm(basename(file))
|
||||||
|
test.expect(checksum).toBe(c)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('simple with password', async ({ page }) => {
|
||||||
|
const file = await tmpFile(Files.Image)
|
||||||
|
const password = 'password'
|
||||||
|
const checksum = await getFileChecksum(file)
|
||||||
|
const note = await CLI('send', 'file', file, '--password', password)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
await rm(file)
|
||||||
|
|
||||||
|
await CLI('open', link, '--all', '--password', password)
|
||||||
|
const c = await getFileChecksum(basename(file))
|
||||||
|
await rm(basename(file))
|
||||||
|
test.expect(checksum).toBe(c)
|
||||||
|
})
|
||||||
|
})
|
@ -1,13 +1,23 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { CLI } from '../../utils'
|
import { CLI, getLinkFromCLI } from '../../utils'
|
||||||
|
|
||||||
test.describe('text @cli', () => {
|
test.describe('text @cli', () => {
|
||||||
test('simple', async ({ page }) => {
|
test('simple', async ({ page }) => {
|
||||||
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||||
const note = await CLI('send', 'text', text)
|
const note = await CLI('send', 'text', text)
|
||||||
const link = note.stdout.trim().replace(/(.|\s)*http/g, 'http')
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
|
||||||
const retrieved = await CLI('open', link)
|
const retrieved = await CLI('open', link)
|
||||||
test.expect(retrieved.stdout.trim()).toBe(text)
|
test.expect(retrieved.stdout.trim()).toBe(text)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('simple with password', async ({ page }) => {
|
||||||
|
const text = `Endless prejudice endless play derive joy eternal-return selfish burying.`
|
||||||
|
const password = 'password'
|
||||||
|
const note = await CLI('send', 'text', text, '--password', password)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
|
||||||
|
const retrieved = await CLI('open', link, '--password', password)
|
||||||
|
test.expect(retrieved.stdout.trim()).toBe(text)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
53
test/cross/file/simple.spec.ts
Normal file
53
test/cross/file/simple.spec.ts
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { test } from '@playwright/test'
|
||||||
|
import { CLI, checkLinkForDownload, checkLinkForText, createNote, getLinkFromCLI } from '../../utils'
|
||||||
|
import { Files, getFileChecksum, rm, tmpFile } from '../../files'
|
||||||
|
import { basename } from 'path'
|
||||||
|
|
||||||
|
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||||
|
const password = 'password'
|
||||||
|
|
||||||
|
test.describe('text @cross', () => {
|
||||||
|
test('cli to web', async ({ page }) => {
|
||||||
|
const file = await tmpFile(Files.Image)
|
||||||
|
const checksum = await getFileChecksum(file)
|
||||||
|
const note = await CLI('send', 'file', file)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
await rm(file)
|
||||||
|
|
||||||
|
await checkLinkForDownload(page, { link, text: basename(file), checksum })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('cli to web with password', async ({ page }) => {
|
||||||
|
const file = await tmpFile(Files.Image)
|
||||||
|
const checksum = await getFileChecksum(file)
|
||||||
|
const note = await CLI('send', 'file', file, '--password', password)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
await rm(file)
|
||||||
|
|
||||||
|
await checkLinkForDownload(page, { link, text: basename(file), checksum, password })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('web to cli', async ({ page }) => {
|
||||||
|
const files = [Files.Image]
|
||||||
|
const checksum = await getFileChecksum(files[0])
|
||||||
|
const link = await createNote(page, { files })
|
||||||
|
|
||||||
|
const filename = basename(files[0])
|
||||||
|
await CLI('open', link, '--all')
|
||||||
|
const c = await getFileChecksum(filename)
|
||||||
|
await rm(basename(filename))
|
||||||
|
test.expect(checksum).toBe(c)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('web to cli with password', async ({ page }) => {
|
||||||
|
const files = [Files.Image]
|
||||||
|
const checksum = await getFileChecksum(files[0])
|
||||||
|
const link = await createNote(page, { files, password })
|
||||||
|
|
||||||
|
const filename = basename(files[0])
|
||||||
|
await CLI('open', link, '--all', '--password', password)
|
||||||
|
const c = await getFileChecksum(filename)
|
||||||
|
await rm(basename(filename))
|
||||||
|
test.expect(checksum).toBe(c)
|
||||||
|
})
|
||||||
|
})
|
@ -1,14 +1,15 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { CLI, checkLinkForText, createNote } from '../../utils'
|
import { CLI, checkLinkForText, createNote, getLinkFromCLI } from '../../utils'
|
||||||
|
|
||||||
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||||
|
const password = 'password'
|
||||||
|
|
||||||
test.describe('text @cross', () => {
|
test.describe('text @cross', () => {
|
||||||
test('cli to web', async ({ page }) => {
|
test('cli to web', async ({ page }) => {
|
||||||
const note = await CLI('send', 'text', text)
|
const note = await CLI('send', 'text', text)
|
||||||
const link = note.stdout.trim().replace(/(.|\s)*http/g, 'http')
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
|
||||||
await checkLinkForText(page, link, text)
|
await checkLinkForText(page, { link, text })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('web to cli', async ({ page }) => {
|
test('web to cli', async ({ page }) => {
|
||||||
@ -16,4 +17,16 @@ test.describe('text @cross', () => {
|
|||||||
const retrieved = await CLI('open', link)
|
const retrieved = await CLI('open', link)
|
||||||
test.expect(retrieved.stdout.trim()).toBe(text)
|
test.expect(retrieved.stdout.trim()).toBe(text)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('cli to web with password', async ({ page }) => {
|
||||||
|
const note = await CLI('send', 'text', text, '--password', password)
|
||||||
|
const link = getLinkFromCLI(note.stdout)
|
||||||
|
await checkLinkForText(page, { link, text, password })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('web to cli with password', async ({ page }) => {
|
||||||
|
const link = await createNote(page, { text, password })
|
||||||
|
const retrieved = await CLI('open', link, '--password', password)
|
||||||
|
test.expect(retrieved.stdout.trim()).toBe(text)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
25
test/files.ts
Normal file
25
test/files.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { createHash } from 'crypto'
|
||||||
|
import { cp as cpFN, rm as rmFN } from 'fs'
|
||||||
|
import { readFile } from 'fs/promises'
|
||||||
|
import { promisify } from 'util'
|
||||||
|
|
||||||
|
export const cp = promisify(cpFN)
|
||||||
|
export const rm = promisify(rmFN)
|
||||||
|
|
||||||
|
export const Files = {
|
||||||
|
PDF: 'test/assets/AES.pdf',
|
||||||
|
Image: 'test/assets/image.jpg',
|
||||||
|
Zip: 'test/assets/Pigeons.zip',
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getFileChecksum(file: string) {
|
||||||
|
const buffer = await readFile(file)
|
||||||
|
const hash = createHash('sha3-256').update(buffer).digest('hex')
|
||||||
|
return hash
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function tmpFile(file: string) {
|
||||||
|
const name = `./tmp/${Math.random().toString(36).substring(7)}`
|
||||||
|
await cp(file, name)
|
||||||
|
return name
|
||||||
|
}
|
@ -1,19 +1,25 @@
|
|||||||
import { expect, type Page } from '@playwright/test'
|
import { expect, type Page } from '@playwright/test'
|
||||||
import { createHash } from 'crypto'
|
|
||||||
import { readFile } from 'fs/promises'
|
|
||||||
import { execFile } from 'node:child_process'
|
import { execFile } from 'node:child_process'
|
||||||
import { promisify } from 'node:util'
|
import { promisify } from 'node:util'
|
||||||
|
import { getFileChecksum } from './files'
|
||||||
|
|
||||||
const exec = promisify(execFile)
|
const exec = promisify(execFile)
|
||||||
|
|
||||||
type CreatePage = { text?: string; files?: string[]; views?: number; expiration?: number; error?: string }
|
type CreatePage = {
|
||||||
|
text?: string
|
||||||
|
files?: string[]
|
||||||
|
views?: number
|
||||||
|
expiration?: number
|
||||||
|
error?: string
|
||||||
|
password?: string
|
||||||
|
}
|
||||||
export async function createNote(page: Page, options: CreatePage): Promise<string> {
|
export async function createNote(page: Page, options: CreatePage): Promise<string> {
|
||||||
await page.goto('/')
|
await page.goto('/')
|
||||||
|
|
||||||
if (options.text) {
|
if (options.text) {
|
||||||
await page.locator('[data-testid="text-field"]').fill(options.text)
|
await page.getByTestId('text-field').fill(options.text)
|
||||||
} else if (options.files) {
|
} else if (options.files) {
|
||||||
await page.locator('[data-testid="switch-file"]').click()
|
await page.getByTestId('switch-file').click()
|
||||||
|
|
||||||
const [fileChooser] = await Promise.all([
|
const [fileChooser] = await Promise.all([
|
||||||
page.waitForEvent('filechooser'),
|
page.waitForEvent('filechooser'),
|
||||||
@ -22,13 +28,16 @@ export async function createNote(page: Page, options: CreatePage): Promise<strin
|
|||||||
await fileChooser.setFiles(options.files)
|
await fileChooser.setFiles(options.files)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.views || options.expiration || options.password) await page.getByTestId('switch-advanced').click()
|
||||||
if (options.views) {
|
if (options.views) {
|
||||||
await page.locator('[data-testid="switch-advanced"]').click()
|
await page.getByTestId('field-views').fill(options.views.toString())
|
||||||
await page.locator('[data-testid="field-views"]').fill(options.views.toString())
|
|
||||||
} else if (options.expiration) {
|
} else if (options.expiration) {
|
||||||
await page.locator('[data-testid="switch-advanced"]').click()
|
await page.getByTestId('switch-advanced-toggle').click()
|
||||||
await page.locator('[data-testid="switch-advanced-toggle"]').click()
|
await page.getByTestId('field-expiration').fill(options.expiration.toString())
|
||||||
await page.locator('[data-testid="field-expiration"]').fill(options.expiration.toString())
|
}
|
||||||
|
if (options.password) {
|
||||||
|
await page.getByTestId('custom-password').click()
|
||||||
|
await page.getByTestId('password').fill(options.password)
|
||||||
}
|
}
|
||||||
|
|
||||||
await page.locator('button:has-text("create")').click()
|
await page.locator('button:has-text("create")').click()
|
||||||
@ -37,29 +46,39 @@ export async function createNote(page: Page, options: CreatePage): Promise<strin
|
|||||||
await expect(page.locator('.error-text')).toContainText(options.error, { timeout: 60_000 })
|
await expect(page.locator('.error-text')).toContainText(options.error, { timeout: 60_000 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const shareLink = await page.locator('[data-testid="share-link"]').inputValue()
|
// Return share link
|
||||||
return shareLink
|
return await page.getByTestId('share-link').inputValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkLinkForDownload(page: Page, link: string, text: string, checksum: string) {
|
type CheckLinkBase = {
|
||||||
|
link: string
|
||||||
|
text: string
|
||||||
|
password?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function checkLinkForDownload(page: Page, options: CheckLinkBase & { checksum: string }) {
|
||||||
await page.goto('/')
|
await page.goto('/')
|
||||||
await page.goto(link)
|
await page.goto(options.link)
|
||||||
await page.locator('[data-testid="show-note-button"]').click()
|
if (options.password) await page.getByTestId('show-note-password').fill(options.password)
|
||||||
|
await page.getByTestId('show-note-button').click()
|
||||||
|
|
||||||
const [download] = await Promise.all([
|
const [download] = await Promise.all([
|
||||||
page.waitForEvent('download'),
|
page.waitForEvent('download'),
|
||||||
page.locator(`[data-testid="result"] >> text=${text}`).click(),
|
page.getByTestId(`result`).locator(`text=${options.text}`).click(),
|
||||||
])
|
])
|
||||||
const path = await download.path()
|
const path = await download.path()
|
||||||
if (!path) throw new Error('Download failed')
|
if (!path) throw new Error('Download failed')
|
||||||
const cs = await getFileChecksum(path)
|
const cs = await getFileChecksum(path)
|
||||||
await expect(cs).toBe(checksum)
|
await expect(cs).toBe(options.checksum)
|
||||||
}
|
}
|
||||||
export async function checkLinkForText(page: Page, link: string, text: string) {
|
|
||||||
|
export async function checkLinkForText(page: Page, options: CheckLinkBase) {
|
||||||
await page.goto('/')
|
await page.goto('/')
|
||||||
await page.goto(link)
|
await page.goto(options.link)
|
||||||
await page.locator('[data-testid="show-note-button"]').click()
|
if (options.password) await page.getByTestId('show-note-password').fill(options.password)
|
||||||
await expect(await page.locator('[data-testid="result"] >> .note').innerText()).toContain(text)
|
await page.getByTestId('show-note-button').click()
|
||||||
|
const text = await page.getByTestId('result').locator('.note').innerText()
|
||||||
|
await expect(text).toContain(options.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkLinkDoesNotExist(page: Page, link: string) {
|
export async function checkLinkDoesNotExist(page: Page, link: string) {
|
||||||
@ -68,12 +87,6 @@ export async function checkLinkDoesNotExist(page: Page, link: string) {
|
|||||||
await expect(page.locator('main')).toContainText('note was not found or was already deleted')
|
await expect(page.locator('main')).toContainText('note was not found or was already deleted')
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getFileChecksum(file: string) {
|
|
||||||
const buffer = await readFile(file)
|
|
||||||
const hash = createHash('sha3-256').update(buffer).digest('hex')
|
|
||||||
return hash
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function CLI(...args: string[]) {
|
export async function CLI(...args: string[]) {
|
||||||
return await exec('./packages/cli/dist/index.cjs', args, {
|
return await exec('./packages/cli/dist/index.cjs', args, {
|
||||||
env: {
|
env: {
|
||||||
@ -82,3 +95,9 @@ export async function CLI(...args: string[]) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getLinkFromCLI(output: string): string {
|
||||||
|
const match = output.match(/(https?:\/\/[^\s]+)/)
|
||||||
|
if (!match) throw new Error('No link found in CLI output')
|
||||||
|
return match[0]
|
||||||
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
export default {
|
|
||||||
PDF: 'test/assets/AES.pdf',
|
|
||||||
Image: 'test/assets/image.jpg',
|
|
||||||
Zip: 'test/assets/Pigeons.zip',
|
|
||||||
}
|
|
@ -1,13 +1,13 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { checkLinkForDownload, createNote, getFileChecksum } from '../../utils'
|
import { Files, getFileChecksum } from '../../files'
|
||||||
import Files from './files'
|
import { checkLinkForDownload, createNote } from '../../utils'
|
||||||
|
|
||||||
test.describe('@web', () => {
|
test.describe('@web', () => {
|
||||||
test('multiple', async ({ page }) => {
|
test('multiple', async ({ page }) => {
|
||||||
const files = [Files.PDF, Files.Image]
|
const files = [Files.PDF, Files.Image]
|
||||||
const checksums = await Promise.all(files.map(getFileChecksum))
|
const checksums = await Promise.all(files.map(getFileChecksum))
|
||||||
const link = await createNote(page, { files, views: 2 })
|
const link = await createNote(page, { files, views: 2 })
|
||||||
await checkLinkForDownload(page, link, 'image.jpg', checksums[1])
|
await checkLinkForDownload(page, { link, text: 'image.jpg', checksum: checksums[1] })
|
||||||
await checkLinkForDownload(page, link, 'AES.pdf', checksums[0])
|
await checkLinkForDownload(page, { link, text: 'AES.pdf', checksum: checksums[0] })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { checkLinkDoesNotExist, checkLinkForDownload, checkLinkForText, createNote, getFileChecksum } from '../../utils'
|
import { Files, getFileChecksum } from '../../files'
|
||||||
import Files from './files'
|
import { checkLinkDoesNotExist, checkLinkForDownload, checkLinkForText, createNote } from '../../utils'
|
||||||
|
|
||||||
test.describe('@web', () => {
|
test.describe('@web', () => {
|
||||||
test('simple pdf', async ({ page }) => {
|
test('simple pdf', async ({ page }) => {
|
||||||
const files = [Files.PDF]
|
const files = [Files.PDF]
|
||||||
const link = await createNote(page, { files })
|
const link = await createNote(page, { files })
|
||||||
await checkLinkForText(page, link, 'AES.pdf')
|
await checkLinkForText(page, { link, text: 'AES.pdf' })
|
||||||
await checkLinkDoesNotExist(page, link)
|
await checkLinkDoesNotExist(page, link)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -14,13 +14,21 @@ test.describe('@web', () => {
|
|||||||
const files = [Files.PDF]
|
const files = [Files.PDF]
|
||||||
const checksum = await getFileChecksum(files[0])
|
const checksum = await getFileChecksum(files[0])
|
||||||
const link = await createNote(page, { files })
|
const link = await createNote(page, { files })
|
||||||
await checkLinkForDownload(page, link, 'AES.pdf', checksum)
|
await checkLinkForDownload(page, { link, text: 'AES.pdf', checksum })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('image content', async ({ page }) => {
|
test('image content', async ({ page }) => {
|
||||||
const files = [Files.Image]
|
const files = [Files.Image]
|
||||||
const checksum = await getFileChecksum(files[0])
|
const checksum = await getFileChecksum(files[0])
|
||||||
const link = await createNote(page, { files })
|
const link = await createNote(page, { files })
|
||||||
await checkLinkForDownload(page, link, 'image.jpg', checksum)
|
await checkLinkForDownload(page, { link, text: 'image.jpg', checksum })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('simple pdf with password', async ({ page }) => {
|
||||||
|
const files = [Files.PDF]
|
||||||
|
const password = 'password'
|
||||||
|
const link = await createNote(page, { files, password })
|
||||||
|
await checkLinkForText(page, { link, text: 'AES.pdf', password })
|
||||||
|
await checkLinkDoesNotExist(page, link)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { createNote } from '../../utils'
|
import { createNote } from '../../utils'
|
||||||
import Files from './files'
|
import { Files } from '../../files'
|
||||||
|
|
||||||
test.describe('@web', () => {
|
test.describe('@web', () => {
|
||||||
test.skip('to big zip', async ({ page }) => {
|
test.skip('to big zip', async ({ page }) => {
|
||||||
|
@ -7,10 +7,10 @@ test.describe('@web', () => {
|
|||||||
const minutes = 1
|
const minutes = 1
|
||||||
const timeout = minutes * 60_000
|
const timeout = minutes * 60_000
|
||||||
test.setTimeout(timeout * 2)
|
test.setTimeout(timeout * 2)
|
||||||
const shareLink = await createNote(page, { text, expiration: minutes })
|
const link = await createNote(page, { text, expiration: minutes })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await page.waitForTimeout(timeout)
|
await page.waitForTimeout(timeout)
|
||||||
await checkLinkDoesNotExist(page, shareLink)
|
await checkLinkDoesNotExist(page, link)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -3,8 +3,15 @@ import { checkLinkForText, createNote } from '../../utils'
|
|||||||
|
|
||||||
test.describe('@web', () => {
|
test.describe('@web', () => {
|
||||||
test('simple', async ({ page }) => {
|
test('simple', async ({ page }) => {
|
||||||
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of decieve play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
const text = `Endless prejudice endless play derive joy eternal-return selfish burying. Of deceive play pinnacle faith disgust. Spirit reason salvation burying strong of joy ascetic selfish against merciful sea truth. Ubermensch moral prejudice derive chaos mountains ubermensch justice philosophy justice ultimate joy ultimate transvaluation. Virtues convictions war ascetic eternal-return spirit. Ubermensch transvaluation noble revaluation sexuality intentions salvation endless decrepit hope noble fearful. Justice ideal ultimate snare god joy evil sexuality insofar gains oneself ideal.`
|
||||||
const shareLink = await createNote(page, { text })
|
const link = await createNote(page, { text })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('simple with password', async ({ page }) => {
|
||||||
|
const text = 'Foo bar'
|
||||||
|
const password = '123'
|
||||||
|
const shareLink = await createNote(page, { text, password })
|
||||||
|
await checkLinkForText(page, { link: shareLink, text, password })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -4,17 +4,17 @@ import { checkLinkDoesNotExist, checkLinkForText, createNote } from '../../utils
|
|||||||
test.describe('@web', () => {
|
test.describe('@web', () => {
|
||||||
test('only shown once', async ({ page }) => {
|
test('only shown once', async ({ page }) => {
|
||||||
const text = `Christian victorious reason suicide dead. Right ultimate gains god hope truth burying selfish society joy. Ultimate.`
|
const text = `Christian victorious reason suicide dead. Right ultimate gains god hope truth burying selfish society joy. Ultimate.`
|
||||||
const shareLink = await createNote(page, { text })
|
const link = await createNote(page, { text })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await checkLinkDoesNotExist(page, shareLink)
|
await checkLinkDoesNotExist(page, link)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('view 3 times', async ({ page }) => {
|
test('view 3 times', async ({ page }) => {
|
||||||
const text = `Justice holiest overcome fearful strong ultimate holiest christianity.`
|
const text = `Justice holiest overcome fearful strong ultimate holiest christianity.`
|
||||||
const shareLink = await createNote(page, { text, views: 3 })
|
const link = await createNote(page, { text, views: 3 })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await checkLinkForText(page, shareLink, text)
|
await checkLinkForText(page, { link, text })
|
||||||
await checkLinkDoesNotExist(page, shareLink)
|
await checkLinkDoesNotExist(page, link)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user