Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Sturdier approveDomains logic #74

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

martinheidegger
Copy link
Contributor

This PR is making approveDomains sturdier for following cases:

  • Former logic didn't work if config.hostname was a subdomain (or a sub-subdomain). example: service.mydomain.com
  • Former logic used a <archive>.<user>.<hostname* in per-archive mode, instead of the correct <archive>-<user>.<hostname>.
  • Former logic accepted all subdomains in per-user mode, no matter if the user existed or not. (userRecord can be null)
  • Former logic was written in return-first-on-success code logic order. This is written in return-first-on-error making it easier to read.

I would love to get some guidance/mentoring on where to write proper tests for this. Also: it seems like there should be some central logic that maps domains to domain-render-object. I.e. app.getDomainContext(domain) to return either the "main" domain context or the context for user/archive.

Making approveDomains sturdier for following cases:
- Former logic didn't work if `config.hostname` was a subdomain (or a sub-subdomain). example: `service.mydomain.com`
- Former logic used a `<archive>.<user>.<hostname*` in `per-archive` mode, instead of the correct `<archive>-<user>.<hostname>`.
- Former logic accepted all subdomains in `per-user` mode, no matter if the user existed or not. (`userRecord` can be `null`)
- Former logic was written in `return-first-on-success` code logic order. This is written in `return-first-on-error` making it easier to read.
Didn't know that -'s are allowed in archive names 😓
}
} else {
// Allow any domain
domainReg = /.?/g
Copy link
Member

Choose a reason for hiding this comment

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

Should we throw in this case?

Copy link
Member

Choose a reason for hiding this comment

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

Seems like this would just be a misconfiguration. We could probably throw an error as config validation around https://github.com/beakerbrowser/hashbase/blob/master/lib/config.js#L30

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like the default configuration of most tests omits the hostname: https://travis-ci.org/beakerbrowser/hashbase/builds/327215556#L1654

@pfrazee
Copy link
Member

pfrazee commented Jan 10, 2018

This is looking good, I appreciate the update.

I would love to get some guidance/mentoring on where to write proper tests for this.

The best way to debug the letsencrypt config is to set debug to true in the config. (https://github.com/beakerbrowser/hashbase#lets-encrypt) You'll get console output telling you about the success or failure, without doing any live changes.

99% sure you have to setup a real hosting environment to test, sadly.

Also: it seems like there should be some central logic that maps domains to domain-render-object. I.e. app.getDomainContext(domain) to return either the "main" domain context or the context for user/archive.

Could you elaborate on this? I'm not sure what you're referring to with contexts.

@martinheidegger
Copy link
Contributor Author

99% sure you have to setup a real hosting environment to test, sadly.

I would usually encapsulate the logic in its own function app.isDomain() and then run this against the settings. This way the letsencrypt logic would be abstracted away.

Could you elaborate on this? I'm not sure what you're referring to with contexts.

Right now the distinction between main and user is done in the index. The suggestion would be to change this code using something like:

app.use(app.getRouter(config.sites))

and then use the same (or part of the getRouter implementation) to also check letsencrypt. So if you change the domains it will automatically adjust the letsencrypt check.

that being said I just noticed that letsencrypt will soon offer wildcard certificates Maybe that would make things quicker and better?

@pfrazee
Copy link
Member

pfrazee commented Jan 11, 2018

It seems like the default configuration of most tests omits the hostname:

Ok in that case, we should disable letsencrypt in the config validation if letsencrypt is configured to 'on' and no hostname is set. It should emit a warning.

that being said I just noticed that letsencrypt will soon offer wildcard certificates Maybe that would make things quicker and better?

That's true. I also dont think we need this logic to be too much more sophisticated than it is. It's going to need to be updated for custom domains anyway.

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

Successfully merging this pull request may close these issues.

2 participants