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

[TIMOB-18159] CLI: Implement node connectivity tests from titanium-conne... #175

Merged
merged 1 commit into from
Jan 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/commands/lib/urls_to_check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
"https://api.appcelerator.com/p/v1/release-list",
"https://api.appcelerator.net/p/v1/release-list",
"https://api.cloud.appcelerator.com",
"http://developer.appcelerator.com",
"https://preview.appcelerator.com",
"http://preview.appcelerator.com",
"https://studio.appcelerator.com",
"http://studio.appcelerator.com",
"https://www.appcelerator.com",
"http://www.appcelerator.com",
"https://www.google.com",
"https://github.com",
"https://registry.npmjs.org"
]
55 changes: 29 additions & 26 deletions lib/commands/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,29 +570,36 @@ SetupScreens.prototype.check = function check(callback) {
var r = {
online: err ? null : online,
proxy: config.get('cli.httpProxyServer'),
http: false,
https: false
unreachable: []
};

if (!r.online) {
return next(null, r);
}

// test http and https
async.parallel(['http', 'https'].map(function (protocol) {
return function (cb) {
request({
url: protocol + '://api.appcelerator.com/p/v1/release-list',
proxy: config.get('cli.httpProxyServer'),
rejectUnauthorized: config.get('cli.rejectUnauthorized', true)
}, function (error, response, body) {
if (!error) {
r[protocol] = true;
}
/*
Test network access and proxy permissions via
node, cURL, and Java through an async series
of tests. Start by attempting to access a set
of necessary http and https endpoints.
*/
async.parallel(JSON.parse(fs.readFileSync(path.resolve(__dirname, 'lib', 'urls_to_check.json'))).map(function (testUrl) {
return function (cb) {
request({
url: testUrl,
proxy: config.get('cli.httpProxyServer', ''),
rejectUnauthorized: config.get('cli.rejectUnauthorized', true)
}, function (error, response, body) {
if (error || (response.statusCode && response.statusCode != 200 && response.statusCode != 401)) {
// if there's an error, response will be null, treat it as a 404
var statCode = (response && response.statusCode) ? response.statusCode : '404'
r.unreachable.push(testUrl + ' (HTTP status: ' + statCode + ')');
}
});
cb();
});
};
}), function () {
}
}),
function () {
next(null, r);
});
});
Expand Down Expand Up @@ -1111,19 +1118,15 @@ SetupScreens.prototype.check = function check(callback) {
note(__('no proxy server configured'));
}
if (r.online) {
if (r.http) {
ok(__('http request test'));
} else {
bad(__('http request test failed'));
}
if (r.https) {
ok(__('https request test'));
if (r.unreachable.length) {
r.unreachable.forEach(function(unreachableUrl) {
bad(unreachableUrl + __(' is unreachable'));
});
} else {
bad(__('https request test failed'));
ok(__('Network connection test'));
}
} else {
note(__('http request test'));
note(__('https request test'));
note(__('Network connection test'));
}
log();
}(results.network));
Expand Down