feat(base-driver): add https server support#18562
feat(base-driver): add https server support#18562devhazem wants to merge 1 commit intoappium:masterfrom
Conversation
|
|
@devhazem Could you please describe the purpose of the PR and sign the CLA? |
|
5653da7 to
6e8cebf
Compare
| single server process. Refer the corresponding driver documentations regarding which mode is optimal | ||
| for the particular driver or whether it supports parallel sessions. | ||
|
|
||
| Appium runs by default on an HTTP server. If an HTTPS server should be used instead, simply set |
There was a problem hiding this comment.
this should be documented in the docs as well, please!
There was a problem hiding this comment.
imo these should be server options; configurable in a config file or via CLI args. env vars probably ok too, but otherwise it deviates from how people normally configure appium.
| @@ -0,0 +1,66 @@ | |||
| import {readFileSync} from 'fs'; | |||
There was a problem hiding this comment.
I think we should have typedoc docstrings for all the member fields and methods in this file.
|
|
||
| class SslHandler { | ||
| constructor() { | ||
| this.secure = false; |
There was a problem hiding this comment.
Our pattern for classes is to define member fields up top. This can also avoid the need for a constructor. something like this:
class SslHandler {
/** @type {boolean} */
secure = false;and so on
| ); | ||
| } | ||
| log.info(`ENV 'APPIUM_SSL_KEY_PATH' is set to '${keyPath}'`); | ||
| this.httpsOptions = {cert: readFileSync(certPath), key: readFileSync(keyPath)}; |
There was a problem hiding this comment.
these should be async calls. that means this function, and the getInstance function should also be async
| */ | ||
| handleHttpsOptions() { | ||
| const secure = process.env.APPIUM_SECURE; | ||
| if (secure === 'true') { |
There was a problem hiding this comment.
i think we should allow both true and 1 as values
| let givens = [{protocol: 'http'}, {protocol: 'https'}]; | ||
|
|
||
| async function startHttpsServer(port, routeConfiguringFunction, serverUpdaters = []) { | ||
| await exec('openssl genrsa 2048 > private.pem'); |
There was a problem hiding this comment.
where will this file be generated? should we not use an absolute path to be sure we're not littering test data around the filesystem or overwriting files?
There was a problem hiding this comment.
use a JS wrapper for generating a keypair. this will fail when we add windows to the matrix.
|
|
||
| let givens = [{protocol: 'http'}, {protocol: 'https'}]; | ||
|
|
||
| async function startHttpsServer(port, routeConfiguringFunction, serverUpdaters = []) { |
There was a problem hiding this comment.
will this test only work on macos or *nix?
| afterEach(async function () { | ||
| try { | ||
| await hwServer.close(); | ||
| //await httpHwServer.close(); |
| given(givens).it( | ||
| 'should allow one or more plugins to update the server', | ||
| async function ({protocol}) { | ||
| let correctPort; |
There was a problem hiding this comment.
throughout this file i think we can use port instead of correctPort
|
|
||
| const log = logger.getLogger('Appium'); | ||
|
|
||
| class SslHandler { |
There was a problem hiding this comment.
it sort of feels like this could all simply be a single async function rather than a class. after we construct the httpsoptions we're not doing very much with this class. it doesn't have behaviours on it really.
| import B from 'bluebird'; | ||
| import _ from 'lodash'; | ||
| import {TEST_HOST, getTestPort} from '@appium/driver-test-support'; | ||
| import {given} from 'mocha-testdata'; |
| describe('server', function () { | ||
| let hwServer; | ||
| let port; | ||
| let httpHwServer; |
There was a problem hiding this comment.
all of these should be typed
| let {data} = await axios.get(`${protocol}://${TEST_HOST}:${correctPort}/plugin1`); | ||
| data.should.eql('res from plugin1 route'); |
There was a problem hiding this comment.
use expressions like this instead (here and elsewhere):
| let {data} = await axios.get(`${protocol}://${TEST_HOST}:${correctPort}/plugin1`); | |
| data.should.eql('res from plugin1 route'); | |
| await axios.get(`${protocol}://${TEST_HOST}:${correctPort}/plugin1`).should.eventually.eql({data: 'res from plugin1 route'}); |
| throw new Error('ugh'); | ||
| }, | ||
| ], | ||
| }).should.eventually.be.rejectedWith(/ugh/); |
There was a problem hiding this comment.
| }).should.eventually.be.rejectedWith(/ugh/); | |
| }).should.be.rejectedWith(/ugh/); |
Proposed changes
Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.
I have implemented this feature as I need appium to run on HTTPS to make communication from an application running on HTTPS posssible.
Types of changes
What types of changes does your code introduce to Appium?
Put an
xin the boxes that applyChecklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...