Skip to content

Commit

Permalink
Merge pull request #48 from electron/fix/invalid-semver
Browse files Browse the repository at this point in the history
fix handling of invalid semvers. closes #47
  • Loading branch information
juliangruber authored May 15, 2018
2 parents 325281e + 14a0f61 commit 2f24074
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Updates {
} else if (platform !== 'darwin' && platform !== 'win32') {
const message = `Unsupported platform: "${platform}". Supported: darwin, win32.`
notFound(res, message)
} else if (version && !semver.valid(version)) {
badRequest(res, `Invalid SemVer: "${version}"`)
} else if (file === 'RELEASES') {
await this.handleReleases(res, account, repository)
} else {
Expand Down Expand Up @@ -203,6 +205,11 @@ const notFound = (res, message = 'Not found') => {
res.end(message)
}

const badRequest = (res, message) => {
res.statusCode = 400
res.end(message)
}

const noContent = res => {
res.statusCode = 204
res.end()
Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ test('Updates', async t => {
}
})

await t.test('invalid semver', async t => {
const res = await fetch(`${address}/owner/repo/darwin/latest`)
t.equal(res.status, 400)
const body = await res.text()
t.equal(body, 'Invalid SemVer: "latest"')
})

await t.test('exists but has no releases', async t => {
for (let i = 0; i < 2; i++) {
const res = await fetch(
Expand Down

0 comments on commit 2f24074

Please sign in to comment.