Jest-puppeteer: Adding server port ask for root password

Created on 15 Jul 2018  路  18Comments  路  Source: smooth-code/jest-puppeteer

This works in my system (arch linux, node 10, latest puppeteteer, jest, etc)

  launch: {
    args: ['--no-sandbox'],
  },
  server: {
    command: `node dist/test-scripts/server-mocks/server1.js`,
  }

But if I add the port number, (high number like 3001 and not busy) then the test interrupts and the terminal ask for my root password like sudo. Is that normal? I'm not entering my root password for running a test, at all and I know in my system my user has permissions to open / close it...

I'm able to run the command manually OK. I tried with headless: false, --disable-setuid-sandbox and
--usedPortAction: 'error' but with no luck,

DO you think this is a problem with sandbox ? I wanted to report this since recent security incidents in npmjs.org - sore is nothing but just in case.

Will try to reproduce the issue in jest-dev-server. Any tip / help is appreciated. Thanks - good work, keep it up

bug 馃悰

Most helpful comment

I have the same issue. This is because jest-dev-server is using find-process to find the process with a given port, and find-process is using the command sudo netstat -tunlp.

This is really unfortunate, this project seemed nice but I really can't enter my root password every time I need to run tests. I guess setting config.usedPortAction = 'ignore' should not run find-process at all, so no sudo would be needed.

All 18 comments

Hi,
I have the same issue, even if I change the rights on the npm root folder it is still asking me for my root password.
Is there any workaround that you have found @cancerberoSgx ?

I think it is a problem in your server. You should try to run "npm start" without Jest Puppeteer and see what's going on. The requirement of a root password can be multiple things: a usage of a restricted port, the execution rights of the process...

This issue is not relative to Jest Puppeteer but I let it opened if someone want to help.

@neoziro I wouldn't be so sure about "This issue is not relative to Jest Puppeteer". I use lots of different servers, using the same terminal, user, port, interface, groups, interfaces both for puppeteer and also other servers on top of jest and never had this problem. Did you tried to reproduce the issue in arch linux at least ? is as easy as providing the configuration I just did in my first comment. I had reproduce it using arch linux and manjaro linux (archlinux - based distribution). Both are very popular linux distros BTW. Will try to see if the same happens on debian or other distros but unfortunately don't have much time to invest on this. Thanks.
@CyrilQuandalle no I didn't found any workaround for this

Thank you for your answer @cancerberoSgx, @neoziro ;-)
I ended up using npm-run-all to run my tasks in parallele: starting the server and running the tests with race condition options to kill the server at the end of the tests ;-)

I have the same issue. This is because jest-dev-server is using find-process to find the process with a given port, and find-process is using the command sudo netstat -tunlp.

This is really unfortunate, this project seemed nice but I really can't enter my root password every time I need to run tests. I guess setting config.usedPortAction = 'ignore' should not run find-process at all, so no sudo would be needed.

@BenoitZugmeyer good catch thanks, so it is actually a bug.

I have the same. config.usedPortAction = 'ignore' this doesnt work for me. So how can i fix that?

Any news on this ? Why is it jest-puppeteer scanning my processes ? IMO, As the user I expect to be responsible of providing the port number, if it's busy is my problem. This tool should just open the server on that port and that's it. Thanks.

I workaround (hack) would be to put
global.process.getuid = () => 0;
at the top of the jest-puppeteer.config.js file before module.export
if it has no implications for your tests.
If it has just copy the function before global.process._getuid = global.process.getuid;
and resign it after the server starts at the beginning of your test.

I don't understand why this was closed. I would expect jest-puppeteers server setting to work out of the box with no password prompt if usedPortAction is set to error. Right now it prompts me for my password, even when the port is available(?!?).

I think it is not possible to test if port is used without sudo. In fact it is because I had never experienced this issue on Mac.

Anyway I can't do anything for it, you should investigate in find-process package and try to patch it to avoid this.

I can't see how that is necessary, unless you either want to bind to ports numbered less than 1024 or want to get the process id of the process listening to the port.

Here is a tiny POC:

node -e "server = require('net').createServer(() => {}); server.on('error', console.log); server.listen(5433);"
{ Error: listen EADDRINUSE :::5433
...

(I have something on that port.)

If usedPortAction is set to error, it won't ever be required to get the process id of the listening process.

Yes you are right, could you submit a fix?

Ok. I'm on it :-)

@neoziro - I suppose the fix goes into jest-dev-server, not jest-puppeteer.

Of course 馃槈, but it is in the same repo.

https://github.com/smooth-code/jest-puppeteer/pull/149

I haven't had time to test it yet, but I'd like to know if this is the right direction, I'm taking.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FezVrasta picture FezVrasta  路  4Comments

melissachang picture melissachang  路  6Comments

tkrotoff picture tkrotoff  路  4Comments

dptoot picture dptoot  路  4Comments

undrafted picture undrafted  路  4Comments