Skip to content

Commit

Permalink
auth, clone fixes. closes #97
Browse files Browse the repository at this point in the history
  • Loading branch information
joehand committed Jan 25, 2017
1 parent 4700805 commit c3da488
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/commands/auth/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ function login (opts) {
email: user.email,
password: user.password
}, function (err, resp, body) {
if (err) ui.exitErr(err)
if (err && err.message) ui.exitErr(err.message)
else if (err) ui.exitErr(err.toString())
console.log('Logged in successfully.')
process.exit(0)
})
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/auth/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ function register (opts) {
username: user.username,
password: user.password
}, function (err) {
if (err) ui.exitErr(err)
if (err && err.message) ui.exitErr(err.message)
else if (err) ui.exitErr(err.toString())
console.log('Registered successfully.')
process.exit(0)
})
Expand Down
8 changes: 5 additions & 3 deletions lib/commands/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ function clone (opts) {
debug('Registry lookup at:', url)
nets({ url: url, json: true }, function (err, resp, body) {
if (err) return exit(err)
if (resp.statusCode !== 200) return exit(resp.message)
if (resp.statusCode !== 200) return exit(body.message)
try {
opts.key = stringKey(JSON.parse(body).url)
opts.key = stringKey(body.url)
debug('Received key from registry:', opts.key)
if (opts.key) return createDir(url.split('/').pop(), run) // dirname is name of repo
} catch (e) { }
} catch (e) {
console.error(new Error(e))
}
exit('Error getting key from registry')
})
}
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function publish (opts) {
client.secureRequest({
method: 'POST', url: '/dats', body: datInfo, json: true
}, function (err, resp, body) {
if (err) return ui.exitErr(err)
if (err && err.message) ui.exitErr(err.message)
else if (err) ui.exitErr(err.toString())
if (body.statusCode === 400) return ui.exitErr(new Error(body.message))
console.log('Successfully published!')
process.exit(0)
Expand Down
2 changes: 1 addition & 1 deletion scripts/auth-server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var createServer = require('./tests/helpers/auth-server')
var createServer = require('../tests/helpers/auth-server')

createServer(process.env.PORT || 8888, function (err, server, closeServer) {
if (err) throw err
Expand Down
7 changes: 4 additions & 3 deletions tests/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ authServer(port, function (err, server, closeServer) {

test('auth - create dat to publish', function (t) {
rimraf.sync(path.join(fixtures, '.dat'))
rimraf.sync(path.join(fixtures, 'dat.json'))
var cmd = dat + ' create --no-import'
var st = spawn(t, cmd, {cwd: fixtures})
st.stdout.match(function (output) {
Expand Down Expand Up @@ -145,14 +146,14 @@ authServer(port, function (err, server, closeServer) {
})

test('auth - bad clone from registry', function (t) {
var shortName = 'joe/not-at-all-awesome'
var shortName = 'localhost:' + port + '/joe/not-at-all-awesome'
var baseDir = path.join(baseTestDir, 'dat_registry_dir_too')
mkdirp.sync(baseDir)
var downloadDir = path.join(baseDir, shortName.split('/')[1])
var downloadDir = path.join(baseDir, shortName.split('/').pop())
var cmd = dat + ' clone ' + shortName
var st = spawn(t, cmd, {cwd: baseDir})
st.stderr.match(function (output) {
t.same(output.trim(), 'Dat archive not found on registry.', 'not found')
t.same(output.trim(), 'Dat with that name not found.', 'not found')
st.kill()
return true
})
Expand Down

0 comments on commit c3da488

Please sign in to comment.