-
- Downloads
Inject secrets into the services (#3652)
This is a reworking of #3410 based on some feedback @calebcartwright left on that PR. The goals of injecting the secrets are threefold: 1. Simplify testing 2. Be consistent with all of the other config (which is injected) 3. Encapsulate the sensitive auth-related code in one place so it can be studied and tested thoroughly - Rather than add more code to BaseService to handle authorization logic, it delegates that to an AuthHelper class. - When the server starts, it fetches the credentials from `config` and injects them into `BaseService.register()` which passes them to `invoke()`. - In `invoke()` the service's auth configuration is checked (`static get auth()`, much like `static get route()`). - If the auth config is present, an AuthHelper instance is created and attached to the new instance. - Then within the service, the password, basic auth config, or bearer authentication can be accessed via e.g. `this.authHelper.basicAuth` and passed to `this._requestJson()` and friends. - Everything is being done very explicitly, so it should be very clear where and how the configured secrets are being used. - Testing different configurations of services can now be done by injecting the config into `invoke()` in `.spec` files instead of mocking global state in the service tests as was done before. See the new Jira spec files for a good example of this. Ref #3393
Showing
- .eslintrc.yml 1 addition, 0 deletions.eslintrc.yml
- core/base-service/auth-helper.js 43 additions, 0 deletionscore/base-service/auth-helper.js
- core/base-service/auth-helper.spec.js 96 additions, 0 deletionscore/base-service/auth-helper.spec.js
- core/base-service/base.js 48 additions, 3 deletionscore/base-service/base.js
- core/base-service/base.spec.js 40 additions, 1 deletioncore/base-service/base.spec.js
- core/base-service/errors.js 18 additions, 0 deletionscore/base-service/errors.js
- core/server/server.js 1 addition, 0 deletionscore/server/server.js
- dangerfile.js 5 additions, 2 deletionsdangerfile.js
- server.js 13 additions, 4 deletionsserver.js
- services/azure-devops/azure-devops-base.js 6 additions, 2 deletionsservices/azure-devops/azure-devops-base.js
- services/azure-devops/azure-devops-coverage.service.js 4 additions, 4 deletionsservices/azure-devops/azure-devops-coverage.service.js
- services/azure-devops/azure-devops-helpers.js 1 addition, 13 deletionsservices/azure-devops/azure-devops-helpers.js
- services/azure-devops/azure-devops-tests.service.js 3 additions, 4 deletionsservices/azure-devops/azure-devops-tests.service.js
- services/bintray/bintray.service.js 5 additions, 10 deletionsservices/bintray/bintray.service.js
- services/drone/drone-build.service.js 5 additions, 6 deletionsservices/drone/drone-build.service.js
- services/drone/drone-build.spec.js 36 additions, 0 deletionsservices/drone/drone-build.spec.js
- services/drone/drone-build.tester.js 2 additions, 11 deletionsservices/drone/drone-build.tester.js
- services/drone/drone-test-helpers.js 0 additions, 21 deletionsservices/drone/drone-test-helpers.js
- services/jenkins/jenkins-base.js 12 additions, 11 deletionsservices/jenkins/jenkins-base.js
- services/jenkins/jenkins-build.spec.js 34 additions, 0 deletionsservices/jenkins/jenkins-build.spec.js
Loading
Please register or sign in to comment