diff --git a/lib/index.js b/lib/index.js index 857c71164..2f8f5d3b1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -32,7 +32,7 @@ module.exports = function(config_hash) { app.use(etagify); app.use(basic_auth(function(user, pass) { return config.authenticate(user, pass); - })); + })); app.use(express.bodyParser()); // TODO: npm DO NOT support compression :( diff --git a/lib/multiplexer.js b/lib/multiplexer.js new file mode 100644 index 000000000..acb322eb2 --- /dev/null +++ b/lib/multiplexer.js @@ -0,0 +1,16 @@ +/* +module.exports = function() { + local_store() + for each uplink + status = uplink_store() + if (status == 201) { + succeess.push(uplink) + } else { + bail() + } + + bail: + local_revert() + uplink_revert() +}; +*/ diff --git a/test/basic.js b/test/basic.js index 62a37ee42..d6ae17d94 100644 --- a/test/basic.js +++ b/test/basic.js @@ -14,7 +14,7 @@ ex['trying to fetch non-existent package'] = function(cb) { }; ex['creating new package'] = function(cb) { - server.put_package('testpkg', readfile('fixtures/test-package.json'), function(res, body) { + server.put_package('testpkg', require('./lib/package')('testpkg'), function(res, body) { assert.equal(res.statusCode, 201); assert(~body.ok.indexOf('created new package')); cb(); @@ -52,7 +52,7 @@ ex['downloading newly created tarball'] = function(cb) { }; ex['uploading new package version'] = function(cb) { - server.put_version('testpkg', '0.0.1', readfile('fixtures/test-package.json'), function(res, body) { + server.put_version('testpkg', '0.0.1', require('./lib/package')('testpkg'), function(res, body) { assert.equal(res.statusCode, 201); assert(~body.ok.indexOf('published')); cb(); @@ -63,9 +63,9 @@ ex['downloading newly created package'] = function(cb) { server.get_package('testpkg', function(res, body) { assert.equal(res.statusCode, 200); assert.equal(body.name, 'testpkg'); - assert.equal(body.versions['0.0.1'].name, 'testpkg'); - assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/testpkg/-/blahblah'); - assert.deepEqual(body['dist-tags'], {latest: '0.0.1'}); + assert.equal(body.versions['0.0.1'].name, 'testpkg'); + assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/testpkg/-/blahblah'); + assert.deepEqual(body['dist-tags'], {latest: '0.0.1'}); cb(); }); }; @@ -74,9 +74,9 @@ ex['downloading package via server2'] = function(cb) { server2.get_package('testpkg', function(res, body) { assert.equal(res.statusCode, 200); assert.equal(body.name, 'testpkg'); - assert.equal(body.versions['0.0.1'].name, 'testpkg'); - assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55552/testpkg/-/blahblah'); - assert.deepEqual(body['dist-tags'], {latest: '0.0.1'}); + assert.equal(body.versions['0.0.1'].name, 'testpkg'); + assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55552/testpkg/-/blahblah'); + assert.deepEqual(body['dist-tags'], {latest: '0.0.1'}); cb(); }); }; diff --git a/test/config-1.yaml b/test/config-1.yaml index cd64458db..6524068fe 100644 --- a/test/config-1.yaml +++ b/test/config-1.yaml @@ -14,6 +14,12 @@ packages: allow_publish: all proxy_access: server2 proxy_publish: server2 + + 'testloop': + allow_access: all + allow_publish: all + proxy_access: server2 + proxy_publish: server2 '*': allow_access: test anonymous diff --git a/test/config-2.yaml b/test/config-2.yaml index fa97f1ad6..0e582f209 100644 --- a/test/config-2.yaml +++ b/test/config-2.yaml @@ -12,6 +12,12 @@ packages: 'testfwd': allow_access: all allow_publish: all + + 'testloop': + allow_access: all + allow_publish: all + proxy_access: server1 + proxy_publish: server1 testpkg: allow_access: test anonymous diff --git a/test/fixtures/fwd-package.json b/test/fixtures/fwd-package.json deleted file mode 100644 index 4f6371b61..000000000 --- a/test/fixtures/fwd-package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "testfwd", - "version": "0.0.0", - "dist": { - "shasum": "fake", - "tarball": "http://localhost:55551/testpkg/-/blahblah" - } -} diff --git a/test/fixtures/test-package.json b/test/fixtures/test-package.json deleted file mode 100644 index c1d68ca47..000000000 --- a/test/fixtures/test-package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "testpkg", - "version": "0.0.0", - "dist": { - "shasum": "fake", - "tarball": "http://localhost:55551/testpkg/-/blahblah" - } -} diff --git a/test/lib/package.js b/test/lib/package.js new file mode 100644 index 000000000..5768910d9 --- /dev/null +++ b/test/lib/package.js @@ -0,0 +1,12 @@ + +module.exports = function(name) { + return { + "name": name, + "version": "0.0.0", + "dist": { + "shasum": "fake", + "tarball": "http://localhost:55551/"+escape(name)+"/-/blahblah" + } + }; +} + diff --git a/test/mirror.js b/test/mirror.js index 13f352f45..02cf30419 100644 --- a/test/mirror.js +++ b/test/mirror.js @@ -4,51 +4,64 @@ var ex = module.exports; var server = process.server; var server2 = process.server2; -ex['creating new package'] = function(cb) { - server.put_package('testfwd', readfile('fixtures/fwd-package.json'), function(res, body) { - assert.equal(res.statusCode, 201); - assert(~body.ok.indexOf('created new package')); - cb(); - }); -}; +['fwd', 'loop'].forEach(function(pkg) { + var prefix = pkg+': '; + pkg = 'test'+pkg; -ex['uploading new package version'] = function(cb) { - server.put_version('testfwd', '0.1.1', readfile('fixtures/fwd-package.json'), function(res, body) { - assert.equal(res.statusCode, 201); - assert(~body.ok.indexOf('published')); - cb(); - }); -}; + ex[prefix+'creating new package'] = function(cb) { + server.put_package(pkg, require('./lib/package')(pkg), function(res, body) { + assert.equal(res.statusCode, 201); + assert(~body.ok.indexOf('created new package')); + cb(); + }); + }; -ex['downloading package via server2'] = function(cb) { - server2.get_package('testfwd', function(res, body) { - assert.equal(res.statusCode, 200); - assert.equal(body.name, 'testfwd'); - assert.equal(body.versions['0.1.1'].name, 'testfwd'); - assert.equal(body.versions['0.1.1'].dist.tarball, 'http://localhost:55552/testpkg/-/blahblah'); - cb(); - }); -}; + ex[prefix+'uploading new package version'] = function(cb) { + server.put_version(pkg, '0.1.1', require('./lib/package')(pkg), function(res, body) { + assert.equal(res.statusCode, 201); + assert(~body.ok.indexOf('published')); + cb(); + }); + }; -ex['uploading incomplete tarball'] = function(cb) { - server.put_tarball_incomplete('testfwd', 'testfwd.bad', readfile('fixtures/binary'), 3000, function(res, body) { - cb(); - }); -}; + ex[prefix+'downloading package via server2'] = function(cb) { + server2.get_package(pkg, function(res, body) { + assert.equal(res.statusCode, 200); + assert.equal(body.name, pkg); + assert.equal(body.versions['0.1.1'].name, pkg); + assert.equal(body.versions['0.1.1'].dist.tarball, 'http://localhost:55552/'+pkg+'/-/blahblah'); + cb(); + }); + }; -ex['uploading new tarball'] = function(cb) { - server.put_tarball('testfwd', 'testfwd.file', readfile('fixtures/binary'), function(res, body) { - assert.equal(res.statusCode, 201); - assert(body.ok); - cb(); - }); -}; + ex[prefix+'uploading incomplete tarball'] = function(cb) { + server.put_tarball_incomplete(pkg, pkg+'.bad', readfile('fixtures/binary'), 3000, function(res, body) { + cb(); + }); + }; -ex['downloading tarball from server2'] = function(cb) { - server2.get_tarball('testfwd', 'testfwd.file', function(res, body) { - assert.equal(res.statusCode, 200); - assert.deepEqual(body, readfile('fixtures/binary').toString('utf8')); - cb(); - }); -}; + ex[prefix+'uploading new tarball'] = function(cb) { + server.put_tarball(pkg, pkg+'.file', readfile('fixtures/binary'), function(res, body) { + assert.equal(res.statusCode, 201); + assert(body.ok); + cb(); + }); + }; + + ex[prefix+'downloading tarball from server1'] = function(cb) { + server.get_tarball(pkg, pkg+'.file', function(res, body) { + assert.equal(res.statusCode, 200); + assert.deepEqual(body, readfile('fixtures/binary').toString('utf8')); + cb(); + }); + }; + + ex[prefix+'downloading tarball from server2'] = function(cb) { + server2.get_tarball(pkg, pkg+'.file', function(res, body) { + assert.equal(res.statusCode, 200); + assert.deepEqual(body, readfile('fixtures/binary').toString('utf8')); + cb(); + }); + }; +});