From c3da488c8a1a740221b0311afde28b656063ef8c Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Tue, 24 Jan 2017 16:03:37 -0800 Subject: [PATCH] auth, clone fixes. closes #97 --- lib/commands/auth/login.js | 3 ++- lib/commands/auth/register.js | 3 ++- lib/commands/clone.js | 8 +++++--- lib/commands/publish.js | 3 ++- scripts/auth-server.js | 2 +- tests/auth.js | 7 ++++--- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/commands/auth/login.js b/lib/commands/auth/login.js index 889b22c..c6725df 100644 --- a/lib/commands/auth/login.js +++ b/lib/commands/auth/login.js @@ -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) }) diff --git a/lib/commands/auth/register.js b/lib/commands/auth/register.js index 5646da7..e839678 100644 --- a/lib/commands/auth/register.js +++ b/lib/commands/auth/register.js @@ -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) }) diff --git a/lib/commands/clone.js b/lib/commands/clone.js index ada849e..1f74d35 100644 --- a/lib/commands/clone.js +++ b/lib/commands/clone.js @@ -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') }) } diff --git a/lib/commands/publish.js b/lib/commands/publish.js index 6832070..c7ec0ec 100644 --- a/lib/commands/publish.js +++ b/lib/commands/publish.js @@ -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) diff --git a/scripts/auth-server.js b/scripts/auth-server.js index 39fe26a..6f07e39 100644 --- a/scripts/auth-server.js +++ b/scripts/auth-server.js @@ -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 diff --git a/tests/auth.js b/tests/auth.js index 949581b..bcfac61 100644 --- a/tests/auth.js +++ b/tests/auth.js @@ -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) { @@ -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 })