Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 9ef8954

Browse files
committed
Remove cookieauth plugin from test clients.
1 parent 31a9f83 commit 9ef8954

File tree

9 files changed

+106
-44
lines changed

9 files changed

+106
-44
lines changed

test/client.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const uuidv4 = require('uuid/v4'); // random
2626
const ME = process.env.cloudant_username || 'nodejs';
2727
const PASSWORD = process.env.cloudant_password || 'sjedon';
2828
const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`;
29+
const SERVER_NO_PROTOCOL = SERVER.replace(/^https?:\/\//, '');
30+
const SERVER_WITH_CREDS = `https://${ME}:${PASSWORD}@${SERVER_NO_PROTOCOL}`;
2931
const DBNAME = `/nodejs-cloudant-${uuidv4()}`;
3032
const DOCID = 'doc1';
3133

@@ -88,17 +90,17 @@ describe('CloudantClient', function() {
8890

8991
describe('plugin support', function() {
9092
it('get plugin path by name', function() {
91-
var cloudantClient = new Client();
93+
var cloudantClient = new Client({ plugins: [] });
9294
assert.equal(cloudantClient._buildPluginPath('dummy-plugin'), '../plugins/dummy-plugin');
9395
});
9496

9597
it('get plugin path by relative path', function() {
96-
var cloudantClient = new Client();
98+
var cloudantClient = new Client({ plugins: [] });
9799
assert.equal(cloudantClient._buildPluginPath('./dummy-plugin'), path.join(process.cwd(), 'dummy-plugin'));
98100
});
99101

100102
it('get plugin path by absolute path', function() {
101-
var cloudantClient = new Client();
103+
var cloudantClient = new Client({ plugins: [] });
102104
assert.equal(cloudantClient._buildPluginPath('/plugins/dummy-plugin'), '/plugins/dummy-plugin');
103105
});
104106

@@ -111,7 +113,7 @@ describe('CloudantClient', function() {
111113
});
112114

113115
it('adds cookie authentication plugin if no other plugins are specified', function() {
114-
var cloudantClient = new Client();
116+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS } });
115117
assert.equal(cloudantClient._plugins.length, 1);
116118
assert.equal(cloudantClient._plugins[0].id, 'cookieauth');
117119
});
@@ -147,12 +149,12 @@ describe('CloudantClient', function() {
147149
});
148150

149151
it('allows a single plugin to be added via "plugins" options', function() {
150-
var cloudantClient = new Client({ plugins: ['cookieauth'] });
152+
var cloudantClient = new Client({ plugins: ['retry'] });
151153
assert.equal(cloudantClient._plugins.length, 1);
152154
});
153155

154156
it('allows an array of plugins to be added via "plugins" options', function() {
155-
var cloudantClient = new Client({
157+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS },
156158
plugins: [
157159
'retry', // plugin 1
158160
'cookieauth', // plugin 2

test/cloudant.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const PASSWORD = process.env.cloudant_password || 'sjedon';
2626
const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`;
2727
const DBNAME = `nodejs-cloudant-${uuidv4()}`;
2828

29+
const COOKIEAUTH_PLUGIN = [ { cookieauth: { autoRenew: false } } ];
30+
2931
describe('Cloudant #db', function() {
3032
before(function(done) {
3133
var mocks = nock(SERVER)
@@ -72,12 +74,14 @@ describe('Cloudant #db', function() {
7274
var security = { cloudant: { nobody: [ '_reader' ] } };
7375

7476
var mocks = nock(SERVER)
77+
.post('/_session')
78+
.reply(200, { ok: true })
7579
.put(`/_api/v2/db/${DBNAME}/_security`, security)
7680
.reply(200, { ok: true })
7781
.get(`/_api/v2/db/${DBNAME}/_security`)
7882
.reply(200, security);
7983

80-
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
84+
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: COOKIEAUTH_PLUGIN });
8185
var db = cloudant.db.use(DBNAME);
8286

8387
db.set_security(security, function(err, result) {
@@ -98,12 +102,14 @@ describe('Cloudant #db', function() {
98102
var security = { cloudant: role };
99103

100104
var mocks = nock(SERVER)
105+
.post('/_session')
106+
.reply(200, { ok: true })
101107
.put(`/_api/v2/db/${DBNAME}/_security`, security)
102108
.reply(200, { ok: true })
103109
.get(`/_api/v2/db/${DBNAME}/_security`)
104110
.reply(200, security);
105111

106-
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
112+
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: COOKIEAUTH_PLUGIN });
107113
var db = cloudant.db.use(DBNAME);
108114

109115
db.set_security(role, function(err, result) {
@@ -133,12 +139,14 @@ describe('Cloudant #db', function() {
133139
};
134140

135141
var mocks = nock(SERVER)
142+
.post('/_session')
143+
.reply(200, { ok: true })
136144
.put(`/${DBNAME}/_security`, security)
137145
.reply(200, { ok: true })
138146
.get(`/_api/v2/db/${DBNAME}/_security`)
139147
.reply(200, security);
140148

141-
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
149+
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: COOKIEAUTH_PLUGIN });
142150
var db = cloudant.db.use(DBNAME);
143151

144152
db.set_security(security, function(err, result) {

test/issues/292.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const PASSWORD = process.env.cloudant_password || 'sjedon';
2626
const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`;
2727
const DBNAME = `nodejs-cloudant-${uuidv4()}`;
2828

29+
const COOKIEAUTH_PLUGIN = [ { cookieauth: { autoRenew: false } } ];
30+
2931
describe('#db Issue #292', function() {
3032
before(function(done) {
3133
var mocks = nock(SERVER)
@@ -69,10 +71,12 @@ describe('#db Issue #292', function() {
6971

7072
it('lists all query indices', function(done) {
7173
var mocks = nock(SERVER)
74+
.post('/_session')
75+
.reply(200, { ok: true })
7276
.get(`/${DBNAME}/_index`)
7377
.reply(200, { total_rows: 1, indexes: [ { name: '_all_docs' } ] });
7478

75-
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
79+
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: COOKIEAUTH_PLUGIN });
7680
var db = cloudant.db.use(DBNAME);
7781

7882
db.index().then((d) => {
@@ -91,10 +95,12 @@ describe('#db Issue #292', function() {
9195
};
9296

9397
var mocks = nock(SERVER)
98+
.post('/_session')
99+
.reply(200, { ok: true })
94100
.post(`/${DBNAME}/_index`, definition)
95101
.reply(200, { result: 'created' });
96102

97-
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD });
103+
var cloudant = Cloudant({ url: SERVER, username: ME, password: PASSWORD, plugins: COOKIEAUTH_PLUGIN });
98104
var db = cloudant.db.use(DBNAME);
99105

100106
db.index(definition).then((d) => {

test/legacy/api.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var uuid = require('uuid/v4');
2525
var nock = require('../nock.js');
2626
var Cloudant = require('../../cloudant.js');
2727

28+
const COOKIEAUTH_PLUGIN = [ { cookieauth: { autoRenew: false } } ];
29+
2830
// These globals may potentially be parameterized.
2931
var ME = process.env.cloudant_username || 'nodejs';
3032
var PASSWORD = process.env.cloudant_password || 'sjedon';
@@ -46,7 +48,7 @@ describe('Cloudant API', function() {
4648
describe('#db Initialization', function() {
4749
it('runs synchronously with one argument', function() {
4850
(function() {
49-
var db = Cloudant({account: ME});
51+
var db = Cloudant({account: ME, plugins: []});
5052
}).should.not.throw();
5153
});
5254

@@ -55,7 +57,7 @@ describe('#db Initialization', function() {
5557
.post('/_session').reply(200, {ok: true})
5658
.get('/').reply(200, {couchdb: 'Welcome', version: '1.0.2'});
5759

58-
Cloudant({url: SERVER, username: ME, password: PASSWORD}, function(er, cloudant, body) {
60+
Cloudant({url: SERVER, username: ME, password: PASSWORD, plugins: COOKIEAUTH_PLUGIN}, function(er, cloudant, body) {
5961
should(er).equal(null, 'No problem pinging Cloudant');
6062
cloudant.should.be.an.Object;
6163
body.should.be.an.Object;
@@ -76,7 +78,7 @@ describe('#db Initialization', function() {
7678
.times(3)
7779
.replyWithError({code: 'ECONNRESET', message: 'socket hang up'})
7880

79-
Cloudant({username: ME, password: PASSWORD, url: SERVER}, function(er, cloudant, body) {
81+
Cloudant({username: ME, password: PASSWORD, url: SERVER, plugins: COOKIEAUTH_PLUGIN}, function(er, cloudant, body) {
8082
er.should.be.an.Object;
8183
mocks.done();
8284
done();
@@ -88,7 +90,7 @@ describe('#db Initialization', function() {
8890
.post('/_session').reply(200, {ok: true, userCtx: {name: ME, roles: []}})
8991
.get('/').reply(200, {couchdb: 'Welcome', version: '1.0.2'});
9092

91-
Cloudant({url: SERVER, username: ME, password: PASSWORD}, function(er, cloudant, welcome) {
93+
Cloudant({url: SERVER, username: ME, password: PASSWORD, plugins: COOKIEAUTH_PLUGIN}, function(er, cloudant, welcome) {
9294
should(er).equal(null, 'No problem pinging Cloudant');
9395
cloudant.should.be.an.Object;
9496

@@ -98,7 +100,7 @@ describe('#db Initialization', function() {
98100
});
99101

100102
it('supports instantiation without a callback', function(done) {
101-
var c = Cloudant({account: ME});
103+
var c = Cloudant({account: ME, plugins: []});
102104
// check we get a Nano object back
103105
c.should.be.an.Object;
104106
c.should.have.property('use');

test/legacy/plugin.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ var PassThroughDuplex = require('../../lib/passthroughduplex.js');
3232
var ME = process.env.cloudant_username || 'nodejs';
3333
var PASSWORD = process.env.cloudant_password || 'sjedon';
3434
var SERVER = process.env.SERVER_URL || 'https://' + ME + '.cloudant.com';
35+
var SERVER_NO_PROTOCOL = SERVER.replace(/^https?:\/\//, '');
36+
var SERVER_WITH_CREDS = `https://${ME}:${PASSWORD}@${SERVER_NO_PROTOCOL}`;
37+
38+
const COOKIEAUTH_PLUGIN = [ { cookieauth: { autoRenew: false } } ];
39+
3540
var dbName;
3641
var mydb = null;
3742
var cc = null;
@@ -143,7 +148,7 @@ describe('promises #db', function() {
143148
it('should return a promise', function(done) {
144149
var mocks = nock(SERVER)
145150
.get('/' + dbName).reply(200, { ok: true });
146-
var cloudant = Cloudant({url: SERVER, username: ME, password: PASSWORD});
151+
var cloudant = Cloudant({url: SERVER, username: ME, password: PASSWORD, plugins: []});
147152
var db = cloudant.db.use(dbName);
148153
var p = db.info().then(function(data) {
149154
data.should.be.an.Object;
@@ -155,7 +160,7 @@ describe('promises #db', function() {
155160
it('should return an error status code', function(done) {
156161
var mocks = nock(SERVER)
157162
.get('/somedbthatdoesntexist').reply(404, { ok: false });
158-
var cloudant = Cloudant({url: SERVER, username: ME, password: PASSWORD});
163+
var cloudant = Cloudant({url: SERVER, username: ME, password: PASSWORD, plugins: []});
159164
var db = cloudant.db.use('somedbthatdoesntexist');
160165
var p = db.info().then(function(data) {
161166
assert(false);
@@ -213,7 +218,13 @@ describe('custom plugin #db', function() {
213218
.get('/')
214219
.reply(200, { couchdb: 'Welcome' });
215220

216-
Cloudant({ plugins: defaultPlugin, url: SERVER, username: ME, password: PASSWORD }, function(err, nano, pong) {
221+
Cloudant({
222+
creds: { outUrl: SERVER_WITH_CREDS },
223+
plugins: defaultPlugin,
224+
url: SERVER,
225+
username: ME,
226+
password: PASSWORD
227+
}, function(err, nano, pong) {
217228
assert.equal(err, null);
218229
assert.notEqual(nano, null);
219230
assert.equal(pong.couchdb, 'Welcome');
@@ -231,7 +242,7 @@ describe('cookieauth plugin #db', function() {
231242
var mocks = nock(SERVER)
232243
.post('/_session').reply(200, { ok: true })
233244
.get('/' + dbName).reply(200, { ok: true });
234-
var cloudant = Cloudant({plugins: 'cookieauth', url: SERVER, username: ME, password: PASSWORD});
245+
var cloudant = Cloudant({plugins: COOKIEAUTH_PLUGIN, url: SERVER, username: ME, password: PASSWORD});
235246
var db = cloudant.db.use(dbName);
236247
var p = db.info().then(function(data) {
237248
data.should.be.an.Object;
@@ -246,7 +257,7 @@ describe('cookieauth plugin #db', function() {
246257
var mocks = nock(SERVER)
247258
.post('/_session', {name: ME, password: PASSWORD}).reply(200, { ok: true, info: {}, userCtx: { name: ME, roles: ['_admin'] } })
248259
.get('/' + dbName + '/mydoc').reply(200, { _id: 'mydoc', _rev: '1-123', ok: true });
249-
var cloudant = Cloudant({plugins: 'cookieauth', url: SERVER, username: ME, password: PASSWORD});
260+
var cloudant = Cloudant({plugins: COOKIEAUTH_PLUGIN, url: SERVER, username: ME, password: PASSWORD});
250261
var db = cloudant.db.use(dbName);
251262
var p = db.get('mydoc', function(err, data) {
252263
assert.equal(err, null);
@@ -266,7 +277,7 @@ describe('cookieauth plugin #db', function() {
266277
.post('/_session', {name: ME, password: PASSWORD}).reply(200, { ok: true, info: {}, userCtx: { name: ME, roles: ['_admin'] } }, { 'Set-Cookie': 'AuthSession=xyz; Version=1; Path=/; HttpOnly' })
267278
.get('/' + dbName + '/mydoc').reply(200, { _id: 'mydoc', _rev: '1-123', ok: true })
268279
.get('/' + dbName + '/mydoc').reply(200, { _id: 'mydoc', _rev: '1-123', ok: true });
269-
var cloudant = Cloudant({plugins: 'cookieauth', url: SERVER, username: ME, password: PASSWORD});
280+
var cloudant = Cloudant({plugins: COOKIEAUTH_PLUGIN, url: SERVER, username: ME, password: PASSWORD});
270281
var db = cloudant.db.use(dbName);
271282
var p = db.get('mydoc', function(err, data) {
272283
assert.equal(err, null);

test/legacy/readme-examples.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const uuid = require('uuid/v4');
3333
var ME = process.env.cloudant_username || 'nodejs';
3434
var PASSWORD = process.env.cloudant_password || 'sjedon';
3535
var SERVER = process.env.SERVER_URL || 'https://' + ME + '.cloudant.com';
36+
const COOKIEAUTH_PLUGIN = [ { cookieauth: { autoRenew: false } } ];
3637

3738
const MOCK_COOKIE = 'AuthSession=Y2xbZWr0bQlpcc19ZQN8OeU4OWFCNYcZOxgdhy-QRDp4i6JQrfkForX5OU5P';
3839
const MOCK_SET_COOKIE_HEADER = { 'set-cookie': `${MOCK_COOKIE}; Version=1; Max-Age=86400; Path=/; HttpOnly` };
@@ -176,7 +177,7 @@ if (SERVER.endsWith('.cloudant.com')) {
176177
it('Example 1', function(done) {
177178
var Cloudant = require('@cloudant/cloudant');
178179

179-
Cloudant({account: ME, password: PASSWORD}, function(er, cloudant, reply) {
180+
Cloudant({account: ME, password: PASSWORD, plugins: COOKIEAUTH_PLUGIN}, function(er, cloudant, reply) {
180181
if (er) {
181182
throw er;
182183
}
@@ -557,7 +558,7 @@ if (SERVER.endsWith('.cloudant.com')) {
557558
cookies[username] = headers['set-cookie'];
558559

559560
console.log('headers %j', headers);
560-
headers.should.have.a.property('set-cookie').which.is.a.Array;
561+
headers.should.have.a.property('set-cookie')
561562
done();
562563
});
563564
});

test/plugins/cookieauth.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const SERVER = process.env.SERVER_URL || `https://${ME}.cloudant.com`;
2626
const SERVER_NO_PROTOCOL = SERVER.replace(/^https?:\/\//, '');
2727
const SERVER_WITH_CREDS = `https://${ME}:${PASSWORD}@${SERVER_NO_PROTOCOL}`;
2828
const DBNAME = `/nodejs-cloudant-${uuidv4()}`;
29+
const COOKIEAUTH_PLUGIN = [ { cookieauth: { autoRenew: false } } ];
2930

3031
// mock cookies
3132

@@ -85,7 +86,7 @@ describe('#db CookieAuth Plugin', function() {
8586
.get(DBNAME)
8687
.reply(200, {doc_count: 0});
8788

88-
var cloudantClient = new Client({ plugins: 'cookieauth' });
89+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: COOKIEAUTH_PLUGIN });
8990
var req = { url: SERVER_WITH_CREDS + DBNAME, method: 'GET' };
9091
cloudantClient.request(req, function(err, resp, data) {
9192
assert.equal(err, null);
@@ -115,7 +116,7 @@ describe('#db CookieAuth Plugin', function() {
115116
var end1 = false;
116117
var end2 = false;
117118

118-
var cloudantClient = new Client({ plugins: 'cookieauth' });
119+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: COOKIEAUTH_PLUGIN });
119120
var req = { url: SERVER_WITH_CREDS + DBNAME, method: 'GET' };
120121
cloudantClient.request(req, function(err, resp, data) {
121122
assert.equal(err, null);
@@ -161,7 +162,7 @@ describe('#db CookieAuth Plugin', function() {
161162
.get(DBNAME)
162163
.reply(500, {error: 'internal_server_error', reason: 'Internal Server Error'});
163164

164-
var cloudantClient = new Client({ plugins: 'cookieauth' });
165+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: COOKIEAUTH_PLUGIN });
165166
var req = { url: SERVER_WITH_CREDS + DBNAME, method: 'GET' };
166167
cloudantClient.request(req, function(err, resp, data) {
167168
assert.equal(err, null);
@@ -184,7 +185,7 @@ describe('#db CookieAuth Plugin', function() {
184185
.get(DBNAME)
185186
.replyWithError({code: 'ECONNRESET', message: 'socket hang up'});
186187

187-
var cloudantClient = new Client({ plugins: 'cookieauth' });
188+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: COOKIEAUTH_PLUGIN });
188189
var req = { url: SERVER_WITH_CREDS + DBNAME, method: 'GET' };
189190
cloudantClient.request(req, function(err, resp, data) {
190191
assert.equal(err.code, 'ECONNRESET');
@@ -207,7 +208,7 @@ describe('#db CookieAuth Plugin', function() {
207208
.get(DBNAME)
208209
.reply(200, {doc_count: 0});
209210

210-
var cloudantClient = new Client({ plugins: 'cookieauth' });
211+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: COOKIEAUTH_PLUGIN });
211212
var req = { url: SERVER_WITH_CREDS + DBNAME, method: 'GET' };
212213
cloudantClient.request(req, function(err, resp, data) {
213214
assert.equal(err, null);
@@ -235,7 +236,7 @@ describe('#db CookieAuth Plugin', function() {
235236
.get(DBNAME)
236237
.reply(200, {doc_count: 0});
237238

238-
var cloudantClient = new Client({ plugins: 'cookieauth' });
239+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: COOKIEAUTH_PLUGIN });
239240
var req = { url: SERVER_WITH_CREDS + DBNAME, method: 'GET' };
240241
cloudantClient.request(req, function(err, resp, data) {
241242
assert.equal(err, null);
@@ -260,10 +261,10 @@ describe('#db CookieAuth Plugin', function() {
260261
.times(3)
261262
.reply(401, {error: 'unauthorized', reason: 'Unauthorized'});
262263

263-
var cloudantClient = new Client({ plugins: 'cookieauth' });
264+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: COOKIEAUTH_PLUGIN });
264265
var req = { url: SERVER_WITH_CREDS + DBNAME, method: 'GET' };
265266
cloudantClient.request(req, function(err, resp, data) {
266-
assert.equal(err.message, 'Failed to acquire session cookie. Status code: 401');
267+
assert.equal(err.message, 'Failed to get cookie. Status code: 401');
267268
mocks.done();
268269
done();
269270
});
@@ -283,7 +284,7 @@ describe('#db CookieAuth Plugin', function() {
283284
.get(DBNAME)
284285
.reply(200, {doc_count: 0});
285286

286-
var cloudantClient = new Client({ plugins: 'cookieauth' });
287+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: COOKIEAUTH_PLUGIN });
287288
var req = { url: SERVER_WITH_CREDS + DBNAME, method: 'GET' };
288289
cloudantClient.request(req, function(err, resp, data) {
289290
assert.equal(err, null);
@@ -311,7 +312,7 @@ describe('#db CookieAuth Plugin', function() {
311312
.get(DBNAME)
312313
.reply(200, {doc_count: 0});
313314

314-
var cloudantClient = new Client({ plugins: 'cookieauth' });
315+
var cloudantClient = new Client({ creds: { outUrl: SERVER_WITH_CREDS }, plugins: COOKIEAUTH_PLUGIN });
315316
var req = { url: SERVER_WITH_CREDS + DBNAME, method: 'GET' };
316317
cloudantClient.request(req, function(err, resp, data) {
317318
assert.equal(err, null);

0 commit comments

Comments
 (0)