Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moving to HTTPS

  • Loading branch information...
commit 00b149d20cb10fc409aecb65ecb321bf515f4456 1 parent 2cd3063
Guilherme Hermeto authored
View
18 lib/blitz/api.js
@@ -6,7 +6,7 @@
* Responsable for requests to Blitz RESTful API
*/
(function () {
- var http = require('http'),
+ var https = require('https'),
EventEmitter = require('events').EventEmitter,
Util = require('util'),
api = {};
@@ -16,8 +16,8 @@
function requestOptions() {
return {
- host: host || 'blitz.io',
- port: port || 80,
+ host: host || 'www.blitz.io',
+ port: port || 443,
method: 'POST',
headers: {
'X-API-User': user,
@@ -62,7 +62,7 @@
options.path = '/api/1/curl/execute';
options.headers['content-length'] = jsonData.length;
- request = http.request(options, function (response) {
+ request = https.request(options, function (response) {
responseHandler(response, function (jsonData) {
// only emmited on complete
var event = 'queue';
@@ -83,7 +83,7 @@
options = requestOptions();
options.path = '/login/api';
options.method = 'GET';
- request = http.request(options, function (response) {
+ request = https.request(options, function (response) {
responseHandler(response, function (jsonData) {
// only emmited on complete
var event = 'login';
@@ -103,7 +103,7 @@
options = requestOptions();
options.path = '/api/1/jobs/' + jobId + '/status';
options.method = 'GET';
- request = http.request(options, function (response) {
+ request = https.request(options, function (response) {
responseHandler(response, function (jsonData) {
// only emmited on complete
var event = 'status';
@@ -123,7 +123,7 @@
options = requestOptions();
options.path = '/api/1/jobs/' + jobId + '/abort';
options.method = 'PUT';
- request = http.request(options, function (response) {
+ request = https.request(options, function (response) {
responseHandler(response, function (jsonData) {
// only emmited on complete
var event = 'abort';
@@ -143,7 +143,7 @@
options = requestOptions();
options.path = '/api/1/account/about';
options.method = 'GET';
- request = http.request(options, function (response) {
+ request = https.request(options, function (response) {
responseHandler(response, function (jsonData) {
callback(jsonData);
});
@@ -160,7 +160,7 @@
options.path = '/api/1/parse';
options.headers['content-length'] = jsonData.length;
- request = http.request(options, function (response) {
+ request = https.request(options, function (response) {
responseHandler(response, function (jsonData) {
// only emmited on complete
var event = 'parse';
View
6 package.json
@@ -1,12 +1,12 @@
{
- "author": "Guilherme Hermeto <gui.hermeto@gmail.com>",
+ "author": "Guilherme Hermeto <guilherme.hermeto@spirent.com>",
"name": "blitz",
"description": "Blitz node.js client API",
- "version": "0.4.0",
+ "version": "0.4.1",
"homepage": "http://blitz.io",
"repository": {
"type": "git",
- "url": "git://github.com/ghermeto/blitz-node.git"
+ "url": "git://github.com/blitz-io/blitz-node.git"
},
"main": "./lib/blitz.js",
"scripts": {
View
122 spec/helper.js
@@ -1,4 +1,6 @@
-var http = require('http'),
+var https = require('https'),
+ path = require('path'),
+ fs = require('fs'),
mockServer = null,
about = {
_id: 'abc123',
@@ -101,70 +103,76 @@ var http = require('http'),
}
};
-module.exports.mockServer = http.createServer(function (request, response) {
- if (request.url === '/api/1/curl/execute') {
- var data = '';
- request.addListener('data', function(chunk) {data += chunk;});
- request.addListener('end', function() {
- var parsedData = JSON.parse(data);
- if (parsedData.steps[0].timeout) {
- response.writeHead(404);
+module.exports.mockServer = https.createServer(
+ {
+ key: fs.readFileSync(path.resolve(__dirname, 'mock-server-key.pem')),
+ cert: fs.readFileSync(path.resolve(__dirname, 'mock-server-cert.pem'))
+ },
+ function (request, response) {
+ if (request.url === '/api/1/curl/execute') {
+ var data = '';
+ request.addListener('data', function(chunk) {data += chunk;});
+ request.addListener('end', function() {
+ var parsedData = JSON.parse(data);
+ if (parsedData.steps[0].timeout) {
+ response.writeHead(404);
+ }
+ else {
+ var id = 'a123';
+ if (parsedData.steps[0].user) {
+ id = parsedData.steps[0].user;
+ }
+ response.writeHead(200, {'content-type': 'application/json'});
+ response.write(JSON.stringify({ok: true, job_id: id}));
+ }
+ response.end();
+ });
+ }
+ else if (request.url === '/login/api') {
+ response.writeHead(200, {'content-type': 'application/json'});
+ if(request.headers['x-api-user'] === process.env['BLITZ_API_USER'] &&
+ request.headers['x-api-key'] === 'key') {
+
+ response.end(JSON.stringify({ok: true, api_key: '123'}));
}
else {
- var id = 'a123';
- if (parsedData.steps[0].user) {
- id = parsedData.steps[0].user;
- }
- response.writeHead(200, {'content-type': 'application/json'});
- response.write(JSON.stringify({ok: true, job_id: id}));
+ response.end(JSON.stringify({error: 'login', reason: 'test'}));
+ }
+ }
+ else if (request.url === '/api/1/parse') {
+ response.writeHead(200, {'content-type': 'application/json'});
+ if(process.env['BLITZ_API_USER'] === 'user') {
+ response.end(JSON.stringify(parseSprint));
+ }
+ else if (process.env['BLITZ_API_USER'] === 'user2') {
+ response.end(JSON.stringify(parseRush));
+ }
+ else {
+ response.end(JSON.stringify({error: 'parse', reason: 'test'}));
}
- response.end();
- });
- }
- else if (request.url === '/login/api') {
- response.writeHead(200, {'content-type': 'application/json'});
- if(request.headers['x-api-user'] === process.env['BLITZ_API_USER'] &&
- request.headers['x-api-key'] === 'key') {
-
- response.end(JSON.stringify({ok: true, api_key: '123'}));
}
- else {
- response.end(JSON.stringify({error: 'login', reason: 'test'}));
+ else if (request.url === '/api/1/jobs/a123/status') {
+ status.status = 'completed';
+ response.writeHead(200, {'content-type': 'application/json'});
+ response.end(JSON.stringify(status));
}
- }
- else if (request.url === '/api/1/parse') {
- response.writeHead(200, {'content-type': 'application/json'});
- if(process.env['BLITZ_API_USER'] === 'user') {
- response.end(JSON.stringify(parseSprint));
+ else if (request.url === '/api/1/jobs/b123/status') {
+ status._id = 'b123';
+ status.status = 'running';
+ response.writeHead(200, {'content-type': 'application/json'});
+ response.end(JSON.stringify(status));
}
- else if (process.env['BLITZ_API_USER'] === 'user2') {
- response.end(JSON.stringify(parseRush));
+ else if (request.url === '/api/1/jobs/c123/status') {
+ timeline.status = 'completed';
+ response.writeHead(200, {'content-type': 'application/json'});
+ response.end(JSON.stringify(timeline));
}
- else {
- response.end(JSON.stringify({error: 'parse', reason: 'test'}));
+ else if (request.url === '/api/1/account/about') {
+ response.writeHead(200, {'content-type': 'application/json'});
+ response.end(JSON.stringify(about));
}
+ response.writeHead(404);
}
- else if (request.url === '/api/1/jobs/a123/status') {
- status.status = 'completed';
- response.writeHead(200, {'content-type': 'application/json'});
- response.end(JSON.stringify(status));
- }
- else if (request.url === '/api/1/jobs/b123/status') {
- status._id = 'b123';
- status.status = 'running';
- response.writeHead(200, {'content-type': 'application/json'});
- response.end(JSON.stringify(status));
- }
- else if (request.url === '/api/1/jobs/c123/status') {
- timeline.status = 'completed';
- response.writeHead(200, {'content-type': 'application/json'});
- response.end(JSON.stringify(timeline));
- }
- else if (request.url === '/api/1/account/about') {
- response.writeHead(200, {'content-type': 'application/json'});
- response.end(JSON.stringify(about));
- }
- response.writeHead(404);
-});
+);
View
13 spec/mock-server-cert.pem
@@ -0,0 +1,13 @@
+-----BEGIN CERTIFICATE-----
+MIIB+DCCAaKgAwIBAgIJAKhL94Nk0/TeMA0GCSqGSIb3DQEBBQUAMDQxCzAJBgNV
+BAYTAlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMRAwDgYDVQQKEwdFeGFtcGxlMB4X
+DTEyMTIwNjE5NDE0MloXDTEzMDEwNTE5NDE0MlowNDELMAkGA1UEBhMCVVMxEzAR
+BgNVBAgTClNvbWUtU3RhdGUxEDAOBgNVBAoTB0V4YW1wbGUwXDANBgkqhkiG9w0B
+AQEFAANLADBIAkEA3xbmR6mgWngkgETS+HOK3EAnPbxgWES4RVdVckykZX5+DFHs
+ve1ITOuouS4EDjuWq5LjaKQjRzJ8mONmbFWnewIDAQABo4GWMIGTMB0GA1UdDgQW
+BBRUIG6T5r2f9qLDujhjfyn1ExhcEjBkBgNVHSMEXTBbgBRUIG6T5r2f9qLDujhj
+fyn1ExhcEqE4pDYwNDELMAkGA1UEBhMCVVMxEzARBgNVBAgTClNvbWUtU3RhdGUx
+EDAOBgNVBAoTB0V4YW1wbGWCCQCoS/eDZNP03jAMBgNVHRMEBTADAQH/MA0GCSqG
+SIb3DQEBBQUAA0EApJaQZPHFXrPRqnqeyYf+DbA3ZZ72QehZfBEGtid9MyKEcC7E
+RfqZ5iz38gza0g+IXpyEKqU3xo4pTmV7m4hyng==
+-----END CERTIFICATE-----
View
9 spec/mock-server-key.pem
@@ -0,0 +1,9 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIBOQIBAAJBAN8W5kepoFp4JIBE0vhzitxAJz28YFhEuEVXVXJMpGV+fgxR7L3t
+SEzrqLkuBA47lquS42ikI0cyfJjjZmxVp3sCAwEAAQJABgPRC6eYKjhJC6hPY+GB
+ofSc2j5E/rxDl6MGK8HDQPU+Ogb4kwwuSb1U6VSIJ63ynhiC5W4ZKGKp8tPJJM4Z
+cQIhAP17uFQ+NZ7Sly+sZfKUPkhg1Wcu5LeLvJ6CgDA/1zFjAiEA4U3tZKE4Q+3/
+etZjTrq8NmF3p7KTui+tvf+JB2/42QkCIFNL9Ka6SqSGT2g7HsU4Mb9XEsl1f3NR
+WAo+mCFC2VRBAiARezdpMG0qMCQ7hrjr2edSnNto4p09vAdSD6q1LgXz6QIgYBbM
+1HwGL6vCdDhVNQY9rGBObT+CHRALzKTlbQu9064=
+-----END RSA PRIVATE KEY-----
Please sign in to comment.
Something went wrong with that request. Please try again.