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

Create an endpoint to change the default port for new access keys #461

Merged
merged 35 commits into from Aug 15, 2019

Conversation

JonathanDCohen
Copy link
Contributor

Adds endpoints and implementations
Adds tests for new api
Adds tests for newly public functions from get_port
Cleans up some deprecated code from before multiplexing was enabled.
Cleans up some unused imports in tests.
Creates and uses a builder class for the ServerAccessRepository unit tests

Copy link
Contributor

@alalamav alalamav left a comment

Choose a reason for hiding this comment

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

Some minor comments/suggestions. Loving the typed errors and repo builder 👍

src/shadowbox/infrastructure/get_port.spec.ts Show resolved Hide resolved
src/shadowbox/server/api.yml Outdated Show resolved Hide resolved
src/shadowbox/server/manager_service.ts Outdated Show resolved Hide resolved
src/shadowbox/server/manager_service.ts Show resolved Hide resolved
src/shadowbox/server/server_access_key.spec.ts Outdated Show resolved Hide resolved
src/shadowbox/server/server_access_key.ts Outdated Show resolved Hide resolved
src/shadowbox/server/server_access_key.ts Outdated Show resolved Hide resolved
@JonathanDCohen
Copy link
Contributor Author

Responded to review comments, PTAL

Copy link
Contributor

@alalamav alalamav left a comment

Choose a reason for hiding this comment

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

LGTM 👍

src/shadowbox/server/main.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

A few initial comments. I didn't have a chance to look at the tests yet.

src/shadowbox/model/access_key.ts Outdated Show resolved Hide resolved
src/shadowbox/model/errors.ts Outdated Show resolved Hide resolved
src/shadowbox/model/errors.ts Outdated Show resolved Hide resolved
src/shadowbox/model/access_key.ts Outdated Show resolved Hide resolved
src/shadowbox/server/manager_service.ts Outdated Show resolved Hide resolved
src/shadowbox/server/server_access_key.ts Outdated Show resolved Hide resolved
src/shadowbox/server/server_access_key.ts Show resolved Hide resolved
src/shadowbox/server/server_access_key.ts Outdated Show resolved Hide resolved
src/shadowbox/server/manager_service.ts Show resolved Hide resolved
src/shadowbox/server/manager_service.ts Outdated Show resolved Hide resolved
@JonathanDCohen
Copy link
Contributor Author

Ping on this ^_^ waiting for some answers before doing another round of review response.

src/shadowbox/server/manager_service.ts Show resolved Hide resolved
src/shadowbox/server/manager_service.ts Show resolved Hide resolved
src/shadowbox/model/errors.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

It seems the JSON parser will actually give you a number for port. I'm sorry for the confusion!
Let's test manually with curl and add a test to the integration test to make sure this is working properly.

src/shadowbox/server/manager_service.ts Outdated Show resolved Hide resolved
src/shadowbox/server/manager_service.ts Outdated Show resolved Hide resolved
src/shadowbox/server/manager_service.spec.ts Outdated Show resolved Hide resolved
src/shadowbox/server/manager_service.ts Outdated Show resolved Hide resolved
@JonathanDCohen
Copy link
Contributor Author

Friendly ping

Copy link
Collaborator

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

Nice to see the integration test!

src/shadowbox/server/manager_service.ts Show resolved Hide resolved
src/shadowbox/server/manager_service.spec.ts Show resolved Hide resolved
} catch (error) {
logging.error(error);
if (error instanceof errors.InvalidPortNumber) {
return next(invalidPortArgument(error.message));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you use resitfy.BadRequestError here instead? It makes it easier to see what HTTP error is being returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what invalidPortArgument does, I just moved it into a function since there are a few different places dealing with invalid port numbers. Made the function local to setPortForNewAccessKeys so it's closer to the use

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd still like to be able to easily see what the HTTP error we are returning, since that's part of the API.
Changing the calls to BadRequestError would make that clearer, I don't think the duplication is a big deal.

Maybe you want a IsValidPort method that validates the port and raises InvalidPortNumber. That would remove the duplication and improve readability.

src/shadowbox/server/manager_service.spec.ts Show resolved Hide resolved
src/shadowbox/server/manager_service.spec.ts Outdated Show resolved Hide resolved
src/shadowbox/server/manager_service.ts Outdated Show resolved Hide resolved
logging.debug(`setPort[ForNewAccessKeys request ${JSON.stringify(req.params)}`);
if (!req.params.port) {
return next(
invalidPortArgument(`Expected a port argument but found none. Request: ${req}`));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the request from the reason message. No need to send it back to the user.

Maybe also use more direct text: Parameter port is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


const port = req.params.port;
if (typeof port !== 'number') {
return next(invalidPortArgument(`Expected an numeric port, instead got ${port}`));
Copy link
Collaborator

Choose a reason for hiding this comment

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

got ${port} of type ${typeof port}, since the type is the sticking point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

} catch (error) {
logging.error(error);
if (error instanceof errors.InvalidPortNumber) {
return next(invalidPortArgument(error.message));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel a little nervous about forwarding error messages like that. It's a good way to leak potentially sensitive information. It's ok to log, but it's risky to send arbitrary messages back to the client.

Maybe rename the message field to reason or explanation, so it's more restricted in its semantics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't an arbitrary message, it's from InvalidPortNumber which is only ever made by us and has the stringified port number as the message. I can't rename the message field since it's part of the Error interface.

Are you worried that somehow this response could expose the manager server to a probing attacker?

@fortuna
Copy link
Collaborator

fortuna commented Aug 13, 2019

Can you give an example of the output in case of API error?

Copy link
Collaborator

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

Let's discuss offline

src/shadowbox/server/manager_service.ts Outdated Show resolved Hide resolved
src/shadowbox/server/manager_service.ts Outdated Show resolved Hide resolved
src/shadowbox/model/errors.ts Show resolved Hide resolved
@JonathanDCohen JonathanDCohen merged commit 16f6c15 into master Aug 15, 2019
@sbruens sbruens deleted the cohenjon-port-hostname branch March 5, 2024 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants