Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url verification #3

Merged
merged 3 commits into from Jan 18, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Complete suite of deployment url verifications

  • Loading branch information
aekeus committed Jan 18, 2016
commit 2d0d58389746c37eddc7e143f21f8a358de104bf
@@ -1,21 +1,37 @@
/*
Verification checks for updater configuration
Verification checks for updater configuration and file location / status
*/

var assert = require('assert')
var fs = require('fs')
var glob = require('glob')
var path = require('path')
var request = require('request')
var url = require('url')

// Verify (via HEAD call) that a file exists at a url, throw if not
var verifyUrl = (url, msg) => {
request.head(url, (err, response, body) => {
assert.equal(err, null)
if (response.statusCode === 200) {
console.log(' OK ... ' + url)
} else {
throw new Error(msg)
}
})
}

process.stdout.write('[1] Verifying data files have identical most current version numbers ... ')

// Read data files
var files = glob.sync(path.join(__dirname, '..', 'data', '*'))
var contents = files.map(function(filename) {
var contents = files.map((filename) => {
return JSON.parse(fs.readFileSync(filename, 'utf-8'))
})

// Are the last version numbers identical?
var versions = {}
contents.forEach(function(json) {
contents.forEach((json) => {
versions[json[0].version] = true
})

@@ -25,25 +41,28 @@ if (versions.length !== 1) {
}
console.log('OK')

// TODO - add verification check by downloading files listed in meta data etc...
console.log('[2] Verifying urls')
contents.forEach(function(json) {
if (json[0].url) {
request.head(json[0].url, (err, response, body) => {
if (response.statusCode === 200) {
console.log(' OK ... ' + json[0].url)
} else {
throw new Error(json[0].url + ' could not be found')
}
})
// Verify files from json url
console.log('[2] Verifying file location and status')
contents.forEach((json) => {
if (json[0].url && json[0].version) {
verifyUrl(json[0].url, json[0].url + ' could not be found')
var parsed = url.parse(json[0].url)
var urlPath = parsed.path.split('/')
urlPath = urlPath.slice(0, urlPath.length - 1).join('/')
verifyUrl(parsed.protocol + '//' + parsed.hostname + urlPath + '/Brave.dmg', 'Brave.dmg not found')
}
})

var winx64_url = 'https://brave-download.global.ssl.fastly.net/releases/winx64/RELEASES'
request.head(winx64_url, (err, response, body) => {
// Verify Windows files
var winx64_url = 'https://brave-download.global.ssl.fastly.net/releases/winx64'
request.get(winx64_url + '/RELEASES', (err, response, body) => {
assert.equal(err, null)
if (response.statusCode === 200) {
console.log(' OK ... ' + winx64_url)
console.log(' OK ... ' + winx64_url + '/RELEASES')
var filename = body.split(' ')[1]
verifyUrl(winx64_url + '/' + filename, 'Windows update file ' + filename + ' is not available at ' + winx64_url + '/' + filename)
} else {
throw new Error(winx64_url + ' could not be found')
}
});
})
verifyUrl(winx64_url + '/BraveSetup.exe', 'BraveSetup.exe not found')
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.