Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a34beb
commit cc22af4
Showing
7 changed files
with
279 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,9 +45,6 @@ test('config', function (t) { | |
} | ||
}, | ||
'@noCallThru': true | ||
}, | ||
touch: { | ||
sync: function () {} | ||
} | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var log = require('npmlog') | ||
var test = require('tap').test | ||
|
||
test('check couch vendor', function (t) { | ||
t.test('request fails', function (tt) { | ||
var checkVendor = require('../../../lib/couchdb.js').checkVendor | ||
|
||
tt.plan(2) | ||
|
||
checkVendor({db: {url: '<% COUCH URL %>'}}, function (input, callback) { | ||
callback(new Error()) | ||
}, function (err) { | ||
tt.match(err.message, '<% COUCH URL %>') | ||
}) | ||
|
||
checkVendor({db: {url: '<% COUCH URL %>'}}, function (input, callback) { | ||
callback(null, {statusCode: 500}) | ||
}, function (err) { | ||
tt.match(err.message, '<% COUCH URL %>') | ||
}) | ||
}) | ||
|
||
t.test('verify vendor', function (tt) { | ||
var checkVendor = require('../../../lib/couchdb.js').checkVendor | ||
tt.plan(3) | ||
|
||
checkVendor({}, function (input, callback) { | ||
callback(null, null, { | ||
couchdb: 'Welcome!' | ||
}) | ||
}, tt.error) | ||
|
||
var tmp = log.warn | ||
log.warn = function (scope, message) { | ||
log.warn = tmp | ||
tt.match(message, '<% VENDOR %>') | ||
} | ||
checkVendor({}, function (input, callback) { | ||
callback(null, null, { | ||
'<% VENDOR %>': 'Welcome!' | ||
}) | ||
}, tt.error) | ||
}) | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var test = require('tap').test | ||
var proxyquire = require('proxyquire') | ||
|
||
test('generate couch config', function (t) { | ||
t.test('read from file', function (tt) { | ||
var generatedConfig = proxyquire('../../../lib/couchdb.js', { | ||
fs: { | ||
existsSync: function () { | ||
return true | ||
}, | ||
'@noCallThru': true | ||
}, | ||
jsonfile: { | ||
readFileSync: function () { | ||
return { | ||
couch_httpd_auth_secret: 'a' | ||
} | ||
}, | ||
'@noCallThru': true | ||
} | ||
}).generatedConfig | ||
|
||
var result = generatedConfig({paths: {data: ''}}) | ||
|
||
tt.is(result.secret, 'a') | ||
tt.is(result.authentication_db, '_users') | ||
|
||
tt.end() | ||
}) | ||
|
||
t.test('generate and write to file', function (tt) { | ||
var generatedConfig = proxyquire('../../../lib/couchdb.js', { | ||
fs: { | ||
existsSync: function () { | ||
return false | ||
}, | ||
'@noCallThru': true | ||
}, | ||
jsonfile: { | ||
writeFileSync: function () {}, | ||
'@noCallThru': true | ||
} | ||
}).generatedConfig | ||
|
||
var result = generatedConfig({paths: {data: ''}}) | ||
|
||
tt.is(result.secret.length, 32) | ||
tt.is(result.authentication_db, '_users') | ||
|
||
tt.end() | ||
}) | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var test = require('tap').test | ||
|
||
test('get couch config', function (t) { | ||
t.test('request fails', function (tt) { | ||
var getConfig = require('../../../lib/couchdb.js').getConfig | ||
|
||
tt.plan(2) | ||
|
||
getConfig(function (input, callback) { | ||
callback(new Error()) | ||
}, function (err) { | ||
tt.ok(err instanceof Error) | ||
}) | ||
|
||
getConfig(function (input, callback) { | ||
callback(null, {statusCode: 500}) | ||
}, function (err) { | ||
tt.ok(err instanceof Error) | ||
}) | ||
}) | ||
|
||
t.test('request succeds', function (tt) { | ||
var getConfig = require('../../../lib/couchdb.js').getConfig | ||
|
||
tt.plan(9) | ||
|
||
getConfig(function (input, callback) { | ||
tt.is(input.url, '/_config/couch_httpd_auth') | ||
callback(null, null, {}) | ||
}, function (err) { | ||
tt.ok(err instanceof Error) | ||
}) | ||
|
||
getConfig(function (input, callback) { | ||
tt.is(input.url, '/_config/couch_httpd_auth') | ||
callback(null, null, {secret: 'foo'}) | ||
}, function (err) { | ||
tt.ok(err instanceof Error) | ||
}) | ||
|
||
getConfig(function (input, callback) { | ||
tt.is(input.url, '/_config/couch_httpd_auth') | ||
callback(null, null, { | ||
secret: 'foo', | ||
authentication_db: 'bar', | ||
ignore: 'baz' | ||
}) | ||
}, function (err, result) { | ||
tt.error(err) | ||
|
||
tt.is(result.secret, 'foo') | ||
tt.is(result.authentication_db, 'bar') | ||
tt.notOk(result.ignore) | ||
}) | ||
}) | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
var test = require('tap').test | ||
|
||
test('set couch config', function (t) { | ||
t.test('request fails', function (tt) { | ||
var setConfig = require('../../../lib/couchdb.js').setConfig | ||
|
||
tt.plan(2) | ||
|
||
setConfig(function (input, callback) { | ||
callback(new Error()) | ||
}, function (err) { | ||
tt.ok(err instanceof Error) | ||
}) | ||
|
||
setConfig(function (input, callback) { | ||
callback(null, {statusCode: 500}) | ||
}, function (err) { | ||
tt.ok(err instanceof Error) | ||
}) | ||
}) | ||
|
||
t.test('request succeds', function (tt) { | ||
var setConfig = require('../../../lib/couchdb.js').setConfig | ||
|
||
tt.plan(4) | ||
|
||
setConfig(function (input, callback) { | ||
tt.is(input.url, '/_config/httpd/authentication_handlers') | ||
tt.is(input.method, 'PUT') | ||
tt.is(input.body, '{couch_httpd_oauth, oauth_authentication_handler},{couch_httpd_auth, default_authentication_handler},{couch_httpd_auth, cookie_authentication_handler}') | ||
callback(null) | ||
}, tt.error) | ||
}) | ||
|
||
t.end() | ||
}) |