mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2024-12-23 08:46:28 +00:00
Compare commits
No commits in common. "a5809c216c2b401f7ae0aed28b1d6bef0abca072" and "fdc2722fb96cc85a902677d2d074af8377076ccd" have entirely different histories.
a5809c216c
...
fdc2722fb9
@ -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 chrome",
|
"test:local": "playwright test --project local",
|
||||||
"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, all: boolean, suggestedPassword?: string) {
|
export async function download(url: URL) {
|
||||||
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,9 +16,6 @@ export async function download(url: URL, all: boolean, suggestedPassword?: strin
|
|||||||
let password: string
|
let password: string
|
||||||
const derivation = preview?.meta.derivation
|
const derivation = preview?.meta.derivation
|
||||||
if (derivation) {
|
if (derivation) {
|
||||||
if (suggestedPassword) {
|
|
||||||
password = suggestedPassword
|
|
||||||
} else {
|
|
||||||
const response = await inquirer.prompt([
|
const response = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'password',
|
type: 'password',
|
||||||
@ -27,7 +24,6 @@ export async function download(url: URL, all: boolean, suggestedPassword?: strin
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
password = response.password
|
password = response.password
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
password = url.hash.slice(1)
|
password = url.hash.slice(1)
|
||||||
}
|
}
|
||||||
@ -43,11 +39,6 @@ export async function download(url: URL, all: boolean, suggestedPassword?: strin
|
|||||||
exit('No files found in note')
|
exit('No files found in note')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let selected: typeof files
|
|
||||||
if (all) {
|
|
||||||
selected = files
|
|
||||||
} else {
|
|
||||||
const { names } = await inquirer.prompt([
|
const { names } = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
@ -60,12 +51,13 @@ export async function download(url: URL, all: boolean, suggestedPassword?: strin
|
|||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
selected = files.filter((file) => names.includes(file.name))
|
|
||||||
}
|
const 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(
|
||||||
selected.map(async (file) => {
|
files.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
|
||||||
@ -76,7 +68,6 @@ export async function download(url: URL, all: boolean, suggestedPassword?: strin
|
|||||||
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,7 +15,6 @@ 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)
|
||||||
@ -87,13 +86,10 @@ 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)
|
||||||
options.password ||= await getStdin()
|
await download(url)
|
||||||
await download(url, options.all, options.password)
|
|
||||||
} catch {
|
} catch {
|
||||||
exit('Invalid URL')
|
exit('Invalid URL')
|
||||||
}
|
}
|
||||||
|
@ -2,23 +2,19 @@ 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 = ''
|
||||||
let t: NodeJS.Timeout
|
process.stdin.on('data', (d) => (buffer += d.toString()))
|
||||||
|
|
||||||
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
|
||||||
t = setTimeout(() => {
|
const t = setTimeout(() => {
|
||||||
process.stdin.removeListener('data', dataHandler)
|
process.stdin.destroy()
|
||||||
process.stdin.removeListener('end', endHandler)
|
|
||||||
process.stdin.pause()
|
|
||||||
resolve('')
|
resolve('')
|
||||||
}, timeout)
|
}, timeout)
|
||||||
|
|
||||||
process.stdin.on('data', dataHandler)
|
// Listen for end and error events
|
||||||
process.stdin.on('end', endHandler)
|
process.stdin.on('end', () => {
|
||||||
|
clearTimeout(t)
|
||||||
|
resolve(buffer.trim())
|
||||||
|
})
|
||||||
|
process.stdin.on('error', reject)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -47,13 +47,8 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<Switch
|
<Switch bind:value={customPassword} label={$t('home.advanced.custom_password')} />
|
||||||
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')}
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
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,23 +1,13 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { CLI, getLinkFromCLI } from '../../utils'
|
import { CLI } 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 = getLinkFromCLI(note.stdout)
|
const link = note.stdout.trim().replace(/(.|\s)*http/g, 'http')
|
||||||
|
|
||||||
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)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
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,15 +1,14 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { CLI, checkLinkForText, createNote, getLinkFromCLI } from '../../utils'
|
import { CLI, checkLinkForText, createNote } 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 = getLinkFromCLI(note.stdout)
|
const link = note.stdout.trim().replace(/(.|\s)*http/g, 'http')
|
||||||
|
|
||||||
await checkLinkForText(page, { link, text })
|
await checkLinkForText(page, link, text)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('web to cli', async ({ page }) => {
|
test('web to cli', async ({ page }) => {
|
||||||
@ -17,16 +16,4 @@ 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)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
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,25 +1,19 @@
|
|||||||
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 = {
|
type CreatePage = { text?: string; files?: string[]; views?: number; expiration?: number; error?: string }
|
||||||
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.getByTestId('text-field').fill(options.text)
|
await page.locator('[data-testid="text-field"]').fill(options.text)
|
||||||
} else if (options.files) {
|
} else if (options.files) {
|
||||||
await page.getByTestId('switch-file').click()
|
await page.locator('[data-testid="switch-file"]').click()
|
||||||
|
|
||||||
const [fileChooser] = await Promise.all([
|
const [fileChooser] = await Promise.all([
|
||||||
page.waitForEvent('filechooser'),
|
page.waitForEvent('filechooser'),
|
||||||
@ -28,16 +22,13 @@ 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.getByTestId('field-views').fill(options.views.toString())
|
await page.locator('[data-testid="switch-advanced"]').click()
|
||||||
|
await page.locator('[data-testid="field-views"]').fill(options.views.toString())
|
||||||
} else if (options.expiration) {
|
} else if (options.expiration) {
|
||||||
await page.getByTestId('switch-advanced-toggle').click()
|
await page.locator('[data-testid="switch-advanced"]').click()
|
||||||
await page.getByTestId('field-expiration').fill(options.expiration.toString())
|
await page.locator('[data-testid="switch-advanced-toggle"]').click()
|
||||||
}
|
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()
|
||||||
@ -46,39 +37,29 @@ 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 })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return share link
|
const shareLink = await page.locator('[data-testid="share-link"]').inputValue()
|
||||||
return await page.getByTestId('share-link').inputValue()
|
return shareLink
|
||||||
}
|
}
|
||||||
|
|
||||||
type CheckLinkBase = {
|
export async function checkLinkForDownload(page: Page, link: string, text: string, checksum: string) {
|
||||||
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(options.link)
|
await page.goto(link)
|
||||||
if (options.password) await page.getByTestId('show-note-password').fill(options.password)
|
await page.locator('[data-testid="show-note-button"]').click()
|
||||||
await page.getByTestId('show-note-button').click()
|
|
||||||
|
|
||||||
const [download] = await Promise.all([
|
const [download] = await Promise.all([
|
||||||
page.waitForEvent('download'),
|
page.waitForEvent('download'),
|
||||||
page.getByTestId(`result`).locator(`text=${options.text}`).click(),
|
page.locator(`[data-testid="result"] >> text=${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(options.checksum)
|
await expect(cs).toBe(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(options.link)
|
await page.goto(link)
|
||||||
if (options.password) await page.getByTestId('show-note-password').fill(options.password)
|
await page.locator('[data-testid="show-note-button"]').click()
|
||||||
await page.getByTestId('show-note-button').click()
|
await expect(await page.locator('[data-testid="result"] >> .note').innerText()).toContain(text)
|
||||||
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) {
|
||||||
@ -87,6 +68,12 @@ 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: {
|
||||||
@ -95,9 +82,3 @@ 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]
|
|
||||||
}
|
|
||||||
|
5
test/web/file/files.ts
Normal file
5
test/web/file/files.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
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 { Files, getFileChecksum } from '../../files'
|
import { checkLinkForDownload, createNote, getFileChecksum } from '../../utils'
|
||||||
import { checkLinkForDownload, createNote } from '../../utils'
|
import Files from './files'
|
||||||
|
|
||||||
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, text: 'image.jpg', checksum: checksums[1] })
|
await checkLinkForDownload(page, link, 'image.jpg', checksums[1])
|
||||||
await checkLinkForDownload(page, { link, text: 'AES.pdf', checksum: checksums[0] })
|
await checkLinkForDownload(page, link, 'AES.pdf', checksums[0])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { test } from '@playwright/test'
|
import { test } from '@playwright/test'
|
||||||
import { Files, getFileChecksum } from '../../files'
|
import { checkLinkDoesNotExist, checkLinkForDownload, checkLinkForText, createNote, getFileChecksum } from '../../utils'
|
||||||
import { checkLinkDoesNotExist, checkLinkForDownload, checkLinkForText, createNote } from '../../utils'
|
import Files from './files'
|
||||||
|
|
||||||
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, text: 'AES.pdf' })
|
await checkLinkForText(page, link, 'AES.pdf')
|
||||||
await checkLinkDoesNotExist(page, link)
|
await checkLinkDoesNotExist(page, link)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -14,21 +14,13 @@ 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, text: 'AES.pdf', checksum })
|
await checkLinkForDownload(page, link, '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, text: 'image.jpg', checksum })
|
await checkLinkForDownload(page, link, '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 link = await createNote(page, { text, expiration: minutes })
|
const shareLink = await createNote(page, { text, expiration: minutes })
|
||||||
await checkLinkForText(page, { link, text })
|
await checkLinkForText(page, shareLink, text)
|
||||||
await checkLinkForText(page, { link, text })
|
await checkLinkForText(page, shareLink, text)
|
||||||
await page.waitForTimeout(timeout)
|
await page.waitForTimeout(timeout)
|
||||||
await checkLinkDoesNotExist(page, link)
|
await checkLinkDoesNotExist(page, shareLink)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -3,15 +3,8 @@ 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 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 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 link = await createNote(page, { text })
|
const shareLink = await createNote(page, { text })
|
||||||
await checkLinkForText(page, { link, text })
|
await checkLinkForText(page, shareLink, 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 link = await createNote(page, { text })
|
const shareLink = await createNote(page, { text })
|
||||||
await checkLinkForText(page, { link, text })
|
await checkLinkForText(page, shareLink, text)
|
||||||
await checkLinkDoesNotExist(page, link)
|
await checkLinkDoesNotExist(page, shareLink)
|
||||||
})
|
})
|
||||||
|
|
||||||
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 link = await createNote(page, { text, views: 3 })
|
const shareLink = await createNote(page, { text, views: 3 })
|
||||||
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 checkLinkForText(page, shareLink, text)
|
||||||
await checkLinkDoesNotExist(page, link)
|
await checkLinkDoesNotExist(page, shareLink)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user