added /account/destroy integration test

This commit is contained in:
Danny Coates 2013-08-09 11:01:46 -07:00
Родитель 5d8c98c74a
Коммит dcf69ff1cf
3 изменённых файлов: 114 добавлений и 25 удалений

Просмотреть файл

@ -22,6 +22,7 @@ function Client(origin) {
this.keyFetchToken = null
this.kA = null
this.wrapKb = null
this._devices = null
}
Client.Api = ClientApi
@ -130,6 +131,16 @@ Client.prototype.create = function (callback) {
}
}
Client.prototype._clear = function () {
this.authToken = null
this.sessionToken = null
this.accountResetToken = null
this.keyFetchToken = null
this.kA = null
this.wrapKb = null
this._devices = null
}
Client.prototype.stringify = function () {
return JSON.stringify(this)
}
@ -169,7 +180,6 @@ Client.prototype.auth = function (callback) {
}
Client.prototype.login = function (callback) {
var K = null
var p = this.auth()
.then(
function (authToken) {
@ -223,7 +233,6 @@ Client.prototype.sign = function (publicKey, duration, callback) {
}
Client.prototype.changePassword = function (newPassword, callback) {
var K = null
var p = this.auth()
.then(
function () {
@ -246,11 +255,7 @@ Client.prototype.changePassword = function (newPassword, callback) {
this.accountResetToken = tokens.accountResetToken
}.bind(this)
)
.then(
function () {
return this.keys()
}.bind(this)
)
.then(this.keys.bind(this))
.then(
function () {
return tokens.AccountResetToken.fromHex(this.accountResetToken)
@ -274,6 +279,7 @@ Client.prototype.changePassword = function (newPassword, callback) {
)
}.bind(this)
)
.then(this._clear.bind(this))
if (callback) {
p.done(callback.bind(null, null), callback)
}
@ -314,6 +320,43 @@ Client.prototype.keys = function (callback) {
}
}
//TODO recovery methods, devices, forgot password, session status/destroy
Client.prototype.devices = function (callback) {
var o = this.sessionToken ? P(null) : this.login()
var p = o.then(
function () {
return this.api.accountDevices(this.sessionToken)
}.bind(this)
)
.then(
function (json) {
this._devices = json.devices
return this._devices
}.bind(this)
)
if (callback) {
p.done(callback.bind(null, null), callback)
}
else {
return p
}
}
Client.prototype.destroyAccount = function (callback) {
var p = this.auth()
.then(
function () {
return this.api.accountDestroy(this.authToken)
}.bind(this)
)
.then(this._clear.bind(this))
if (callback) {
p.done(callback.bind(null, null), callback)
}
else {
return p
}
}
//TODO recovery methods, forgot password, session status/destroy
module.exports = Client

Просмотреть файл

@ -140,10 +140,11 @@ module.exports = function (inherits, Token, db) {
)
.then(
function (data) {
this.hmacKey = data[1].slice(0, 32).toString('hex')
this.xorKey = data[1].slice(32, 96).toString('hex')
return this
}.bind(this)
var token = new Token()
token.hmacKey = data[1].slice(0, 32).toString('hex')
token.xorKey = data[1].slice(32, 96).toString('hex')
return token
}
)
.then(
function (token) {

Просмотреть файл

@ -38,8 +38,8 @@ function main() {
)
.then(
function (keys) {
t.equal(typeof(keys.kA), 'string')
t.equal(typeof(keys.wrapKb), 'string')
t.equal(typeof(keys.kA), 'string', 'kA exists')
t.equal(typeof(keys.wrapKb), 'string', 'wrapKb exists')
}
)
.then(
@ -49,7 +49,7 @@ function main() {
)
.then(
function (cert) {
t.equal(typeof(cert), 'string')
t.equal(typeof(cert), 'string', 'cert exists')
}
)
.done(
@ -70,26 +70,34 @@ function main() {
var email = Buffer('test2@example.com').toString('hex')
var password = 'allyourbasearebelongtous'
var newPassword = 'foobar'
var wrapKb = null
var client = null
Client.create(config.public_url, email, password)
.then(
function (x) {
client = x
return client.changePassword(newPassword)
}
)
.then(
function () {
t.equal(client.password, newPassword)
// kill sessionToken to 'logout'
client.sessionToken = null
return client.keys()
}
)
.then(
function (keys) {
t.equal(typeof(keys.kA), 'string')
t.equal(typeof(keys.wrapKb), 'string')
wrapKb = keys.wrapKb
}
)
.then(
function () {
return client.changePassword(newPassword)
}
)
.then(
function () {
t.equal(client.password, newPassword, 'password has changed')
return client.keys()
}
)
.then(
function (keys) {
t.equal(keys.wrapKb, wrapKb, 'wrapKb is preserved')
}
)
.done(
@ -104,6 +112,43 @@ function main() {
}
)
test(
'account destroy',
function (t) {
var email = Buffer('test3@example.com').toString('hex')
var password = 'allyourbasearebelongtous'
var client = null
Client.create(config.public_url, email, password)
.then(
function (x) {
client = x
return client.devices()
}
)
.then(
function (devices) {
t.equal(devices.length, 1, 'we have an account')
return client.destroyAccount()
}
)
.then(
function () {
return client.keys()
}
)
.done(
function (keys) {
t.fail('account not destroyed')
t.end()
},
function (err) {
t.equal(err.message, 'Unknown account', 'account destroyed')
t.end()
}
)
}
)
test(
'teardown',
function (t) {