Skip to content

feat(base-driver): add https server support#18562

Closed
devhazem wants to merge 1 commit intoappium:masterfrom
devhazem:master
Closed

feat(base-driver): add https server support#18562
devhazem wants to merge 1 commit intoappium:masterfrom
devhazem:master

Conversation

@devhazem
Copy link

@devhazem devhazem commented Apr 23, 2023

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 x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in 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.

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

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...

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Apr 23, 2023

CLA Not Signed

@github-actions github-actions bot added @appium/base-driver appium core chore refactoring, overhead, tests, etc. Dependencies issues with dependencies Documentation related to writing, reading, or generating documentation Enhancement feature labels Apr 23, 2023
@mykola-mokhnach mykola-mokhnach requested a review from jlipps April 23, 2023 18:16
@mykola-mokhnach
Copy link
Collaborator

@devhazem Could you please describe the purpose of the PR and sign the CLA?

@devhazem
Copy link
Author

@devhazem Could you please describe the purpose of the PR and sign the CLA?
@mykola-mokhnach I have described the purpose of this PR. I will shortly sign the CLA too.

@devhazem devhazem force-pushed the master branch 3 times, most recently from 5653da7 to 6e8cebf Compare April 24, 2023 05:23
Copy link
Member

@jlipps jlipps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @devhazem! this is a good idea. i made some comments.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be documented in the docs as well, please!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have typedoc docstrings for all the member fields and methods in this file.


class SslHandler {
constructor() {
this.secure = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = []) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this test only work on macos or *nix?

afterEach(async function () {
try {
await hwServer.close();
//await httpHwServer.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be commented out?

given(givens).it(
'should allow one or more plugins to update the server',
async function ({protocol}) {
let correctPort;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throughout this file i think we can use port instead of correctPort


const log = logger.getLogger('Appium');

class SslHandler {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mocha-testdata is deprecated; please remove

describe('server', function () {
let hwServer;
let port;
let httpHwServer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of these should be typed

Comment on lines +196 to +197
let {data} = await axios.get(`${protocol}://${TEST_HOST}:${correctPort}/plugin1`);
data.should.eql('res from plugin1 route');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use expressions like this instead (here and elsewhere):

Suggested change
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/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}).should.eventually.be.rejectedWith(/ugh/);
}).should.be.rejectedWith(/ugh/);

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

Labels

@appium/base-driver appium core chore refactoring, overhead, tests, etc. Dependencies issues with dependencies Documentation related to writing, reading, or generating documentation Enhancement feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants