Server IP : 127.0.0.2 / Your IP : 18.216.60.85 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/npm/node_modules/npm-registry-client/test/ |
Upload File : |
var test = require('tap').test var server = require('./lib/server.js') var common = require('./lib/common.js') var client = common.freshClient() var cache = require('./fixtures/underscore/cache.json') var nock = require('nock') function nop () {} var URI = 'https://npm.registry:8043/rewrite' var STARRED = true var USERNAME = 'username' var PASSWORD = '%1234@asdf%' var EMAIL = 'i@izs.me' var AUTH = { username: USERNAME, password: PASSWORD, email: EMAIL } var PARAMS = { starred: STARRED, auth: AUTH } test('star call contract', function (t) { t.throws(function () { client.star(undefined, PARAMS, nop) }, 'requires a URI') t.throws(function () { client.star([], PARAMS, nop) }, 'requires URI to be a string') t.throws(function () { client.star(URI, undefined, nop) }, 'requires params object') t.throws(function () { client.star(URI, '', nop) }, 'params must be object') t.throws(function () { client.star(URI, PARAMS, undefined) }, 'requires callback') t.throws(function () { client.star(URI, PARAMS, 'callback') }, 'callback must be function') t.throws( function () { var params = { starred: STARRED } client.star(URI, params, nop) }, { name: 'AssertionError', message: 'must pass auth to star' }, 'params must include auth' ) t.end() }) test('star a package', function (t) { server.expect('GET', '/underscore?write=true', function (req, res) { t.equal(req.method, 'GET') res.json(cache) }) server.expect('PUT', '/underscore', function (req, res) { t.equal(req.method, 'PUT') var b = '' req.setEncoding('utf8') req.on('data', function (d) { b += d }) req.on('end', function () { var updated = JSON.parse(b) var already = [ 'vesln', 'mvolkmann', 'lancehunt', 'mikl', 'linus', 'vasc', 'bat', 'dmalam', 'mbrevoort', 'danielr', 'rsimoes', 'thlorenz' ] for (var i = 0; i < already.length; i++) { var current = already[i] t.ok( updated.users[current], current + ' still likes this package' ) } t.ok(updated.users[USERNAME], 'user is in the starred list') res.statusCode = 201 res.json({ starred: true }) }) }) var params = { starred: STARRED, auth: AUTH } client.star('http://localhost:1337/underscore', params, function (er, data) { t.ifError(er, 'no errors') t.ok(data.starred, 'was starred') t.end() }) }) test('if password auth, only sets authorization on put', function (t) { var starGet = nock('http://localhost:1010') .get('/underscore?write=true') .reply(200, {}) var starPut = nock('http://localhost:1010', { reqheaders: { authorization: 'Basic ' + new Buffer(AUTH.username + ':' + AUTH.password).toString('base64') } }) .put('/underscore') .reply(200) var params = { starred: STARRED, auth: AUTH } client.star('http://localhost:1010/underscore', params, function (er) { t.ifError(er, 'starred without issues') starGet.done() starPut.done() t.end() }) }) test('if token auth, sets bearer on get and put', function (t) { var starGet = nock('http://localhost:1010', { reqheaders: { authorization: 'Bearer foo' } }) .get('/underscore?write=true') .reply(200, {}) var getUser = nock('http://localhost:1010', { reqheaders: { authorization: 'Bearer foo' } }) .get('/-/whoami') .reply(200, { username: 'bcoe' }) var starPut = nock('http://localhost:1010', { reqheaders: { authorization: 'Bearer foo' } }) .put('/underscore') .reply(200) var params = { starred: STARRED, auth: { token: 'foo' } } client.star('http://localhost:1010/underscore', params, function (er) { t.ifError(er, 'starred without error') starGet.done() starPut.done() getUser.done() t.end() }) }) test('cleanup', function (t) { server.close() t.end() })