|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var PouchDB = require('pouchdb-memory'); |
| 4 | +var Authentication = require('../lib'); |
| 5 | +PouchDB.plugin(Authentication); |
| 6 | + |
| 7 | +var utils = require('./test-utils'); |
| 8 | +var chai = require('chai'); |
| 9 | +chai.should(); |
| 10 | + |
| 11 | +describe('issue-109', function () { |
| 12 | + |
| 13 | + var dbName = 'http://localhost:5984/testdb'; |
| 14 | + |
| 15 | + var db; |
| 16 | + |
| 17 | + beforeEach(function () { |
| 18 | + db = new PouchDB(dbName); |
| 19 | + return utils.ensureUsersDatabaseExists(db).then(function () { |
| 20 | + return db.signUpAdmin('anna', 'secret'); |
| 21 | + }).then(function () { |
| 22 | + return db.signUp('spiderman', 'will-forget'); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + afterEach(function () { |
| 27 | + return db.logIn('anna', 'secret').then(function () { |
| 28 | + return db.deleteUser('spiderman'); |
| 29 | + }).then(function () { |
| 30 | + return db.deleteAdmin('anna'); |
| 31 | + }).then(function () { |
| 32 | + return db.logOut(); |
| 33 | + }).then(function () { |
| 34 | + return db.destroy(); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + it('Test admin change user password with cookie authentication', function () { |
| 39 | + return db.logIn('anna', 'secret').then(function () { |
| 40 | + return db.changePassword('spiderman', 'will-remember'); |
| 41 | + }).then(function (res) { |
| 42 | + res.ok.should.equal(true); |
| 43 | + }).then(function () { |
| 44 | + return db.logIn('spiderman', 'will-remember'); |
| 45 | + }).then(function (res) { |
| 46 | + res.ok.should.equal(true); |
| 47 | + }).then(function () { |
| 48 | + return db.logOut(); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + it('Test admin change user password with basic authentication', function () { |
| 53 | + var dbNameWithAuth = dbName.replace('http://', 'http://anna:secret@'); |
| 54 | + var dbWithBasicAuth = new PouchDB(dbNameWithAuth, {skip_setup: true}); |
| 55 | + return dbWithBasicAuth.changePassword('spiderman', 'will-remember').then(function (res) { |
| 56 | + res.ok.should.equal(true); |
| 57 | + }).then(function () { |
| 58 | + return db.logIn('spiderman', 'will-remember'); |
| 59 | + }).then(function (res) { |
| 60 | + res.ok.should.equal(true); |
| 61 | + }).then(function () { |
| 62 | + return db.logOut(); |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
0 commit comments