Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #243 from mozilla/raw_password_client
Browse files Browse the repository at this point in the history
add raw password apis to client api
  • Loading branch information
ckarlof committed Oct 23, 2013
2 parents 0e5360b + 768649b commit 1a5060c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 68 deletions.
24 changes: 24 additions & 0 deletions client/api.js
Expand Up @@ -315,6 +315,30 @@ ClientApi.prototype.sessionDestroy = function (sessionTokenHex) {
)
}

ClientApi.prototype.rawPasswordAccountCreate = function (email, password) {
return this.doRequest(
'POST',
this.baseURL + '/raw_password/account/create',
null,
{
email: email,
password: password
}
)
}

ClientApi.prototype.rawPasswordSessionCreate = function (email, password) {
return this.doRequest(
'POST',
this.baseURL + '/raw_password/session/create',
null,
{
email: email,
password: password
}
)
}

ClientApi.heartbeat = function (origin) {
return (new ClientApi(origin)).doRequest('GET', origin + '/__heartbeat__')
}
Expand Down
126 changes: 58 additions & 68 deletions test/run/integration_tests.js
Expand Up @@ -3,7 +3,6 @@ var cp = require('child_process')
var crypto = require('crypto');
var Client = require('../../client')
var config = require('../../config').root()
var request = require('request')

process.env.DEV_VERIFIED = 'true'

Expand Down Expand Up @@ -77,96 +76,87 @@ function main() {
test(
'(reduced security) Login with email and password',
function (t) {
request(
{
method: 'POST',
url: config.public_url + '/v1/raw_password/session/create',
json: {
email: Buffer(email1).toString('hex'),
password: 'allyourbasearebelongtous'
var clientApi = new Client.Api(config.public_url)
var email = Buffer(email1).toString('hex')
var password = 'allyourbasearebelongtous'
clientApi.rawPasswordSessionCreate(email, password)
.then(
function (result) {
t.equal(typeof(result.sessionToken), 'string', 'sessionToken exists')
t.end()
}
},
function (err, res, body) {
t.equal(typeof(body.sessionToken), 'string', 'sessionToken exists')
t.end()
}
)
)
}
)

test(
'(reduced security) Login with email and wrong password',
function (t) {
request(
{
method: 'POST',
url: config.public_url + '/v1/raw_password/session/create',
json: {
email: Buffer(email1).toString('hex'),
password: 'xxx'
var clientApi = new Client.Api(config.public_url)
var email = Buffer(email1).toString('hex')
var password = 'xxx'
clientApi.rawPasswordSessionCreate(email, password)
.then(
function (result) {
t.fail('login succeeded')
t.end()
},
function (err) {
t.equal(err.errno, 103)
t.end()
}
},
function (err, res, body) {
t.equal(body.errno, 103)
t.end()
}
)
)
}
)

test(
'(reduced security) Login with unknown email',
function (t) {
request(
{
method: 'POST',
url: config.public_url + '/v1/raw_password/session/create',
json: {
email: Buffer('x@y.me').toString('hex'),
password: 'allyourbasearebelongtous'
var clientApi = new Client.Api(config.public_url)
var email = Buffer('x@y.me').toString('hex')
var password = 'allyourbasearebelongtous'
clientApi.rawPasswordSessionCreate(email, password)
.done(
function (result) {
t.fail('login succeeded')
t.end()
},
function (err) {
t.equal(err.errno, 102)
t.end()
}
},
function (err, res, body) {
t.equal(body.errno, 102)
t.end()
}
)
)
}
)

test(
'(reduced security) Create account',
function (t) {
var clientApi = new Client.Api(config.public_url)
var email = Buffer(email5).toString('hex')
var password = 'newPassword'
request(
{
method: 'POST',
url: config.public_url + '/v1/raw_password/account/create',
json: {
email: Buffer(email5).toString('hex'),
password: password
clientApi.rawPasswordAccountCreate(email, password)
.done(
function (result) {
var client = null
t.equal(typeof(result.uid), 'string')
Client.login(config.public_url, email5, password)
.then(
function (x) {
client = x
return client.keys()
}
)
.then(
function (keys) {
t.equal(typeof(keys.kA), 'string', 'kA exists')
t.equal(typeof(keys.wrapKb), 'string', 'wrapKb exists')
t.equal(client.kB.length, 64, 'kB exists, has the right length')
t.end()
}
)
}
},
function (err, res, body) {
var client = null
t.equal(typeof(body.uid), 'string')
Client.login(config.public_url, email5, password)
.then(
function (x) {
client = x
return client.keys()
}
)
.then(
function (keys) {
t.equal(typeof(keys.kA), 'string', 'kA exists')
t.equal(typeof(keys.wrapKb), 'string', 'wrapKb exists')
t.equal(client.kB.length, 64, 'kB exists, has the right length')
t.end()
}
)
}
)
)
}
)

Expand Down

0 comments on commit 1a5060c

Please sign in to comment.