fix: handle unicode filename and website uploads (#491)

* fix: print meaningful error message for invalid filenames

* fix: handle unicode dirnames and filenames

* chore: revert custom error message
This commit is contained in:
Cafe137
2022-07-26 13:13:25 +02:00
committed by GitHub
parent fd11f0166d
commit f82444f212
9 changed files with 167 additions and 7 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ async function selectStampAndUpload(page) {
}
async function assertUploadedContentAtPath(swarmHash, path, contentType) {
const response = await axios.get(`http://localhost:1633/bzz/${swarmHash}/${path}`)
const response = await axios.get(`http://localhost:1633/bzz/${swarmHash}/${encodeURI(path)}`)
if (response.status !== 200) {
throw new Error(`Expected 200 OK, got ${response.status}`)
+11 -1
View File
@@ -7,10 +7,20 @@ const { testImageFileUpload } = require('./test-case/ImageFileUpload')
const { testTextFileUpload } = require('./test-case/TextFileUpload')
const { testWebsiteUpload } = require('./test-case/WebsiteUpload')
const { testReactWebsiteUpload } = require('./test-case/ReactWebsiteUpload')
const { testUnicodeFileUpload } = require('./test-case/UnicodeFileUpload')
const { testUnicodeWebsiteUpload } = require('./test-case/UnicodeWebsiteUpload')
const VIEWPORT = { width: 1366, height: 768 }
const testCases = [testTextFileUpload, testImageFileUpload, testFolderUpload, testWebsiteUpload, testReactWebsiteUpload]
const testCases = [
testUnicodeFileUpload,
testUnicodeWebsiteUpload,
testTextFileUpload,
testImageFileUpload,
testFolderUpload,
testWebsiteUpload,
testReactWebsiteUpload,
]
async function main() {
const server = prepareServer()
+33
View File
@@ -0,0 +1,33 @@
const puppeteer = require('puppeteer')
const { selectStampAndUpload } = require('../helpers')
const { Assert, Click } = require('../library')
/**
* @param {puppeteer.Page} page Puppeteer Page object returned by `browser.newPage()`
*/
async function testUnicodeFileUpload(page) {
await Click.elementWithText(page, 'a', 'Files')
await Click.elementWithTextAndUpload(page, 'button', 'Add File', 'test-data/—𝖆𝖆🙇\\𝖈𝖈.txt')
await assertUploadPreview(page)
await selectStampAndUpload(page)
await assertDownloadPreview(page)
}
/**
* @param {puppeteer.Page} page Puppeteer Page object returned by `browser.newPage()`
*/
async function assertUploadPreview(page) {
await Assert.elementWithTextExists(page, 'p', 'Filename: —𝖆𝖆🙇\\𝖈𝖈.txt')
await Assert.elementWithTextExists(page, 'p', 'Kind: text/plain')
await Assert.elementWithTextExists(page, 'p', 'Size: 5.51 kB')
}
/**
* @param {puppeteer.Page} page Puppeteer Page object returned by `browser.newPage()`
*/
async function assertDownloadPreview(page) {
assertUploadPreview(page)
await Assert.elementWithTextExists(page, 'p', 'Swarm Hash: 30fbf1d2[…]ba400e86')
}
module.exports = { testUnicodeFileUpload }
+16
View File
@@ -0,0 +1,16 @@
const puppeteer = require('puppeteer')
const { selectStampAndUpload, assertUploadedContentAtPath } = require('../helpers')
const { Click } = require('../library')
/**
* @param {puppeteer.Page} page Puppeteer Page object returned by `browser.newPage()`
*/
async function testUnicodeWebsiteUpload(page) {
await Click.elementWithText(page, 'a', 'Files')
await Click.elementWithTextAndUpload(page, 'button', 'Add Website', 'test-data/test-unicode-website—𝖆𝖆🙇\\𝖈𝖈')
const swarmHash = await selectStampAndUpload(page)
await assertUploadedContentAtPath(swarmHash, 'index.html', 'text/html; charset=utf-8')
await assertUploadedContentAtPath(swarmHash, '—𝖆𝖆🙇/𝖈𝖈.txt', 'text/plain; charset=utf-8')
}
module.exports = { testUnicodeWebsiteUpload }