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

fix(web-server) Fix 581 https support for karma server #1160

Conversation

JayBerlin
Copy link

This PR implements support for running the karma proxy server as https so that karma is able to proxy a secure site and handle secure cookies. It really just some formalization of danielabar's hack as I need this to support some internal e2e testing using karma.

To us this, add this to the karma.conf.js file:

protocol: 'https'

By default, this will create a self-signed certificate that lasts 1 day to be used by the karma server. If you want to supply your own certificate, add the following property to the karma.conf.js file:

cert: {
   key: 'name_of_key.pem_file',
   cert: 'name_of_cert.pem_file'
}

Caveats:

  • If you are using self-signed certificates, you need to modify the karma-chrome-launcher module by adding these additional options when launching:

    '--ignore-certificate-errors',
    '--ignore-urlfetcher-cert-requests',

Otherwise, the browser will hang waiting for a confirmation that it is okay to visit a site with a self-signed certificate. I have not found a way to do this for Firefox or other browsers.

  • I found that I had to use version 0.8.3 of the modified node-http-proxy in place of the default http-proxy in order to run e2e tests with embedded frames. This version properly handles location header rewriting so that access to proxied content within an iframe works properly. This was an issue for us when redirects were occurring.

Not sure if this is worth pulling into karma for everyone as there are some pretty big caveats, but wanted to get a PR in place as we are using this now.

Jay Berlin and others added 4 commits August 7, 2014 18:15
Add config.protocol = 'http' or 'https' to indicate running Karma server in
http or https mode (to ensure secure cookies are handled properly from the
proxied urls).

Add config.cert { key: 'file_name', cert: 'file_name' } to identify the .pem
files to use for the server certificate.

This fix requires node-http-proxy from https://github.com/jayv/node-http-proxy
as this is the only http-proxy implementation that properly supports rewriting
the Location headers.

Closes karma-runner#581
Add 'pem' dependency to allow for creating one-time certificates
when config.cert.key/cert are not specified.

Cleanup of some lint errors (oops)

Closes karma-runner#581
Add tests to validate configuration settings are properly handled and
refactor one-time certificate handling a little to make it easier to
test.

Closes karma-runner#581
@JayBerlin JayBerlin changed the title Fix 581 https support for karma server fix(web-server) Fix 581 https support for karma server Aug 15, 2014
@dignifiedquire
Copy link
Member

First, sorry for the late feedback. This looks like a good idea to me and it seems there is more need for this, see the newer #1400 and #1401. So I would really like to get this in, could you rebase onto the latest master and squash the latest commit?

@dignifiedquire
Copy link
Member

Closing due to inactivity

@mystro-bryce
Copy link

@JayBerlin have you had any luck polishing off @dignifiedquire's final requests? I'd love to see this in Karma proper ASAP.

@dignifiedquire is there something I can do to help this along? I'm not sure what needs to be done.

@JayBerlin
Copy link
Author

I have been away from this code for the last several months. I will see if I can resurrect it and get an environment set up to merge this in, but will not be able to get to it for several days. Anyone else is more than welcome to do so in the interim.

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

Successfully merging this pull request may close these issues.

3 participants