Skip to content

Commit 9f80827

Browse files
author
Chris Moultrie
committed
Now handling self-signed certificates
1 parent 0b0cb36 commit 9f80827

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

lib/jira.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,19 @@ var url = require('url'),
9292
logger = console;
9393

9494

95-
var JiraApi = exports.JiraApi = function(protocol, host, port, username, password, apiVersion, verbose) {
95+
var JiraApi = exports.JiraApi = function(protocol, host, port, username, password, apiVersion, verbose, strictSSL) {
9696
this.protocol = protocol;
9797
this.host = host;
9898
this.port = port;
9999
this.username = username;
100100
this.password = password;
101101
this.apiVersion = apiVersion;
102+
// Default strictSSL to true (previous behavior) but now allow it to be
103+
// modified
104+
if (strictSSL == null) {
105+
strictSSL = true;
106+
}
107+
this.strictSSL = strictSSL;
102108
// This is so we can fake during unit tests
103109
this.request = require('request');
104110
if (verbose !== true) { logger = { log: function() {} }; }
@@ -140,6 +146,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
140146
this.findIssue = function(issueNumber, callback) {
141147

142148
var options = {
149+
rejectUnauthorized: this.strictSSL,
143150
uri: this.makeUri('/issue/' + issueNumber),
144151
method: 'GET'
145152
};
@@ -180,6 +187,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
180187

181188
this.getUnresolvedIssueCount = function(version, callback) {
182189
var options = {
190+
rejectUnauthorized: this.strictSSL,
183191
uri: this.makeUri('/version/' + version + '/unresolvedIssueCount'),
184192
method: 'GET'
185193
};
@@ -222,6 +230,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
222230
this.getProject = function(project, callback) {
223231

224232
var options = {
233+
rejectUnauthorized: this.strictSSL,
225234
uri: this.makeUri('/project/' + project),
226235
method: 'GET'
227236
};
@@ -268,6 +277,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
268277
this.findRapidView = function(projectName, callback) {
269278

270279
var options = {
280+
rejectUnauthorized: this.strictSSL,
271281
uri: this.makeUri('/rapidviews/list', 'rest/greenhopper/'),
272282
method: 'GET',
273283
json: true
@@ -322,6 +332,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
322332
this.getLastSprintForRapidView = function(rapidViewId, callback) {
323333

324334
var options = {
335+
rejectUnauthorized: this.strictSSL,
325336
uri: this.makeUri('/sprints/' + rapidViewId, 'rest/greenhopper/'),
326337
method: 'GET',
327338
json:true
@@ -374,6 +385,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
374385
this.getSprintIssues = function getSprintIssues(rapidViewId, sprintId, callback) {
375386

376387
var options = {
388+
rejectUnauthorized: this.strictSSL,
377389
uri: this.makeUri('/rapid/charts/sprintreport?rapidViewId=' + rapidViewId + '&sprintId=' + sprintId, 'rest/greenhopper/'),
378390
method: 'GET',
379391
json: true
@@ -429,6 +441,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
429441
this.addIssueToSprint = function(issueId, sprintId, callback) {
430442

431443
var options = {
444+
rejectUnauthorized: this.strictSSL,
432445
uri: this.makeUri('/sprint/' + sprintId + '/issues/add', 'rest/greenhopper/'),
433446
method: 'PUT',
434447
followAllRedirects: true,
@@ -493,6 +506,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
493506
this.issueLink = function(link, callback) {
494507

495508
var options = {
509+
rejectUnauthorized: this.strictSSL,
496510
uri: this.makeUri('/issueLink'),
497511
method: 'POST',
498512
followAllRedirects: true,
@@ -536,6 +550,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
536550
this.getVersions = function(project, callback) {
537551

538552
var options = {
553+
rejectUnauthorized: this.strictSSL,
539554
uri: this.makeUri('/project/' + project + '/versions'),
540555
method: 'GET'
541556
};
@@ -589,6 +604,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
589604
this.createVersion = function(version, callback) {
590605

591606
var options = {
607+
rejectUnauthorized: this.strictSSL,
592608
uri: this.makeUri('/version'),
593609
method: 'POST',
594610
followAllRedirects: true,
@@ -651,6 +667,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
651667
}
652668

653669
var options = {
670+
rejectUnauthorized: this.strictSSL,
654671
uri: this.makeUri('/search'),
655672
method: 'POST',
656673
json: true,
@@ -719,6 +736,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
719736
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290028)
720737
this.addNewIssue = function(issue, callback) {
721738
var options = {
739+
rejectUnauthorized: this.strictSSL,
722740
uri: this.makeUri('/issue'),
723741
method: 'POST',
724742
followAllRedirects: true,
@@ -760,6 +778,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
760778
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290791)
761779
this.deleteIssue = function(issueNum, callback) {
762780
var options = {
781+
rejectUnauthorized: this.strictSSL,
763782
uri: this.makeUri('/issue/' + issueNum),
764783
method: 'DELETE',
765784
followAllRedirects: true,
@@ -796,6 +815,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
796815
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290878)
797816
this.updateIssue = function(issueNum, issueUpdate, callback) {
798817
var options = {
818+
rejectUnauthorized: this.strictSSL,
799819
uri: this.makeUri('/issue/' + issueNum),
800820
body: issueUpdate,
801821
method: 'PUT',
@@ -869,6 +889,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
869889
*/
870890
this.listTransitions = function(issueId, callback) {
871891
var options = {
892+
rejectUnauthorized: this.strictSSL,
872893
uri: this.makeUri('/issue/' + issueId + '/transitions'),
873894
method: 'GET',
874895
json: true
@@ -908,6 +929,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
908929
// [Jira Doc](http://docs.atlassian.com/jira/REST/latest/#id290489)
909930
this.transitionIssue = function(issueNum, issueTransition, callback) {
910931
var options = {
932+
rejectUnauthorized: this.strictSSL,
911933
uri: this.makeUri('/issue/' + issueNum + '/transitions'),
912934
body: issueTransition,
913935
method: 'POST',
@@ -957,6 +979,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
957979
*/
958980
this.listProjects = function(callback) {
959981
var options = {
982+
rejectUnauthorized: this.strictSSL,
960983
uri: this.makeUri('/project'),
961984
method: 'GET',
962985
json: true
@@ -1022,6 +1045,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
10221045
*/
10231046
this.addWorklog = function(issueId, worklog, callback) {
10241047
var options = {
1048+
rejectUnauthorized: this.strictSSL,
10251049
uri: this.makeUri('/issue/' + issueId + '/worklog'),
10261050
body: worklog,
10271051
method: 'POST',
@@ -1076,6 +1100,7 @@ var JiraApi = exports.JiraApi = function(protocol, host, port, username, passwor
10761100
*/
10771101
this.listIssueTypes = function(callback) {
10781102
var options = {
1103+
rejectUnauthorized: this.strictSSL,
10791104
uri: this.makeUri('/issuetype'),
10801105
method: 'GET',
10811106
json: true

spec/jira.spec.coffee

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe "Node Jira Tests", ->
77
base = 'rest/api/2/'
88
base = 'rest/greenhopper/2/' if altBase?
99
url.format
10-
protocol: 'http'
10+
protocol: 'http:'
1111
hostname: 'localhost'
1212
auth: 'test:test'
1313
port: 80
@@ -19,8 +19,23 @@ describe "Node Jira Tests", ->
1919
spyOn @jira, 'request'
2020
@cb = jasmine.createSpy 'callback'
2121

22+
it "Sets strictSSL to false when passed in", ->
23+
expected = false
24+
jira = new nodeJira.JiraApi 'http', 'localhost', 80, 'test', 'test', 2, false, expected
25+
expect(jira.strictSSL).toEqual(expected)
26+
27+
it "Sets strictSSL to true when passed in", ->
28+
expected = true
29+
jira = new nodeJira.JiraApi 'http', 'localhost', 80, 'test', 'test', 2, false, expected
30+
expect(jira.strictSSL).toEqual(expected)
31+
32+
it "Sets strictSSL to true when not passed in", ->
33+
expected = true
34+
expect(@jira.strictSSL).toEqual(expected)
35+
2236
it "Finds an issue", ->
2337
options =
38+
rejectUnauthorized: true
2439
uri: makeUrl "issue/1"
2540
method: 'GET'
2641
@jira.findIssue 1, @cb
@@ -43,6 +58,7 @@ describe "Node Jira Tests", ->
4358

4459
it "Gets the unresolved issue count", ->
4560
options =
61+
rejectUnauthorized: true
4662
uri: makeUrl "version/1/unresolvedIssueCount"
4763
method: 'GET'
4864

@@ -66,6 +82,7 @@ describe "Node Jira Tests", ->
6682

6783
it "Gets the project from a key", ->
6884
options =
85+
rejectUnauthorized: true
6986
uri: makeUrl "project/ABC"
7087
method: 'GET'
7188

@@ -84,6 +101,7 @@ describe "Node Jira Tests", ->
84101

85102
it "Finds a Rapid View", ->
86103
options =
104+
rejectUnauthorized: true
87105
uri: makeUrl("rapidviews/list", true)
88106
method: 'GET'
89107
json: true
@@ -110,6 +128,7 @@ describe "Node Jira Tests", ->
110128

111129
it "Gets the last sprint for a Rapid View", ->
112130
options =
131+
rejectUnauthorized: true
113132
uri: makeUrl("sprints/1", true)
114133
method: 'GET'
115134
json: true
@@ -135,6 +154,7 @@ describe "Node Jira Tests", ->
135154

136155
it "Adds an issue to a sprint", ->
137156
options =
157+
rejectUnauthorized: true
138158
uri: makeUrl("sprint/1/issues/add", true)
139159
method: 'PUT'
140160
json: true
@@ -155,6 +175,7 @@ describe "Node Jira Tests", ->
155175

156176
it "Creates a Link Between two Issues", ->
157177
options =
178+
rejectUnauthorized: true
158179
uri: makeUrl "issueLink"
159180
method: 'POST'
160181
json: true
@@ -178,6 +199,7 @@ describe "Node Jira Tests", ->
178199

179200
it "Gets versions for a project", ->
180201
options =
202+
rejectUnauthorized: true
181203
uri: makeUrl "project/ABC/versions"
182204
method: 'GET'
183205

@@ -199,6 +221,7 @@ describe "Node Jira Tests", ->
199221

200222
it "Creates a version for a project", ->
201223
options =
224+
rejectUnauthorized: true
202225
uri: makeUrl "version"
203226
method: 'POST'
204227
json: true
@@ -230,6 +253,7 @@ describe "Node Jira Tests", ->
230253
it "Passes a search query to Jira, default options", ->
231254
fields = ["summary", "status", "assignee", "description"]
232255
options =
256+
rejectUnauthorized: true
233257
uri: makeUrl "search"
234258
method: 'POST'
235259
json: true
@@ -259,6 +283,7 @@ describe "Node Jira Tests", ->
259283
it "Passes a search query to Jira, non-default options", ->
260284
fields = ["assignee", "description", "test"]
261285
options =
286+
rejectUnauthorized: true
262287
uri: makeUrl "search"
263288
method: 'POST'
264289
json: true
@@ -283,6 +308,7 @@ describe "Node Jira Tests", ->
283308

284309
it "Gets the sprint issues and information", ->
285310
options =
311+
rejectUnauthorized: true
286312
uri: makeUrl("rapid/charts/sprintreport?rapidViewId=1&sprintId=1", true)
287313
method: 'GET'
288314
json: true
@@ -303,6 +329,7 @@ describe "Node Jira Tests", ->
303329

304330
it "Deletes an Issue", ->
305331
options =
332+
rejectUnauthorized: true
306333
uri: makeUrl "issue/1"
307334
method: 'DELETE'
308335
json: true
@@ -320,6 +347,7 @@ describe "Node Jira Tests", ->
320347

321348
it "Updates an Issue", ->
322349
options =
350+
rejectUnauthorized: true
323351
uri: makeUrl "issue/1"
324352
body: 'updateGoesHere'
325353
method: 'PUT'
@@ -338,6 +366,7 @@ describe "Node Jira Tests", ->
338366

339367
it "Lists Transitions", ->
340368
options =
369+
rejectUnauthorized: true
341370
uri: makeUrl "issue/1/transitions"
342371
method: 'GET'
343372
json: true
@@ -358,6 +387,7 @@ describe "Node Jira Tests", ->
358387

359388
it "Transitions an issue", ->
360389
options =
390+
rejectUnauthorized: true
361391
uri: makeUrl "issue/1/transitions"
362392
body: 'someTransition'
363393
method: 'POST'
@@ -376,6 +406,7 @@ describe "Node Jira Tests", ->
376406

377407
it "Lists Projects", ->
378408
options =
409+
rejectUnauthorized: true
379410
uri: makeUrl "project"
380411
method: 'GET'
381412
json: true
@@ -395,6 +426,7 @@ describe "Node Jira Tests", ->
395426

396427
it "Adds a worklog to a project", ->
397428
options =
429+
rejectUnauthorized: true
398430
uri: makeUrl "issue/1/worklog"
399431
body: 'aWorklog'
400432
method: 'POST'
@@ -420,6 +452,7 @@ describe "Node Jira Tests", ->
420452

421453
it "Lists Issue Types", ->
422454
options =
455+
rejectUnauthorized: true
423456
uri: makeUrl "issuetype"
424457
method: 'GET'
425458
json: true

0 commit comments

Comments
 (0)