Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adduser gives HTTP:403 #67

Closed
cdietrich opened this issue Apr 15, 2014 · 5 comments
Closed

adduser gives HTTP:403 #67

cdietrich opened this issue Apr 15, 2014 · 5 comments
Labels

Comments

@cdietrich
Copy link

I try to setup sinopia locally.
starting sinopia gives me

# ./sinopia
Config file doesn't exist, create a new one? (Y/n) y
===========================================================
 Creating a new configuration file: "./config.yaml"

 If you want to setup npm to work with this registry,
 run following commands:

 $ npm set registry http://localhost:4873/
 $ npm set always-auth true
 $ npm adduser
   Username: admin
   Password: <Password>
===========================================================
 warn  --- Server is listening on http://localhost:4873/

now i try to configure my npm to use this repo

npm set registry http://localhost:4873/
npm set always-auth true
npm adduser

this does not work

C:\ba_dev10\jsx>npm adduser
Username: admin
Password:
Email: (this IS public) x@y.de
npm http PUT http://localhost:4873/-/user/org.couchdb.user:admin
npm http 403 http://localhost:4873/-/user/org.couchdb.user:admin
npm ERR! registry error parsing json
npm WARN adduser Incorrect username or password
npm WARN adduser You can reset your account by visiting:
npm WARN adduser
npm WARN adduser     https://npmjs.org/forgot
npm WARN adduser

what could cause this problem

@cdietrich
Copy link
Author

I just found out that this has todo with using a proxy

proxy = http://proxy.sbaintern.de:3128/
https-proxy = http://proxy.sbaintern.de:3128/

the problem is that if i remove this one sinopia cant download stuff

@cdietrich
Copy link
Author

i now configured the very same proxy in config.yaml but i dont see an option to configure strict-ssl=false

@cdietrich
Copy link
Author

And after patching sinopia to pass strictSSL false to request i get random errors like

 error --- unexpected error: EPERM, rename 'C:\xxx\node_modules\sinopia\bin\storage\glob\package.json'
Error: EPERM, rename 'C:\xxx\node_modules\sinopia\bin\storage\glob\package.json'
[Error: Can't set headers after they are sent.]
 fatal --- uncaught exception, please report this
TypeError: Cannot call method 'destroy' of null
    at ServerResponse.res.send (C:\xxx\node_modules\sinopia\lib\middleware.js:154:23)
    at ServerResponse.res.report_error (C:\xxx\node_modules\sinopia\lib\index.js:77:10)
    at ReadTarball.<anonymous> (C:\xxx\node_modules\sinopia\lib\index.js:166:15)
    at ReadTarball.EventEmitter.emit (events.js:117:20)
    at UploadTarball.<anonymous> (C:\xxx\node_modules\sinopia\lib\storage.js:255:11)
    at UploadTarball.EventEmitter.emit (events.js:117:20)
    at C:\xxx\node_modules\sinopia\lib\local-storage.js:356:12
    at C:\xxx\node_modules\sinopia\lib\local-storage.js:456:16
    at Object.oncomplete (fs.js:107:15)

# ./sinopia
 error --> using proxy http://proxy.sbaintern.de:3128/ for https://registry.npmjs.org/
 warn  --- Server is listening on http://localhost:4873/
 http  --> 200, req: 'GET https://registry.npmjs.org/grunt', bytes: 0/82569
 http  <-- 200, user: admin, req: 'GET /grunt', bytes: 0/102521
 error --> using proxy http://proxy.sbaintern.de:3128/ for http://registry.npmjs.org/grunt/-/grunt-0.4.4.tgz
 http  --> 200, req: 'GET http://registry.npmjs.org/grunt/-/grunt-0.4.4.tgz', bytes: 0/25094
 http  <-- 200, user: admin, req: 'GET /grunt/-/grunt-0.4.4.tgz', bytes: 0/25094
 error --- unexpected error: EPERM, rename 'C:\xxx\node_modules\sinopia\bin\storage\grunt\package.json'
Error: EPERM, rename 'C:\xxx\node_modules\sinopia\bin\storage\grunt\package.json'
[Error: Can't set headers after they are sent.]
 fatal --- uncaught exception, please report this
TypeError: Cannot call method 'destroy' of null
    at ServerResponse.res.send (C:\xxx\node_modules\sinopia\lib\middleware.js:154:23)
    at ServerResponse.res.report_error (C:\xxx\node_modules\sinopia\lib\index.js:77:10)
    at ReadTarball.<anonymous> (xxx\jsx\node_modules\sinopia\lib\index.js:166:15)
    at ReadTarball.EventEmitter.emit (events.js:117:20)
    at UploadTarball.<anonymous> (C:\xxx\node_modules\sinopia\lib\storage.js:255:11)
    at UploadTarball.EventEmitter.emit (events.js:117:20)
    at C:xxx\node_modules\sinopia\lib\local-storage.js:356:12
    at C:\xxx\node_modules\sinopia\lib\local-storage.js:456:16
    at Object.oncomplete (fs.js:107:15)

@korto
Copy link

korto commented Jun 1, 2014

I was having the same problem, when running sinopia in windows. At some random times, renamimg the temporary package.json file (called package.json.tmpSOME_RANDOM_NUM) to package.json failed because a file called package.json already existed in the same folder. I first tried to unlinkSync the file before the call to rename but that failed as well. In windows unlinkSync is not that synchronous, as it will wait for any open handles to the file to close first. So, I modified the sinopia\lib\local-fs.js file to rename any existing package.json to package.json.old, then call to delete that one, before the call to rename the package.json.tmp to package.json is done.

;TDLR
Try adding these two lines, in file lib\local-fs.js, before line 22 (return fs.rename(tmpname, dest, cb)):

if(fs.existsSync(dest)) fs.renameSync(dest, dest + '.old')
if(fs.existsSync(dest + '.old')) fs.unlinkSync(dest + '.old')

add these two lines before line 59 (fs.rename(tmpname, name, function(err) {):

if(fs.existsSync(name)) fs.renameSync(name, name + '.old')
if(fs.existsSync(name + '.old')) fs.unlinkSync(name + '.old')

It seems to work for me, although I 'd prefer a proper fix from the code owner when that's available.

@rlidwka rlidwka added the windows label Aug 2, 2014
ciaranj added a commit to ciaranj/sinopia that referenced this issue Sep 1, 2014
- I made various attempts to get flock working properly on windows for sinopia.
  They all seem to result in the process ending un-expctedly :/
- So in the short term this patch does seem to address a bunch of realworld issues people are seeing, however
  it also causes 3 new test breaks, so I doubt you want to actually merge it.

If I have time to cycle back to this problem I might look at re-jigging it
again
@Delagen Delagen mentioned this issue Sep 2, 2014
rlidwka added a commit that referenced this issue Nov 1, 2014
@rlidwka
Copy link
Owner

rlidwka commented Nov 1, 2014

At some random times, renamimg the temporary package.json file (called package.json.tmpSOME_RANDOM_NUM) to package.json failed because a file called package.json already existed in the same folder.

It happens when the file exists and already opened, like this:

fd = fs.createWriteStream('foo')
fs.writeFileSync('foo.tmp', 'blah')
fs.renameSync('foo.tmp', 'foo') // works on linux, fails with EPERM on windows
fs.close(fd)

On unix systems you can unlink an opened file. Filesystem will just delete a reference to it, but any program can still do i/o with the deleted file. I suppose that's why it's called "unlink", not "remove".

On windows you can't do that for some weird reason.

Anyway, I took your suggestion with fs.rename and rewrote it in async style in a854d07 . It seems to work great on windows 8, but I'm not sure about other versions.

Fix published as sinopia@0.13.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants