diff --git a/index.js b/index.js index d72e6f60..001a90b3 100644 --- a/index.js +++ b/index.js @@ -53,8 +53,12 @@ class Updates { async handle (req, res) { let segs = req.url.split(/[/?]/).filter(Boolean) const [account, repository, platform, version, file] = segs + if (!account || !repository || !platform || !version) { redirect(res, 'https://github.com/electron/update.electronjs.org') + } else if (platform !== 'darwin' && platform !== 'win32') { + const message = `Unsupported platform: "${platform}". Supported: darwin, win32.` + notFound(res, message) } else if (file === 'RELEASES') { await this.handleReleases(res, account, repository) } else { @@ -194,9 +198,9 @@ const assetPlatform = fileName => { return false } -const notFound = res => { +const notFound = (res, message = 'Not found') => { res.statusCode = 404 - res.end('Not found') + res.end(message) } const noContent = res => { diff --git a/test/index.js b/test/index.js index ed6fb795..107f9b09 100644 --- a/test/index.js +++ b/test/index.js @@ -255,6 +255,27 @@ test('Updates', async t => { } }) }) + + await t.test('Linux', async t => { + await t.test('not supported', async t => { + const res = await fetch(`${address}/owner/repo/linux/0.0.0`) + t.equal(res.status, 404) + const body = await res.text() + t.equal( + body, + 'Unsupported platform: "linux". Supported: darwin, win32.' + ) + }) + }) + + await t.test('Others', async t => { + await t.test('not supported', async t => { + const res = await fetch(`${address}/owner/repo/os/0.0.0`) + t.equal(res.status, 404) + const body = await res.text() + t.equal(body, 'Unsupported platform: "os". Supported: darwin, win32.') + }) + }) }) server.close()