From a80b4566c86f494b8d8e4c294235a1fd130bbcdf Mon Sep 17 00:00:00 2001 From: "Didier Villevalois (Ptitjes)" Date: Wed, 22 Nov 2017 17:06:34 +0100 Subject: [PATCH] test(ajax): admin changing user password with basic authentication --- test/test.issue.109.js | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/test.issue.109.js diff --git a/test/test.issue.109.js b/test/test.issue.109.js new file mode 100644 index 0000000..fa6eaf6 --- /dev/null +++ b/test/test.issue.109.js @@ -0,0 +1,65 @@ +'use strict'; + +var PouchDB = require('pouchdb-memory'); +var Authentication = require('../lib'); +PouchDB.plugin(Authentication); + +var utils = require('./test-utils'); +var chai = require('chai'); +chai.should(); + +describe('issue-109', function () { + + var dbName = 'http://localhost:5984/testdb'; + + var db; + + beforeEach(function () { + db = new PouchDB(dbName); + return utils.ensureUsersDatabaseExists(db).then(function () { + return db.signUpAdmin('anna', 'secret'); + }).then(function () { + return db.signUp('spiderman', 'will-forget'); + }); + }); + + afterEach(function () { + return db.logIn('anna', 'secret').then(function () { + return db.deleteUser('spiderman'); + }).then(function () { + return db.deleteAdmin('anna'); + }).then(function () { + return db.logOut(); + }).then(function () { + return db.destroy(); + }); + }); + + it('Test admin change user password with cookie authentication', function () { + return db.logIn('anna', 'secret').then(function () { + return db.changePassword('spiderman', 'will-remember'); + }).then(function (res) { + res.ok.should.equal(true); + }).then(function () { + return db.logIn('spiderman', 'will-remember'); + }).then(function (res) { + res.ok.should.equal(true); + }).then(function () { + return db.logOut(); + }); + }); + + it('Test admin change user password with basic authentication', function () { + var dbNameWithAuth = dbName.replace('http://', 'http://anna:secret@'); + var dbWithBasicAuth = new PouchDB(dbNameWithAuth, {skip_setup: true}); + return dbWithBasicAuth.changePassword('spiderman', 'will-remember').then(function (res) { + res.ok.should.equal(true); + }).then(function () { + return db.logIn('spiderman', 'will-remember'); + }).then(function (res) { + res.ok.should.equal(true); + }).then(function () { + return db.logOut(); + }); + }); +});