This commit is contained in:
Zachary Carter 2013-10-23 03:05:05 -07:00
Родитель e5aadc4163
Коммит e48de28465
2 изменённых файлов: 73 добавлений и 1 удалений

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

@ -193,6 +193,7 @@ Client.prototype.create = function (callback) {
Client.prototype._clear = function () {
this.authToken = null
this.sessionToken = null
this.srpSession = null
this.accountResetToken = null
this.keyFetchToken = null
this.forgotPasswordToken = null
@ -205,10 +206,38 @@ Client.prototype.stringify = function () {
return JSON.stringify(this)
}
Client.prototype.accountExists = function (email, callback) {
if (email) {
this.email = Buffer(email).toString('hex')
}
var K = null
var p = this.api.authStart(this.email)
.then(
function (srpSession) {
this.srpSession = srpSession
return true
}.bind(this),
function (err) {
if (err.errno === 102) {
return false
} else {
throw err
}
}
)
if (callback) {
p.done(callback.bind(null, null), callback)
}
else {
return p
}
};
Client.prototype.auth = function (callback) {
var K = null
var session
var p = this.api.authStart(this.email)
var sessionPromise = this.srpSession ? P(this.srpSession) : this.api.authStart(this.email)
var p = sessionPromise
.then(
function (srpSession) {
var k = P.defer()

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

@ -24,6 +24,8 @@ function main() {
var email3 = uniqueID() + "@example.com"
var email4 = uniqueID() + "@example.com"
var email5 = uniqueID() + "@example.com"
var email6 = uniqueID() + "@example.com"
var email7 = uniqueID() + "@example.com"
test(
'Create account flow',
@ -347,6 +349,47 @@ function main() {
}
)
test(
'Unknown account should not exist',
function (t) {
var email = email6
var client = new Client(config.public_url)
client.accountExists(email)
.then(
function (exists) {
t.equal(exists, false, "account shouldn't exist")
t.end()
}
)
}
)
test(
'Known account should exist',
function (t) {
var email = email7
var password = 'ilikepancakes'
var client
Client.create(config.public_url, email, password)
.then(
function (x) {
client = x
return client.accountExists()
}
).then(
function (exists) {
t.equal(exists, true, "account should exist")
return client.login()
}
).done(
function () {
t.ok(client.sessionToken, "client can login after accountExists")
t.end()
}
)
}
)
test(
'random bytes',
function (t) {