From 00a175b65544bdf8f0703141ebaf0ac4c370dad8 Mon Sep 17 00:00:00 2001 From: Tom Ridd Date: Fri, 17 Nov 2023 16:31:53 +0000 Subject: [PATCH] Haar 2007 e integration testing (#42) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Initial commit * Alee/init (#1) * Initial commit * πŸŽ‰ Initial drop of code * 🎨 Small tidy up * Adding circle build and updating node to v14 * Adding helm config * Fix wiremock port and update package.json Co-authored-by: Jon Brighton Co-authored-by: Jon Brighton * Fixing docker image (#2) * Fix secret name (#3) * Correcting variable names and removing unnecessary ones (#4) * Fixing variable name (#5) * Removing trailing slashes from env vars (#6) * Fix hostname (#7) * Update dependencies (#8) * Update dependencies Also move to use declaration overrides for describing additional possible fields in session data Also removing/moving unnecessary prod dependencies Moving jest tests to run in parallel * Fix types for user * Do not allow any warnings * Correcting test results path * Reducing docker image size (#9) Also * Update dependencies * Adopt standard github gitignore for node projects * Using body typography * Add rename script (#10) * Add rename script * PR reviews * Removing unused vars * Alee/decoupling auth client from redis (#11) * Decoupling auth client from redis impl * Update to latest hmpps orb version (#12) * Fixing build-info.json placement (#13) * Convert to arrow functions in utils (#14) * Convert to arrow functions in utils * Remove returns and fix prettier issues * Make the use of logger naming consistent (#15) * Adding outdated job (#16) * Adding outdated job * Updating dependencies * Removing patch to minor version * Updating dependencies (#17) * Moving to enable no-implicit-any (#18) * DT-1659: πŸ”¨ Remove helm copying secrets from AWS (#19) * Adding moj design system (#20) * Add new veracode scan for schedueled workflow (#21) * Add new veracode scan for schedueled workflow * Re-add - check_outdated job * Removing deprecated body parser (#22) * DT-1627: πŸ“„ Update license with correct year (#23) * Added missing ping endpoint as used by Kubernetes for liveliness probe (#24) * DT-2012 - upgrade hmpps orb, and add veracode policy scan job. (#25) * Use generic-service and generic-prometheus-alerts charts (#26) * Updating dependencies and adding slack notifications to outdated checks (#27) * Updating dependencies and adding slack notifications to outdated checks * Add slack orb * Moving to group middleware into related modules, following the pattern established in prison staff hub (#28) * Fix the slack notification on `check_outdated` (#30) * Ensure that the `SLACK_ACCESS_TOKEN` env var is set for `check_outdated` As the final step (on fail) is a slack notification we need to use a context containing the variable. * Refactor the channel for alerts into parameters This establishes a reusable pattern in case consumers wish to notify slack on other jobs. * Updating node dependencies (#31) * Fixing configuration of security audit (#32) The "medium" configuration was not an acceptable term, should be one of "info", "low", "moderate", "high" or "critical". This meant that it would not pick up on anything! * Alee/update dependencies (#33) * Updating dependencies and node * Use parameterised slack channel rather than default of typescript alerts channel * Extracting out executor * DT-2166 - add trivy image scanning job (#35) * Fix trivy scan job slack notifications channel (#36) * Use node executor and parameterise the version (#34) * WFP-322 use the hmpps/node executor to build * WFP-322 parameterise the node version in the executor * WFP-322 use node version parameter in integration test image * WFP-322 integration tests use new node_redis executor Co-authored-by: Andrew Lee <1517745+andrewrlee@users.noreply.github.com> * Deploy template project to template k8s namespace (#37) * Deploy template project to template k8s namespace * DT-2260 - update to latest circleci orb and chart dependencies (#38) * Updating dependencies and improving README (#39) * DT-2282: ⬆️ Fix veracode policy scan (#40) * Moving cypress tests to typescript (#41) * DT-2404: πŸ’„ Switch to sign in / out instead of login / out (#42) * DT-2404: πŸ’„ Switch to sign in / out instead of login / out * DT-2404: πŸ’„ Don't need .gitignore for husky any more * DT-2404: βœ… Run tests automatically on commit (#43) * Update dependencies (#44) * DT-2297 - Veracode - switch to daily pipeline scan (results in circleci), and weekly policy scan (upload to veracode portal). (#45) * DT-2297- randomise timing of circleci security workflow due to rate limiting at veracode. (#47) * update typescript (#48) * Fixing docker caching apt-get layer (#49) * Fix docker build failing, and reduce image size (#50) * Remove use of semi colons before arrays (#51) * Remove use of semi-colons before arrays * Fix typos in README * WFP-610 update to npmv7 and fix some audit (#52) * WFP-610 update to npm 7 * WFP-610 update outdated dependencies * WFP-610 fixed some audit vulnerabilities * WFP-610 updated passport-oauth2 * WFP-610 upgrade to jest-junit 13 to bring in new ansi-regex (#54) * Upgrading dependencies (#55) * FIXBUILD: update ansi-regex subdependency (#56) * DT-2702: πŸ”¨ Use new generic service configuration (#57) * Update dependencies (#58) * Moving to use HMPPS header (#59) * Moving to use HMPPS header * Removing explicit reference to DPS * Fix path of unit test results that are uploaded as artifacts (#60) and properly indent "build" job (jobs should be an array of [name] to dictionary) Co-authored-by: Jon Brighton * DT-2814: πŸ› Fix cron timings for veracode (#61) * NN-3747 fixing json structure for the stubUserRoles call and populating the user directly and not from the request because passport isn't in the test stack (#62) * Bumping node version (#63) Also fixing open handle in test and bumping dependencies * DT-2796: πŸ”¨ Migrate dev to live context (#64) * Update dependencies and move to NPM v8 (#65) * Upgrading dependencies (#66) * Update modules and remove express-request-id (#67) * INC-163 Timeout Fix - Correctly sets the timeout for a HttpAgent (#69) * ⬆️ update dependencies and πŸ’„add no-only-tests linting rule for cypress (#70) * ⬆️ update dependencies * πŸ’„Add no-only-tests linting rule for cypress * SDI-60: πŸ”¨ Add global protect and petty france to allowlists (#71) * Update dependencies (#72) * DCS-1442 jquery-ui.css coep fix (#73) * Fixing docker caching issue (#74) Need to refer to build args before calling apt-get upgrade otherwise the set of packages are cached and not upgraded. Docker cannot cache anything in layers after a dynamic variable has been used Also bumping version of node and fixing test compilation issue * Setup prometheus metrics by default. (#75) This change sets up prometheus metrics to be available on port 3001, and with the helm chart changes they will automatically get scraped and be available for alerts and dashboards in grafana. The added metrics include: - General nodejs stats: memory use, gc etc - HTTP server requests: counters and timings of all served HTTP requests by the app. - HTTP client requests: counters and timings of all HTTP requests to other upstream APIs (as long as they are based off `restClient.ts`). - Upstream healthchecks: guages recording the status/health of each upstream service when the healthcheck is tested. This is all backported from the `manage-recalls-ui` app, please let me know what you think. :) * Bump minimist from 1.2.5 to 1.2.6 (#76) Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update dependencies (#77) * Audit fix (#79) * NN-4060: App Insights only works with bunyan v1 (#80) Co-authored-by: sp-watson * Update orb and dependencies (#82) * Stop metrics test from hitting a real service and occasionally timing out (#81) Co-authored-by: Jon Wyatt <> Co-authored-by: Andrew Lee <1517745+andrewrlee@users.noreply.github.com> * SDI-181: πŸ”§ Add jira notifications for new projects (#83) * Adding better redis error handling (#84) * SDI-181: πŸ”§ Use new cimg redis executor (#85) * SDI-181: πŸ”§ Use new cimg redis executor * SDI-181: πŸ”§ Improve docker ignore and use released orb instead * SDI-181: ⬆️ Bump node minor version * SLM-245 Restore cache prior to running up the app for the integration tests (#86) This caused an issue with our build where we received a segmentation fault as soon as the integration tests called the node app. Segmentation faults generally indicate an issue with one of the native C/C++ modules and it appears that one of these modules was relying on something we have stashed in the cache. * SDI-88: 🚨 Fix querystring warning (#87) * SDI-88: 🚨 Fix querystring warning * SDI-88: 🚨 Second attempt to querystring warning * SDI-88: πŸ› Fix cookie session down as a dependency (#88) * SDI-88: ♻️ Tidy up mocks and switch to multiplatform builds (#89) * Allow async get to take an array of strings for paths like original get method (#90) * SDI-182: ✨ Switch to using connection string instead (#91) * Update README.md (#92) * SDI-88: βœ… Add token verification integration tests (#94) * Minor "code smell" fixes suggested by Sonar Cloud (#95) * INC-567: Remove unnecessary type assertions * INC-567: Return resolved promise directly * SDI-211: πŸ”’οΈ Bump versions to fix security issues and cope with passport major upgrade (#96) * Updating dependencies (#97) * SDI-211: 🎨 Enforce trailing comma on functions too (#98) * SDI-211: 🎨 Enforce arrow parens (#99) * Bump dependencies (#100) * SDI-218: ⬆ Upgrade cypress to v10 (#101) * ⬆️ Update dependencies (#102) * Ignore false positive around nodemon (#103) * Ignore false positive around nodemon * Manage version of audit ci and provide full path to ignored dependency * Updating dependencies (#104) * Update dependencies (#105) * Create services container (#106) This allows passing through a container of wired up services through to route This approach has been used for the dps-shared and farsight projects and it leads to a testing approach that scales more naturally. Means you can pass through the services through to where they are needed and this can grow without changes propagating through the application Also extracted standard router into standalone middleware as the current approach relies on mutation and encourages making multiple copies of it. * SDI-265: ♻️ Minor improvements (#107) * SDI-265: 🚨 Add lint check for only (#108) * Update Jest to v28 and minor dependency updates (#109) * Remove duplicate
elements (#110) The govuk/template.njk which the layout.njk extends which these files use already includes a
element According to the HTML spec there should only be one
element present in the document at a time * Bumping dependencies and fixing page width (#111) * Bumping dependencies and fixing page width There seems to be a lot of variability in page width so going with something that seems most popular in HMPPS * Run tests in band Partially to fix tests hanging in circle, but also as test seems to run almost twice as fast (after clearing cache) * Add a `cspNonce` to the webSecurity setup (#112) Based on what I’ve seen elsewhere, this seems to now be a common approach to allow us to inline scripts, see: https://content-security-policy.com/nonce The GOV.UK frontend has now been updated to support the use of the `cspNonce` local - see: https://github.com/alphagov/govuk-frontend/commit/2e40d744af6e6e4213ebc47644982d4eb94422d4 So we no longer need to add the inline hash, which is vulnerable to if the code in the frontend template is changed. I’ve also removed the domain-specific overrides for jQuery scripts and styles, as we can use the nonce for this too. * Update dependencies 2022-08-22 (#113) * Update dependencies to fix check outdated flagging typescript (#114) * Update dependencies 2022-09-09 (#115) * Speeding up jest tests (#116) This speeds up the running of jest tests by enabling isolatedModules which has the effect of [disabling typechecking](https://kulshekhar.github.io/ts-jest/docs/getting-started/options/isolatedModules) It also drastically reduces memory usage, allowing for running tests in parallel locally at least. On my laptop this reduces the time to run the tests in this project from ~14 seconds to ~4 seconds. On larger projects the effect is much more pronounced, welcome-people-to-prison reduces build time from ~2mins, 20 seconds to ~25 seconds. In circle we still need to run in band but this is still significantly faster than before, in WPIP it reduces the build by over 1 min. Type checking is still available in the IDE, it is also part of the husky pre-commit hook and run by circle as part of the build, so the risk of type errors slipping through are very small. (We could possibly add a typechecking stage before running jest and it would still be much faster but not adding unless it becomes apparent that we need it ) It would be worth to re-assess this after jest 29 as there seems to be some fixes around a [memory issue](https://github.com/facebook/jest/issues/11956) that is part of node in versions > 16.10 NB: This will not work if type declaration (`d.ts`) files contain enums or any other constructs that generate javascript code. This seems to be a bit of an anti-pattern anyway (see [here](https://lukasbehal.com/2017-05-22-enums-in-declaration-files/)). Other tooling such as cypress will only allow you to import types from these files. * Removing colour from logs in production mode (#117) * Move ingress (#118) * Move ingress * CHange generic service to latest * SDI-345: ⬆️ Upgrade node and cypress (#119) * SDI-345: ⬆️ Upgrade node and cypress * SDI-345: ⬆️ Actually upgrade cypress * Fixing logging (#120) There was an issue where we weren't sending trace info to app insights. This is because appInsights needs to be imported before bunyan is imported so it can do its instrumentation magic. There was a related issue that obscured this. It was previously impossible to test app insights locally as dotenv wasn't set up correctly - it needed to happen before app insights is imported or app insights would prevent the app starting up. So this moves dotenv to dev dependencies and preloads it before running the app via start:dev. This removes some code that is only relevant for local development. It also means the application runs similar locally to how it would run in docker or kubernetes - it just expects the environment variables to be present. Also moving the app insights import so it's very apparent that it's the first thing that happens when the app starts. * Update dependencies 2022-09-28 (#121) * ⬆️Upgrade to latest helm chart versions (#122) * Adding badges (#123) * Adding badges * Update README.md * Updating node to v18 (#124) * Set helm timeout to 5 minutes (#125) * Use official redis image for docker-compose (#126) Which is suitable for arm64 and consistent with docker-compose-test which was updated with https://github.com/ministryofjustice/hmpps-template-typescript/pull/89 * Update Helm config to match Kotlin template (#127) * Update dependencies 2022-11-15 (#128) * Update dependencies 2022-11-16 (#129) * Update node images (#130) * SDI-476: ⬆ Bump versions (#131) * Update dependencies 2022-12-08 (#132) * Update dependencies 2022-12-19 (#133) * Bump jsonwebtoken from 8.5.1 to 9.0.0 (#136) Bumps [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) from 8.5.1 to 9.0.0. - [Release notes](https://github.com/auth0/node-jsonwebtoken/releases) - [Changelog](https://github.com/auth0/node-jsonwebtoken/blob/master/CHANGELOG.md) - [Commits](https://github.com/auth0/node-jsonwebtoken/compare/v8.5.1...v9.0.0) --- updated-dependencies: - dependency-name: jsonwebtoken dependency-type: direct:development ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Fix conflicting prettier / eslint rule (#135) In eslint, we ask for a trailing comma, while the prettier rules are set to `es5`. This causes issues if you have your IDE set up to fix on save, as one linter kicks in before the other, causing conflicting fixes. Co-authored-by: Andrew Lee <1517745+andrewrlee@users.noreply.github.com> * SDI-523: πŸ”’οΈ Fix / ignoresecurity issues (#138) * HEAT-41: use npm outdated job from HMPPS Orb; update other dependencies (#139) * Update dependencies 2023-01-24 (#140) * Update dependencies 2023-01-31 (#141) * Update dependencies 2023-02-01 (#142) * Configure Renovate (#144) * Add renovate.json * HEAT-52: source Renovate config from shared HMPPS repo * HEAT-52: tweak dependencies pinned by Renovate Inherit the ones from https://github.com/ministryofjustice/hmpps-renovate-config/blob/main/node.json * HEAT-52: manually bump Slack Orb as Renovate was complaining 'Can't find version matching 4.4.2 for slack' --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Neil Mendum * Update Helm release generic-service to v2.4.0 (#146) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update peter-evans/create-pull-request action to v4 (#148) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update actions/checkout action to v3 (#147) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Add .nvmrc file, Prettier support for Nunjucks and use SCSS (#143) * Add .nvmrc file with node version set to `18` Update npm engine version to `^9` Add `prettier-plugin-jinja-template` as dev dependency plus config Refactor `.sass` files to `.scss` for consistency * Add newline to .nvmrc --------- Co-authored-by: Neil Mendum * Revert build_multiplatform_docker because it causes the build to take over an hour (#149) See Slack discussion https://mojdt.slack.com/archives/C69NWE339/p1671529301455009?thread_ts=1671529075.740459&cid=C69NWE339 * Update dependency cypress to ^12.5.1 (#150) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * HEAT-52: reduce the size of the PR body by specifying prBodyTemplate (#152) This should help with GitHub integration in Slack * Update all non major NPM dependencies (#151) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update all non major NPM dependencies (#153) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update all non major NPM dependencies (#155) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update all non major NPM dependencies (#156) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update all non major NPM dependencies (#159) * Update all non major NPM dependencies * Reduce Renovate stabilityDays so that it raises fewer PRs --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Neil Mendum * Update Helm release generic-service to v2.5.0 (#161) * Update Helm release generic-service to v2.5.0 * Drop generic-service params no longer required --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Neil Mendum * Update node image and regenerate package-lock.json (#165) * Update hmpps-orb to v7.2.1 (#166) * Upgrade to connect-redis 7 and update other dependencies (#168) * Upgrade to connect-redis 7 and update other dependencies * Remove legacy mode * Fix npm prune warning * Upgrade to typescript 5 (#169) * Add HMPPS Auth URL to form-action CSP string (#170) Update the Content Security Policy to allow the HMPPS Auth URL as a possible form action target. Currently, if a 403 error occurs on a GET request, this will be captured by the error handling setup in errorHandler.ts, and the user will be redirected to the sign out URL, which then redirects to the HMPPS Auth URL. However, if a 403 error occurs on a POST request, this second redirect may not occur, and the user may, depending on their choice of browser, be frozen on the form page they just submitted. Due to CSP implementation details that vary between browsers, adding the HMPPS Auth URL to our form action targets allows this second redirect to occur as expected. * Update TypeScript etc 2023-04-03 (#174) * Removing unnecessary build (#172) All 3 processes: tsc, sass and copy-views are run by concurrently at start up anyway * Update dependencies 2023-04-12 (#177) * SDIT-738: ⚑️ Cache static resources for 1 hour (#178) * Update dependencies 2023-04-21 (#181) * Fix security vuln 2023-04-25 (#183) * Update Helm release generic-service to v2.6.2 (#182) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Neil Mendum * SDIT-760: πŸ”§ Upgrade redis to 7 (#186) * Update Helm release generic-service to v2.6.3 (#184) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Tie css cache to version of application (#188) At the moment the cache is linked to the start up time of pod, so get unnecessary cache misses for each pod in the cluster and also when pods restart This ties the cache to the git short hash of the deployment * Fix version not appearing in application insights (#190) * Fix version not appearing in application insights This previously relied on running a shell script to generate a file with a json payload in it. The code that read this file to extract out the version for the cache improvement and also setting the application version in app insights, was looking in the wrong location There was another location that looked up the file and read in the details for the health endpoint which was looking in the right place This change moves to reading the version and git reference into an env var in the docker file instead, which means we can centralise how this info is made available and remove the additional file management This should be a safe fix as the build info file was previously being generated from the docker build anyway - so the file should be available * Tidy up passing around application version * Update Helm release generic-prometheus-alerts to v1.3.2 (#189) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Add PreProd and Prod helm config (#193) As per Kotlin Template https://github.com/ministryofjustice/hmpps-template-kotlin/tree/main/helm_deploy * Update slack orb to v4.12.5 (#185) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update peter-evans/create-pull-request action to v5 (#175) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update all non major NPM dependencies (#176) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update Node.js to v18.16 (#191) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update dependencies 2023-06-07 (#196) * Do not retry POST requests by default (#197) It doesn't really make sense to retry non-idempotent calls Also moving sanitised error over to a real error rather than a object. Makes it a little bit easier to test these: 'expect(..).reject.throws' etc.. doesn't work if you don't have really errors * Adding changelog (#198) * Have `sanitisedError` always return an Error instance (#199) … for the same reasons as explained in https://github.com/ministryofjustice/hmpps-template-typescript/pull/197 * Update all non major NPM dependencies (#195) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update all non major NPM dependencies (#200) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Fix semver vuln (#202) * Update govuk-frontend to 4.7.0 (#205) * Update all non major NPM dependencies (#204) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * HEAT-82: Add productId and /info endpoint (#212) * HEAT-82: Add productId and /info endpoint * Update README and default value * Update values.yaml to point at README.md * Update README with dev portal URL (#213) * Update README with dev portal URL * Fix URL * Fix info endpoint test description (#214) * Update CHANGELOG.md (#216) * Fix linting, update modules, remove override (#219) * Move /info to health check block (#220) * Update dependencies 2023-09-05 (#226) * Update dependencies 2023-09-05 * Fix node version * Fix CircleCI workflows for cypress (#223) * Persist compiled stylesheets to workspace so that integration tests can load styles properly * Upload cypress screenshot and video artefacts from correct location * Fix cypress config and remove some vestigial code (#228) * Remove unused/vestigial integration test method * Remove deleted cypress config option * Update copyright date * Update readme (#229) * Update Helm release generic-prometheus-alerts to v1.3.3 (#224) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update redis Docker tag to v7.2 (#221) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update Node.js to v18.18 (#230) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * HEAT-106: Standardise endpoints (#231) * HEAT-106: Standardise endpoints * Fix e2e * Correct response * Update Dockerfile to pull through branch name * Amend output checks for int tests * Fix bugs and add Changelog * SDIT-1088: ✨ Get components to always return status even if failed (#232) * SDIT-1108: πŸ”§ Don't default build args (#233) * SDIT-1108: πŸ”§ Don't default build args * SDIT-1108: πŸ”§ Copy across args to env variables * SDIT-1108: πŸ”§ Add in docker compose build args and missing env vars * SDIT-1108: ♻️ Fix deprecated syntax version of ENV (#234) * SDIT-1108: ✨ Add in environment name to header (#235) * SDIT-1108: πŸ“ Add new environment name to changelog (#236) * NON-270: Improve REST client (#238) * Improve REST client typing information and add PATCH, PUT and DELETE methods allowing for query parameters as well as body payloads * Propagate user types into `res.locals` in request handlers * Update actions/checkout action to v4 (#225) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update all non major NPM dependencies (#210) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update Helm release generic-service to v2.6.5 (#237) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update dependencies 2023-10-17 (#243) * add tests for list base clients page * add view base client page * Fix errors in template * basic view for create new base client screen * HAAR-1891: Update deprecated endpoints with new endpoints (#247) * HAAR-1891: Update deprecated endpoints with new (manage users api) endpoints * HAAR-1891: Update following PR comments * HAAR-1891: Added MANAGE_USERS_API_URL values. * HAAR-1891: Added MANAGE_USERS_API_URL values. * Update renovate.json (#248) …to prevent Node docker image from being updated beyond LTS * post new base client with error loop * added controller tests * add tests for presenter * add test for expiry today * Move to Node 20 plus minor updates (#249) * Update CHANGELOG for node 20 change (#250) * Update CHANGELOG for node 20 change * Missed update link * Update jwt-decode module to version 4.0.0 (#252) * Update CHANGELOG.md (#253) * correct test comments and refactor time functions * Added changelog for PR #247 (#254) * display edit base clients details page * Add post update functionality * update test comments * update comments * display edit base clients deployment details page * add update deployment flow * fix integration test * remove excess helm folder * add manage-users-api to docker-compose * add remove client instance code * page to display Delete Client confirmation * test update * delete functionality - validation * add filter functionality * setup homepage tests * base-client-list integration tests * correct failing test * remove template files * fix service filter * integration tests for main base client view screen * Add base client tests * edit base client details testing * integration tests for edit deployment * Integration tests for Client instance add and delete functionality --------- Signed-off-by: dependabot[bot] Co-authored-by: Andrew Lee <1517745+andrewrlee@users.noreply.github.com> Co-authored-by: Jon Brighton Co-authored-by: Jon Brighton Co-authored-by: Matt <34448412+mattops@users.noreply.github.com> Co-authored-by: Paul Solecki <51918433+psoleckimoj@users.noreply.github.com> Co-authored-by: petergphillips Co-authored-by: Andy Marke Co-authored-by: Darren Oakley Co-authored-by: markreesmoj <76954782+markreesmoj@users.noreply.github.com> Co-authored-by: Connor Glynn <66882795+connormaglynn@users.noreply.github.com> Co-authored-by: Gareth.m.Davies Co-authored-by: ushkarev Co-authored-by: richardpopple Co-authored-by: Michael Willis Co-authored-by: Louise N Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: sp-watson <77974320+sp-watson@users.noreply.github.com> Co-authored-by: sp-watson Co-authored-by: Jon Wyatt Co-authored-by: Mike Halma <58170926+mikehalmamoj@users.noreply.github.com> Co-authored-by: Richard James <44123869+richpjames@users.noreply.github.com> Co-authored-by: Stuart Harrison Co-authored-by: Neil Mendum Co-authored-by: carlov20 Co-authored-by: Neil Mendum Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: David Middleton <122619525+davidmiddletonmoj@users.noreply.github.com> Co-authored-by: Gareth.m.Davies Co-authored-by: bryangaledxw <94137563+bryangaledxw@users.noreply.github.com> Co-authored-by: ravmoj <104509282+ravmoj@users.noreply.github.com> --- assets/js/application.js | 1 + assets/js/initMOJFilterPage.js | 5 +- integration_tests/e2e/add-base-client.cy.ts | 124 ++++++++++++++++++ .../e2e/edit-base-client-deployment.cy.ts | 58 ++++++++ .../e2e/edit-base-client-details.cy.ts | 86 ++++++++++++ .../e2e/edit-client-instances.cy.ts | 108 +++++++++++++++ .../e2e/view-base-client-list.cy.ts | 88 +++++++++++++ integration_tests/e2e/view-base-client.cy.ts | 80 +++++++++++ integration_tests/index.d.ts | 2 +- integration_tests/mockApis/baseClientsApi.ts | 67 +++++++++- integration_tests/mockApis/manageUsersApi.ts | 2 +- .../pages/addBaseClientDetails.ts | 46 +++++++ integration_tests/pages/addBaseClientGrant.ts | 17 +++ .../pages/confirmDeleteClient.ts | 17 +++ .../pages/editBaseClientDeploymentDetails.ts | 33 +++++ .../pages/editBaseClientDetails.ts | 46 +++++++ integration_tests/pages/newBaseClientGrant.ts | 7 + integration_tests/pages/viewBaseClient.ts | 33 +++++ integration_tests/pages/viewBaseClientList.ts | 19 +++ integration_tests/pages/viewClientSecrets.ts | 11 ++ integration_tests/support/commands.ts | 7 +- .../localMockData/baseClientsResponseMock.ts | 32 ++++- server/views/pages/base-client.njk | 55 ++++++-- server/views/pages/base-clients.njk | 8 +- server/views/pages/delete-client-instance.njk | 47 ++++++- .../pages/edit-base-client-deployment.njk | 62 +++++++-- .../views/pages/edit-base-client-details.njk | 94 ++++++++++--- .../views/pages/new-base-client-details.njk | 92 ++++++++++--- server/views/pages/new-base-client-grant.njk | 22 +++- .../views/pages/new-base-client-success.njk | 10 +- .../presenters/listBaseClientsPresenter.ts | 21 ++- .../viewBaseClientPresenter.test.ts | 4 +- .../presenters/viewBaseClientPresenter.ts | 4 +- 33 files changed, 1211 insertions(+), 97 deletions(-) create mode 100644 integration_tests/e2e/add-base-client.cy.ts create mode 100644 integration_tests/e2e/edit-base-client-deployment.cy.ts create mode 100644 integration_tests/e2e/edit-base-client-details.cy.ts create mode 100644 integration_tests/e2e/edit-client-instances.cy.ts create mode 100644 integration_tests/e2e/view-base-client-list.cy.ts create mode 100644 integration_tests/e2e/view-base-client.cy.ts create mode 100644 integration_tests/pages/addBaseClientDetails.ts create mode 100644 integration_tests/pages/addBaseClientGrant.ts create mode 100644 integration_tests/pages/confirmDeleteClient.ts create mode 100644 integration_tests/pages/editBaseClientDeploymentDetails.ts create mode 100644 integration_tests/pages/editBaseClientDetails.ts create mode 100644 integration_tests/pages/newBaseClientGrant.ts create mode 100644 integration_tests/pages/viewBaseClient.ts create mode 100644 integration_tests/pages/viewBaseClientList.ts create mode 100644 integration_tests/pages/viewClientSecrets.ts diff --git a/assets/js/application.js b/assets/js/application.js index 6619680..a4506c2 100644 --- a/assets/js/application.js +++ b/assets/js/application.js @@ -8,6 +8,7 @@ function showDiv(divId, element, val) { document.addEventListener('DOMContentLoaded', function (event) { const select = document.getElementById('access-token-validity') + if (!select) return select.onchange = () => showDiv('custom-access-token-validity-element', select, 'custom') showDiv('custom-access-token-validity-element', select, 'custom') }) diff --git a/assets/js/initMOJFilterPage.js b/assets/js/initMOJFilterPage.js index 0a5b310..9a14625 100644 --- a/assets/js/initMOJFilterPage.js +++ b/assets/js/initMOJFilterPage.js @@ -5,7 +5,10 @@ new MOJFrontend.FilterToggleButton({ container: $('.moj-action-bar__filter'), showText: 'Show filter', hideText: 'Hide filter', - classes: 'govuk-button--secondary', + classes: 'govuk-button--secondary toggle-filter-button', + attributes: { + 'data-qa': 'toggle-filter-button', + }, }, closeButton: { container: $('.moj-filter__header-action'), diff --git a/integration_tests/e2e/add-base-client.cy.ts b/integration_tests/e2e/add-base-client.cy.ts new file mode 100644 index 0000000..a14e3e1 --- /dev/null +++ b/integration_tests/e2e/add-base-client.cy.ts @@ -0,0 +1,124 @@ +import Page from '../pages/page' +import AddBaseClientGrantPage from '../pages/addBaseClientGrant' +import AddBaseClientDetailsPage from '../pages/addBaseClientDetails' +import ViewBaseClientListPage from '../pages/viewBaseClientList' + +const visitAddBaseClientPage = (): AddBaseClientGrantPage => { + cy.signIn({ failOnStatusCode: true, redirectPath: '/base-clients/new' }) + return Page.verifyOnPage(AddBaseClientGrantPage) +} + +const visitAddWithClientCredentialsPage = (): AddBaseClientDetailsPage => { + cy.signIn({ failOnStatusCode: true, redirectPath: '/base-clients/new?grant=client-credentials' }) + return Page.verifyOnPage(AddBaseClientDetailsPage) +} + +context('Add client page', () => { + beforeEach(() => { + cy.task('reset') + cy.task('stubSignIn') + cy.task('stubManageUser') + cy.task('stubListBaseClients') + }) + + context('Add base client choose grant screen', () => { + let addBaseClientGrantPage: AddBaseClientGrantPage + + beforeEach(() => { + addBaseClientGrantPage = visitAddBaseClientPage() + }) + + it('User can see select a grant type radio buttons', () => { + addBaseClientGrantPage.grantTypeRadioGroup().should('be.visible') + }) + + it('Client credentials is selected by default', () => { + addBaseClientGrantPage.clientCredentialsRadio().should('have.attr', 'checked') + }) + + it('Authorization code is disabled (for now)', () => { + addBaseClientGrantPage.authorizationCodeRadio().should('have.attr', 'disabled') + }) + + it('User clicks cancel to return to home screen', () => { + addBaseClientGrantPage.cancelLink().click() + Page.verifyOnPage(ViewBaseClientListPage) + }) + + it('User clicks continue to got to add base client details screen', () => { + addBaseClientGrantPage.continueButton().click() + Page.verifyOnPage(AddBaseClientDetailsPage) + }) + }) + + context('Add base client enter details screen - client credentials', () => { + let addBaseClientDetailsPage: AddBaseClientDetailsPage + + beforeEach(() => { + addBaseClientDetailsPage = visitAddWithClientCredentialsPage() + }) + + it('User can see base-client form inputs', () => { + addBaseClientDetailsPage.baseClientIdInput().should('be.visible') + addBaseClientDetailsPage.baseClientServiceRadioButton().should('exist') + addBaseClientDetailsPage.baseClientPersonalRadioButton().should('exist') + addBaseClientDetailsPage.baseClientAccessTokenValidityDropdown().should('be.visible') + addBaseClientDetailsPage.baseClientApprovedScopesInput().should('be.visible') + }) + + it('User can see audit trail form inputs', () => { + addBaseClientDetailsPage.auditTrailDetailsInput().should('be.visible') + }) + + it('User can see grant details form inputs', () => { + addBaseClientDetailsPage.grantTypeInput().should('be.visible') + addBaseClientDetailsPage.grantAuthoritiesInput().should('be.visible') + addBaseClientDetailsPage.grantDatabaseUsernameInput().should('be.visible') + }) + + it('User can see config form inputs', () => { + addBaseClientDetailsPage.configDoesExpireCheckbox().should('exist') + addBaseClientDetailsPage.configAllowedIpsInput().should('be.visible') + }) + + context('Access token validity dropdown', () => { + it('Custom input is initially hidden', () => { + addBaseClientDetailsPage.baseClientAccessTokenValidityInput().should('not.be.visible') + }) + + it('Custom input is shown when custom option is selected', () => { + addBaseClientDetailsPage.baseClientAccessTokenValidityDropdown().select('Custom') + addBaseClientDetailsPage.baseClientAccessTokenValidityInput().should('be.visible') + }) + }) + + context('Allow client to expire ', () => { + it('Does expire checkbox is unchecked by default', () => { + addBaseClientDetailsPage.configDoesExpireCheckbox().should('not.be.checked') + }) + + it('Expiry days input is shown if checkbox is selected', () => { + addBaseClientDetailsPage.configDoesExpireCheckbox().click() + addBaseClientDetailsPage.configExpiryDaysInput().should('be.visible') + }) + }) + + it('User clicks cancel to return to home screen', () => { + addBaseClientDetailsPage.cancelLink().click() + Page.verifyOnPage(ViewBaseClientListPage) + }) + + it('User clicks continue to post new client details screen', () => { + // enter a base client id + addBaseClientDetailsPage.baseClientIdInput().type('new-client-id') + + // set up to check the POST request + cy.intercept('POST', '/base-clients/new', req => { + const { body } = req + expect(body).to.contain('baseClientId=new-client-id') + }) + + addBaseClientDetailsPage.saveButton().click() + }) + }) +}) diff --git a/integration_tests/e2e/edit-base-client-deployment.cy.ts b/integration_tests/e2e/edit-base-client-deployment.cy.ts new file mode 100644 index 0000000..7c6e5d2 --- /dev/null +++ b/integration_tests/e2e/edit-base-client-deployment.cy.ts @@ -0,0 +1,58 @@ +import Page from '../pages/page' +import ViewBaseClientPage from '../pages/viewBaseClient' +import EditBaseClientDeploymentDetailsPage from '../pages/editBaseClientDeploymentDetails' + +const visitEditBaseClientDeploymentDetailsPage = (): EditBaseClientDeploymentDetailsPage => { + cy.signIn({ failOnStatusCode: true, redirectPath: '/base-clients/base_client_id_1/deployment' }) + return Page.verifyOnPage(EditBaseClientDeploymentDetailsPage) +} + +context('Edit base client deployment details page', () => { + let editBaseClientDeploymentDetailsPage: EditBaseClientDeploymentDetailsPage + + beforeEach(() => { + cy.task('reset') + cy.task('stubSignIn') + cy.task('stubManageUser') + cy.task('stubListBaseClients') + cy.task('stubGetBaseClient') + cy.task('stubGetListClientInstancesList') + editBaseClientDeploymentDetailsPage = visitEditBaseClientDeploymentDetailsPage() + }) + + it('User can see contact details form inputs', () => { + editBaseClientDeploymentDetailsPage.baseClientSummaryList().should('be.visible') + editBaseClientDeploymentDetailsPage.deploymentTeamInput().should('be.visible') + editBaseClientDeploymentDetailsPage.deploymentTeamContactInput().should('be.visible') + editBaseClientDeploymentDetailsPage.deploymentTeamSlackInput().should('be.visible') + }) + + it('User can see platform details form inputs', () => { + editBaseClientDeploymentDetailsPage.platformHostingRadios().should('be.visible') + editBaseClientDeploymentDetailsPage.platformNamespaceInput().should('be.visible') + editBaseClientDeploymentDetailsPage.platformDeploymentInput().should('be.visible') + editBaseClientDeploymentDetailsPage.platformSecretNameInput().should('be.visible') + editBaseClientDeploymentDetailsPage.platformSecretKeyInput().should('be.visible') + editBaseClientDeploymentDetailsPage.platformClientIdInput().should('be.visible') + editBaseClientDeploymentDetailsPage.platformDeploymentInfoInput().should('be.visible') + }) + + it('User clicks cancel to return to base-client screen', () => { + editBaseClientDeploymentDetailsPage.cancelLink().click() + Page.verifyOnPage(ViewBaseClientPage) + }) + + it('User clicks continue to post new client deployment details', () => { + // enter new audit details + editBaseClientDeploymentDetailsPage.deploymentTeamInput().clear() + editBaseClientDeploymentDetailsPage.deploymentTeamInput().type('HAHA') + + // set up to check the POST request + cy.intercept('POST', '/base-clients/base_client_id_1/deployment', req => { + const { body } = req + expect(body).to.contain('team=HAHA') + }) + + editBaseClientDeploymentDetailsPage.saveButton().click() + }) +}) diff --git a/integration_tests/e2e/edit-base-client-details.cy.ts b/integration_tests/e2e/edit-base-client-details.cy.ts new file mode 100644 index 0000000..6d4dc13 --- /dev/null +++ b/integration_tests/e2e/edit-base-client-details.cy.ts @@ -0,0 +1,86 @@ +import Page from '../pages/page' +import EditBaseClientDetailsPage from '../pages/editBaseClientDetails' +import ViewBaseClientPage from '../pages/viewBaseClient' + +const visitEditBaseClientDetailsPage = (): EditBaseClientDetailsPage => { + cy.signIn({ failOnStatusCode: true, redirectPath: '/base-clients/base_client_id_1/edit' }) + return Page.verifyOnPage(EditBaseClientDetailsPage) +} + +context('Edit base client details page', () => { + let editBaseClientDetailsPage: EditBaseClientDetailsPage + + beforeEach(() => { + cy.task('reset') + cy.task('stubSignIn') + cy.task('stubManageUser') + cy.task('stubListBaseClients') + cy.task('stubGetBaseClient') + cy.task('stubGetListClientInstancesList') + editBaseClientDetailsPage = visitEditBaseClientDetailsPage() + }) + + it('User can see base-client form inputs', () => { + editBaseClientDetailsPage.baseClientIdInput().should('exist') + editBaseClientDetailsPage.baseClientServiceRadioButton().should('exist') + editBaseClientDetailsPage.baseClientPersonalRadioButton().should('exist') + editBaseClientDetailsPage.baseClientAccessTokenValidityDropdown().should('be.visible') + editBaseClientDetailsPage.baseClientApprovedScopesInput().should('be.visible') + }) + + it('User can see audit trail form inputs', () => { + editBaseClientDetailsPage.auditTrailDetailsInput().should('be.visible') + }) + + it('User can see grant details form inputs', () => { + editBaseClientDetailsPage.grantTypeInput().should('be.visible') + editBaseClientDetailsPage.grantAuthoritiesInput().should('be.visible') + editBaseClientDetailsPage.grantDatabaseUsernameInput().should('be.visible') + }) + + it('User can see config form inputs', () => { + editBaseClientDetailsPage.configDoesExpireCheckbox().should('exist') + editBaseClientDetailsPage.configAllowedIpsInput().should('be.visible') + }) + + context('Access token validity dropdown', () => { + it('Custom input is initially hidden', () => { + editBaseClientDetailsPage.baseClientAccessTokenValidityInput().should('not.be.visible') + }) + + it('Custom input is shown when custom option is selected', () => { + editBaseClientDetailsPage.baseClientAccessTokenValidityDropdown().select('Custom') + editBaseClientDetailsPage.baseClientAccessTokenValidityInput().should('be.visible') + }) + }) + + context('Allow client to expire ', () => { + it('Does expire checkbox is unchecked by default', () => { + editBaseClientDetailsPage.configDoesExpireCheckbox().should('not.be.checked') + }) + + it('Expiry days input is shown if checkbox is selected', () => { + editBaseClientDetailsPage.configDoesExpireCheckbox().click() + editBaseClientDetailsPage.configExpiryDaysInput().should('be.visible') + }) + }) + + it('User clicks cancel to return to base-client screen', () => { + editBaseClientDetailsPage.cancelLink().click() + Page.verifyOnPage(ViewBaseClientPage) + }) + + it('User clicks continue to post new client details screen', () => { + // enter new audit details + editBaseClientDetailsPage.auditTrailDetailsInput().clear() + editBaseClientDetailsPage.auditTrailDetailsInput().type('updated') + + // set up to check the POST request + cy.intercept('POST', '/base-clients/base_client_id_1/edit', req => { + const { body } = req + expect(body).to.contain('audit=updated') + }) + + editBaseClientDetailsPage.saveButton().click() + }) +}) diff --git a/integration_tests/e2e/edit-client-instances.cy.ts b/integration_tests/e2e/edit-client-instances.cy.ts new file mode 100644 index 0000000..1a86f02 --- /dev/null +++ b/integration_tests/e2e/edit-client-instances.cy.ts @@ -0,0 +1,108 @@ +import Page from '../pages/page' +import ViewBaseClientPage from '../pages/viewBaseClient' +import ViewClientSecretsPage from '../pages/viewClientSecrets' +import ConfirmDeleteClientPage from '../pages/confirmDeleteClient' + +const visitBaseClientPage = (): ViewBaseClientPage => { + cy.signIn({ failOnStatusCode: true, redirectPath: '/base-clients/base_client_id_1' }) + return Page.verifyOnPage(ViewBaseClientPage) +} + +const visitConfirmDeleteClientPage = (): ConfirmDeleteClientPage => { + cy.signIn({ + failOnStatusCode: true, + redirectPath: '/base-clients/base_client_id_1/clients/base_client_id_1_01/delete', + }) + return Page.verifyOnPage(ConfirmDeleteClientPage) +} + +context('Base client page - client instances', () => { + beforeEach(() => { + cy.task('reset') + cy.task('stubSignIn') + cy.task('stubGetBaseClient') + cy.task('stubManageUser') + cy.task('stubGetListClientInstancesList') + }) + + context('Add client instances', () => { + let baseClientsPage: ViewBaseClientPage + + beforeEach(() => { + cy.task('stubAddClientInstance') + baseClientsPage = visitBaseClientPage() + }) + + it('User can click Add on base-client page to create new client instance', () => { + baseClientsPage.addClientInstanceButton().click() + Page.verifyOnPage(ViewClientSecretsPage) + }) + + context('Client secrets page', () => { + let clientSecretsPage: ViewClientSecretsPage + + beforeEach(() => { + baseClientsPage.addClientInstanceButton().click() + clientSecretsPage = Page.verifyOnPage(ViewClientSecretsPage) + }) + + it('User can see client secrets', () => { + clientSecretsPage.secretsTable().should('be.visible') + }) + + it('User can click continue to be taken back to base client page', () => { + clientSecretsPage.continueButton().click() + Page.verifyOnPage(ViewBaseClientPage) + }) + }) + }) + + context('Delete client instances', () => { + let confirmDeleteClientPage: ConfirmDeleteClientPage + + beforeEach(() => { + cy.task('stubDeleteClientInstance') + confirmDeleteClientPage = visitConfirmDeleteClientPage() + }) + + it('User can see warning message', () => { + confirmDeleteClientPage.warningMessage().should('be.visible') + }) + + it('Should not have error message by default', () => { + confirmDeleteClientPage.errorMessage().should('not.exist') + }) + + it('User can fill out confirm then click Delete on base-client page to delete client instance', () => { + confirmDeleteClientPage.confirmInput().clear() + confirmDeleteClientPage.confirmInput().type('base_client_id_1_01') + + confirmDeleteClientPage.deleteButton().click() + Page.verifyOnPage(ViewBaseClientPage) + }) + + it('User does not fill out Confirmation input clicking delete returns to page with error', () => { + confirmDeleteClientPage.confirmInput().clear() + + confirmDeleteClientPage.deleteButton().click() + confirmDeleteClientPage = Page.verifyOnPage(ConfirmDeleteClientPage) + + confirmDeleteClientPage.errorMessage().should('be.visible') + }) + + it('User fills out incorrect Confirmation input clicking delete returns to page with error', () => { + confirmDeleteClientPage.confirmInput().clear() + confirmDeleteClientPage.confirmInput().type('incorrect_client_id') + + confirmDeleteClientPage.deleteButton().click() + confirmDeleteClientPage = Page.verifyOnPage(ConfirmDeleteClientPage) + + confirmDeleteClientPage.errorMessage().should('be.visible') + }) + + it('User can click cancel to return to base client screen', () => { + confirmDeleteClientPage.cancelButton().click() + Page.verifyOnPage(ViewBaseClientPage) + }) + }) +}) diff --git a/integration_tests/e2e/view-base-client-list.cy.ts b/integration_tests/e2e/view-base-client-list.cy.ts new file mode 100644 index 0000000..12eae2f --- /dev/null +++ b/integration_tests/e2e/view-base-client-list.cy.ts @@ -0,0 +1,88 @@ +import Page from '../pages/page' +import ViewBaseClientListPage from '../pages/viewBaseClientList' +import ViewBaseClientPage from '../pages/viewBaseClient' +import NewBaseClientGrantPage from '../pages/newBaseClientGrant' + +const visitBaseClientListPage = (): ViewBaseClientListPage => { + cy.signIn() + cy.visit('/') + return Page.verifyOnPage(ViewBaseClientListPage) +} + +context('Homepage - list base-clients', () => { + let listBaseClientsPage: ViewBaseClientListPage + + beforeEach(() => { + cy.task('reset') + cy.task('stubSignIn') + cy.task('stubListBaseClients') + cy.task('stubGetBaseClient') + cy.task('stubManageUser') + cy.task('stubGetListClientInstancesList') + + listBaseClientsPage = visitBaseClientListPage() + }) + + it('User can see base-client list', () => { + listBaseClientsPage.baseClientList().should('have.length', 3) + }) + + it('User can click through to base-client', () => { + listBaseClientsPage.baseClientList().first().children('a').click() + Page.verifyOnPage(ViewBaseClientPage) + }) + + it('User can see Add New button', () => { + listBaseClientsPage.addNewBaseClient().should('exist') + }) + + it('User can click through to new base-client page', () => { + listBaseClientsPage.addNewBaseClient().click() + Page.verifyOnPage(NewBaseClientGrantPage) + }) + + it('Filter page is hidden', () => { + listBaseClientsPage.filterPanel().should('not.be.visible') + }) + + it('Toggle filter button has text Show filter', () => { + listBaseClientsPage.toggleFilterButton().should('have.text', 'Show filter') + }) + + it('On click shows filter panel and updates text to Hide filter', () => { + listBaseClientsPage.toggleFilterButton().click() + listBaseClientsPage.filterPanel().should('be.visible') + listBaseClientsPage.toggleFilterButton().should('have.text', 'Hide filter') + }) + + it('On second click hides filter panel and reverts text to Show filter', () => { + listBaseClientsPage.toggleFilterButton().click() + listBaseClientsPage.toggleFilterButton().click() + listBaseClientsPage.filterPanel().should('not.be.visible') + listBaseClientsPage.toggleFilterButton().should('have.text', 'Show filter') + }) + + it('On second click hides filter panel and reverts text to Show filter', () => { + listBaseClientsPage.toggleFilterButton().click() + listBaseClientsPage.toggleFilterButton().click() + listBaseClientsPage.filterPanel().should('not.be.visible') + listBaseClientsPage.toggleFilterButton().should('have.text', 'Show filter') + }) + + it('On click Apply filter hides the filter', () => { + listBaseClientsPage.toggleFilterButton().click() + listBaseClientsPage.applyFilterButton().click() + + listBaseClientsPage.filterPanel().should('not.be.visible') + }) + + it('On click Apply with filter content limits rows in table', () => { + listBaseClientsPage.toggleFilterButton().click() + listBaseClientsPage.roleFilterInputBox().type('ROLE_TWO') + + listBaseClientsPage.applyFilterButton().click() + + listBaseClientsPage.filterPanel().should('not.be.visible') + listBaseClientsPage.baseClientList().should('have.length', 2) + }) +}) diff --git a/integration_tests/e2e/view-base-client.cy.ts b/integration_tests/e2e/view-base-client.cy.ts new file mode 100644 index 0000000..3930459 --- /dev/null +++ b/integration_tests/e2e/view-base-client.cy.ts @@ -0,0 +1,80 @@ +import Page from '../pages/page' +import ViewBaseClientPage from '../pages/viewBaseClient' +import ViewClientSecretsPage from '../pages/viewClientSecrets' +import ConfirmDeleteClientPage from '../pages/confirmDeleteClient' +import EditBaseClientDetailsPage from '../pages/editBaseClientDetails' +import EditBaseClientDeploymentDetailsPage from '../pages/editBaseClientDeploymentDetails' + +const visitBaseClientPage = (): ViewBaseClientPage => { + cy.signIn({ failOnStatusCode: true, redirectPath: '/base-clients/base_client_id_1' }) + return Page.verifyOnPage(ViewBaseClientPage) +} + +context('Base client page', () => { + let baseClientsPage: ViewBaseClientPage + + beforeEach(() => { + cy.task('reset') + cy.task('stubSignIn') + cy.task('stubGetBaseClient') + cy.task('stubManageUser') + cy.task('stubGetListClientInstancesList') + cy.task('stubAddClientInstance') + + baseClientsPage = visitBaseClientPage() + }) + + context('Client instances', () => { + it('User can see client instance list', () => { + baseClientsPage.clientInstanceRows().should('have.length', 3) + }) + + it('User can click add to create new client instance', () => { + baseClientsPage.addClientInstanceButton().click() + Page.verifyOnPage(ViewClientSecretsPage) + }) + + it('User can click delete to be taken to delete confirmation page', () => { + baseClientsPage.clientInstanceDeleteButtons().first().click() + Page.verifyOnPage(ConfirmDeleteClientPage) + }) + }) + + context('Base client details', () => { + it('User can see base client details table', () => { + baseClientsPage.baseClientDetailsTable().should('be.visible') + }) + + it('User can see audit trail table', () => { + baseClientsPage.baseClientAuditTable().should('be.visible') + }) + + it('User can see client credentials table', () => { + baseClientsPage.baseClientClientCredentialsTable().should('be.visible') + }) + + it('User can see config table', () => { + baseClientsPage.baseClientConfigTable().should('be.visible') + }) + + it('User can click Change client details to be taken to edit page', () => { + baseClientsPage.changeClientDetailsLink().click() + Page.verifyOnPage(EditBaseClientDetailsPage) + }) + }) + + context('Deployment details', () => { + it('User can see deployment contacts table', () => { + baseClientsPage.baseClientDeploymentContactTable().should('be.visible') + }) + + it('User can see deployment platform table', () => { + baseClientsPage.baseClientDeploymentPlatformTable().should('be.visible') + }) + + it('User can click Change client details to be taken to edit deployment page', () => { + baseClientsPage.changeDeploymentDetailsLink().click() + Page.verifyOnPage(EditBaseClientDeploymentDetailsPage) + }) + }) +}) diff --git a/integration_tests/index.d.ts b/integration_tests/index.d.ts index ce64a17..4bb604a 100644 --- a/integration_tests/index.d.ts +++ b/integration_tests/index.d.ts @@ -4,6 +4,6 @@ declare namespace Cypress { * Custom command to signIn. Set failOnStatusCode to false if you expect and non 200 return code * @example cy.signIn({ failOnStatusCode: boolean }) */ - signIn(options?: { failOnStatusCode: boolean }): Chainable + signIn(options?: { failOnStatusCode: boolean; redirectPath?: string }): Chainable } } diff --git a/integration_tests/mockApis/baseClientsApi.ts b/integration_tests/mockApis/baseClientsApi.ts index e76dbd1..1f1bf9a 100644 --- a/integration_tests/mockApis/baseClientsApi.ts +++ b/integration_tests/mockApis/baseClientsApi.ts @@ -2,6 +2,8 @@ import { stubFor } from './wiremock' import { listBaseClientsResponseMock, getBaseClientResponseMock, + getListClientInstancesResponseMock, + getSecretsResponseMock, } from '../../server/data/localMockData/baseClientsResponseMock' export default { @@ -25,7 +27,7 @@ export default { return stubFor({ request: { method: 'GET', - urlPattern: `/baseClientsApi/base-clients/baseClientId`, + urlPattern: `/baseClientsApi/base-clients/base_client_id_1`, }, response: { status: 200, @@ -36,4 +38,67 @@ export default { }, }) }, + + stubGetListClientInstancesList: () => { + return stubFor({ + request: { + method: 'GET', + urlPattern: `/baseClientsApi/base-clients/base_client_id_1/clients`, + }, + response: { + status: 200, + headers: { + 'Content-Type': 'application/json;charset=UTF-8', + }, + jsonBody: getListClientInstancesResponseMock, + }, + }) + }, + + stubGetClientDeploymentDetails: () => { + return stubFor({ + request: { + method: 'GET', + urlPattern: `/baseClientsApi/base-clients/base_client_id_1/deployment`, + }, + response: { + status: 200, + headers: { + 'Content-Type': 'application/json;charset=UTF-8', + }, + jsonBody: getListClientInstancesResponseMock, + }, + }) + }, + + stubAddClientInstance: () => { + return stubFor({ + request: { + method: 'POST', + urlPattern: `/baseClientsApi/base-clients/base_client_id_1/clients`, + }, + response: { + status: 200, + headers: { + 'Content-Type': 'application/json;charset=UTF-8', + }, + jsonBody: getSecretsResponseMock, + }, + }) + }, + + stubDeleteClientInstance: () => { + return stubFor({ + request: { + method: 'DELETE', + urlPattern: `/baseClientsApi/base-clients/base_client_id_1/clients/base_client_id_1_01`, + }, + response: { + status: 200, + headers: { + 'Content-Type': 'application/json;charset=UTF-8', + }, + }, + }) + }, } diff --git a/integration_tests/mockApis/manageUsersApi.ts b/integration_tests/mockApis/manageUsersApi.ts index f715d28..8ebefcc 100644 --- a/integration_tests/mockApis/manageUsersApi.ts +++ b/integration_tests/mockApis/manageUsersApi.ts @@ -33,7 +33,7 @@ const stubUserRoles = () => headers: { 'Content-Type': 'application/json;charset=UTF-8', }, - jsonBody: [{ roleCode: 'SOME_USER_ROLE' }], + jsonBody: [{ roleCode: 'ROLE_CLIENT_CREDENTIALS' }], }, }) diff --git a/integration_tests/pages/addBaseClientDetails.ts b/integration_tests/pages/addBaseClientDetails.ts new file mode 100644 index 0000000..59bc3e2 --- /dev/null +++ b/integration_tests/pages/addBaseClientDetails.ts @@ -0,0 +1,46 @@ +import Page, { PageElement } from './page' + +export default class AddBaseClientDetailsPage extends Page { + constructor() { + super('Add new client') + } + + baseClientIdInput = (): PageElement => cy.get('[data-qa="base-client-id-input"]') + + baseClientServiceRadioButton = (): PageElement => cy.get('[data-qa="base-client-service-radio"]') + + baseClientPersonalRadioButton = (): PageElement => cy.get('[data-qa="base-client-personal-radio"]') + + baseClientTypeRadios = (): PageElement => cy.get('[data-qa="base-client-type-radios"]') + + baseClientAccessTokenValidityDropdown = (): PageElement => + cy.get('[data-qa="base-client-access-token-validity-dropdown"]') + + baseClientAccessTokenValidityInput = (): PageElement => cy.get('[data-qa="base-client-access-token-validity-input"]') + + baseClientApprovedScopesInput = (): PageElement => cy.get('[data-qa="base-client-approved-scopes-input"]') + + auditTrailDetailsInput = (): PageElement => cy.get('[data-qa="audit-trail-details-input"]') + + grantTypeInput = (): PageElement => cy.get('[data-qa="grant-type-input"]') + + grantAuthoritiesInput = (): PageElement => cy.get('[data-qa="grant-authorities-input"]') + + grantDatabaseUsernameInput = (): PageElement => cy.get('[data-qa="grant-database-username-input"]') + + grantRedirectUrisInput = (): PageElement => cy.get('[data-qa="grant-redirect-uris-input"]') + + grantJwtFieldsInput = (): PageElement => cy.get('[data-qa="grant-jwt-fields-input"]') + + grantAzureAdLoginFlowCheckboxes = (): PageElement => cy.get('[data-qa="grant-azure-ad-login-flow-checkboxes"]') + + configDoesExpireCheckbox = (): PageElement => cy.get('[data-qa="config-does-expire-checkbox"]') + + configExpiryDaysInput = (): PageElement => cy.get('[data-qa="config-expiry-days-input"]') + + configAllowedIpsInput = (): PageElement => cy.get('[data-qa="config-allowed-ips-input"]') + + saveButton = (): PageElement => cy.get('[data-qa="save-button"]') + + cancelLink = (): PageElement => cy.get('[data-qa="cancel-link"]') +} diff --git a/integration_tests/pages/addBaseClientGrant.ts b/integration_tests/pages/addBaseClientGrant.ts new file mode 100644 index 0000000..5d91d28 --- /dev/null +++ b/integration_tests/pages/addBaseClientGrant.ts @@ -0,0 +1,17 @@ +import Page from './page' + +export default class AddBaseClientGrantPage extends Page { + constructor() { + super('Select a grant type') + } + + grantTypeRadioGroup = () => cy.get('[data-qa="grant-type-radio-group"]') + + clientCredentialsRadio = () => cy.get('[data-qa="client-credentials-radio"]') + + authorizationCodeRadio = () => cy.get('[data-qa="authorization-code-radio"]') + + continueButton = () => cy.get('[data-qa="continue-button"]') + + cancelLink = () => cy.get('[data-qa="cancel-link"]') +} diff --git a/integration_tests/pages/confirmDeleteClient.ts b/integration_tests/pages/confirmDeleteClient.ts new file mode 100644 index 0000000..559b17e --- /dev/null +++ b/integration_tests/pages/confirmDeleteClient.ts @@ -0,0 +1,17 @@ +import Page, { PageElement } from './page' + +export default class ConfirmDeleteClientPage extends Page { + constructor() { + super('Delete client?') + } + + warningMessage = (): PageElement => cy.get('[data-qa="delete-warning"]') + + confirmInput = (): PageElement => cy.get('[data-qa="confirm-input"]') + + errorMessage = (): PageElement => cy.get('[data-qa="error-message"]') + + deleteButton = (): PageElement => cy.get('[data-qa="delete-button"]') + + cancelButton = (): PageElement => cy.get('[data-qa="cancel-button"]') +} diff --git a/integration_tests/pages/editBaseClientDeploymentDetails.ts b/integration_tests/pages/editBaseClientDeploymentDetails.ts new file mode 100644 index 0000000..a35a42b --- /dev/null +++ b/integration_tests/pages/editBaseClientDeploymentDetails.ts @@ -0,0 +1,33 @@ +import Page, { PageElement } from './page' + +export default class EditBaseClientDeploymentDetailsPage extends Page { + constructor() { + super('Edit deployment details') + } + + baseClientSummaryList = (): PageElement => cy.get('[data-qa="base-client-summary-list"]') + + deploymentTeamInput = (): PageElement => cy.get('[data-qa="deployment-team-input"]') + + deploymentTeamContactInput = (): PageElement => cy.get('[data-qa="deployment-team-contact-input"]') + + deploymentTeamSlackInput = (): PageElement => cy.get('[data-qa="deployment-team-slack-input"]') + + platformHostingRadios = (): PageElement => cy.get('[data-qa="platform-hosting-radios"]') + + platformNamespaceInput = (): PageElement => cy.get('[data-qa="platform-namespace-input"]') + + platformDeploymentInput = (): PageElement => cy.get('[data-qa="platform-deployment-input"]') + + platformSecretNameInput = (): PageElement => cy.get('[data-qa="platform-secret-name-input"]') + + platformSecretKeyInput = (): PageElement => cy.get('[data-qa="platform-secret-key-input"]') + + platformClientIdInput = (): PageElement => cy.get('[data-qa="platform-client-id-input"]') + + platformDeploymentInfoInput = (): PageElement => cy.get('[data-qa="platform-deployment-info-input"]') + + saveButton = (): PageElement => cy.get('[data-qa="save-button"]') + + cancelLink = (): PageElement => cy.get('[data-qa="cancel-link"]') +} diff --git a/integration_tests/pages/editBaseClientDetails.ts b/integration_tests/pages/editBaseClientDetails.ts new file mode 100644 index 0000000..1a60c99 --- /dev/null +++ b/integration_tests/pages/editBaseClientDetails.ts @@ -0,0 +1,46 @@ +import Page, { PageElement } from './page' + +export default class EditBaseClientDetailsPage extends Page { + constructor() { + super('Edit base client details') + } + + baseClientIdInput = (): PageElement => cy.get('[data-qa="base-client-id-input"]') + + baseClientServiceRadioButton = (): PageElement => cy.get('[data-qa="base-client-service-radio"]') + + baseClientPersonalRadioButton = (): PageElement => cy.get('[data-qa="base-client-personal-radio"]') + + baseClientTypeRadios = (): PageElement => cy.get('[data-qa="base-client-type-radios"]') + + baseClientAccessTokenValidityDropdown = (): PageElement => + cy.get('[data-qa="base-client-access-token-validity-dropdown"]') + + baseClientAccessTokenValidityInput = (): PageElement => cy.get('[data-qa="base-client-access-token-validity-input"]') + + baseClientApprovedScopesInput = (): PageElement => cy.get('[data-qa="base-client-approved-scopes-input"]') + + auditTrailDetailsInput = (): PageElement => cy.get('[data-qa="audit-trail-details-input"]') + + grantTypeInput = (): PageElement => cy.get('[data-qa="grant-type-input"]') + + grantAuthoritiesInput = (): PageElement => cy.get('[data-qa="grant-authorities-input"]') + + grantDatabaseUsernameInput = (): PageElement => cy.get('[data-qa="grant-database-username-input"]') + + grantRedirectUrisInput = (): PageElement => cy.get('[data-qa="grant-redirect-uris-input"]') + + grantJwtFieldsInput = (): PageElement => cy.get('[data-qa="grant-jwt-fields-input"]') + + grantAzureAdLoginFlowCheckboxes = (): PageElement => cy.get('[data-qa="grant-azure-ad-login-flow-checkboxes"]') + + configDoesExpireCheckbox = (): PageElement => cy.get('[data-qa="config-does-expire-checkbox"]') + + configExpiryDaysInput = (): PageElement => cy.get('[data-qa="config-expiry-days-input"]') + + configAllowedIpsInput = (): PageElement => cy.get('[data-qa="config-allowed-ips-input"]') + + saveButton = (): PageElement => cy.get('[data-qa="save-button"]') + + cancelLink = (): PageElement => cy.get('[data-qa="cancel-link"]') +} diff --git a/integration_tests/pages/newBaseClientGrant.ts b/integration_tests/pages/newBaseClientGrant.ts new file mode 100644 index 0000000..30cf6ef --- /dev/null +++ b/integration_tests/pages/newBaseClientGrant.ts @@ -0,0 +1,7 @@ +import Page from './page' + +export default class NewBaseClientGrantPage extends Page { + constructor() { + super('Select a grant type') + } +} diff --git a/integration_tests/pages/viewBaseClient.ts b/integration_tests/pages/viewBaseClient.ts new file mode 100644 index 0000000..52f3cdd --- /dev/null +++ b/integration_tests/pages/viewBaseClient.ts @@ -0,0 +1,33 @@ +import Page from './page' + +export default class ViewBaseClientPage extends Page { + constructor() { + super('Client:') + } + + clientInstanceList = () => cy.get('[data-qa="client-instance-list"]') + + clientInstanceRows = () => this.clientInstanceList().find('tr') + + clientInstanceDeleteButtons = () => this.clientInstanceList().find('[data-qa="delete-client-instance-link"]') + + addClientInstanceButton = () => cy.get('[data-qa="add-new-client-button"]') + + baseClientDetailsTable = () => cy.get('[data-qa="base-client-details-table"]') + + baseClientAuditTable = () => cy.get('[data-qa="base-client-audit-table"]') + + baseClientClientCredentialsTable = () => cy.get('[data-qa="base-client-client-credentials-table"]') + + baseClientAuthorizationCodeTable = () => cy.get('[data-qa="base-client-authorization-code-table"]') + + baseClientConfigTable = () => cy.get('[data-qa="base-client-config-table"]') + + baseClientDeploymentContactTable = () => cy.get('[data-qa="base-client-deployment-contact-table"]') + + baseClientDeploymentPlatformTable = () => cy.get('[data-qa="base-client-deployment-platform-table"]') + + changeClientDetailsLink = () => cy.get('[data-qa="change-client-details-link"]') + + changeDeploymentDetailsLink = () => cy.get('[data-qa="change-deployment-details-link"]') +} diff --git a/integration_tests/pages/viewBaseClientList.ts b/integration_tests/pages/viewBaseClientList.ts new file mode 100644 index 0000000..e260725 --- /dev/null +++ b/integration_tests/pages/viewBaseClientList.ts @@ -0,0 +1,19 @@ +import Page, { PageElement } from './page' + +export default class ViewBaseClientListPage extends Page { + constructor() { + super('OAuth Client details') + } + + public baseClientList = (): PageElement => cy.get('[data-qa=baseClientList]') + + public addNewBaseClient = (): PageElement => cy.get('[data-qa=addNewBaseClientButton]') + + public toggleFilterButton = (): PageElement => cy.get('.toggle-filter-button') + + public applyFilterButton = (): PageElement => cy.get('.govuk-button').contains('Apply filters') + + public filterPanel = (): PageElement => cy.get('.moj-filter') + + public roleFilterInputBox = (): PageElement => cy.get('[data-qa=roleFilterInputBox]') +} diff --git a/integration_tests/pages/viewClientSecrets.ts b/integration_tests/pages/viewClientSecrets.ts new file mode 100644 index 0000000..dbc40c8 --- /dev/null +++ b/integration_tests/pages/viewClientSecrets.ts @@ -0,0 +1,11 @@ +import Page, { PageElement } from './page' + +export default class ViewClientSecretsPage extends Page { + constructor() { + super('Client has been added') + } + + secretsTable = (): PageElement => cy.get('[data-qa="secrets-table"]') + + continueButton = (): PageElement => cy.get('[data-qa="continue-button"]') +} diff --git a/integration_tests/support/commands.ts b/integration_tests/support/commands.ts index e8d0a00..27393fa 100644 --- a/integration_tests/support/commands.ts +++ b/integration_tests/support/commands.ts @@ -1,4 +1,5 @@ -Cypress.Commands.add('signIn', (options = { failOnStatusCode: true }) => { - cy.request('/') - return cy.task('getSignInUrl').then((url: string) => cy.visit(url, options)) +Cypress.Commands.add('signIn', (options = { failOnStatusCode: true, redirectPath: '/' }) => { + const { failOnStatusCode, redirectPath } = options + cy.request(redirectPath) + return cy.task('getSignInUrl').then((url: string) => cy.visit(url, { failOnStatusCode })) }) diff --git a/server/data/localMockData/baseClientsResponseMock.ts b/server/data/localMockData/baseClientsResponseMock.ts index 0d9623c..37958b3 100644 --- a/server/data/localMockData/baseClientsResponseMock.ts +++ b/server/data/localMockData/baseClientsResponseMock.ts @@ -1,4 +1,9 @@ -import { GetBaseClientResponse, ListBaseClientsResponse } from '../../interfaces/baseClientApi/baseClientResponse' +import { + ClientSecretsResponse, + GetBaseClientResponse, + ListBaseClientsResponse, + ListClientInstancesResponse, +} from '../../interfaces/baseClientApi/baseClientResponse' export const listBaseClientsResponseMock: ListBaseClientsResponse = { clients: [ @@ -7,6 +12,7 @@ export const listBaseClientsResponseMock: ListBaseClientsResponse = { clientType: 'SERVICE', teamName: null, grantType: 'client_credentials', + roles: 'ROLE_ONE, ROLE_TWO', count: 1, }, { @@ -21,13 +27,14 @@ export const listBaseClientsResponseMock: ListBaseClientsResponse = { clientType: 'SERVICE', teamName: 'Team 2', grantType: 'client_credentials', + roles: 'ROLE_TWO, ROLE_THREE', count: 1, }, ], } export const getBaseClientResponseMock: GetBaseClientResponse = { - clientId: 'baseClientId1', + clientId: 'base_client_id_1', scopes: ['read', 'write'], authorities: ['ROLE_CLIENT_CREDENTIALS'], ips: [], @@ -48,3 +55,24 @@ export const getBaseClientResponseMock: GetBaseClientResponse = { deploymentInfo: 'deployment deployment info', }, } + +export const getListClientInstancesResponseMock: ListClientInstancesResponse = { + clients: [ + { + clientId: 'base_client_id_1_01', + created: '2020-01-01T00:00:00.000', + }, + { + clientId: 'base_client_id_1_02', + created: '2020-01-01T00:00:00.000', + }, + ], + grantType: 'client_credentials', +} + +export const getSecretsResponseMock: ClientSecretsResponse = { + clientId: 'base_client_id_1_03', + clientSecret: 'aaa', + base64ClientId: 'bbb', + base64ClientSecret: 'ccc', +} diff --git a/server/views/pages/base-client.njk b/server/views/pages/base-client.njk index e368421..b98901b 100644 --- a/server/views/pages/base-client.njk +++ b/server/views/pages/base-client.njk @@ -46,14 +46,20 @@ text: "" } ], - rows: presenter.clientsTable + rows: presenter.clientsTable, + attributes: { + "data-qa": "client-instance-list" + } }) }}
{{ govukButton({ - text: "Add new client" + text: "Add new client", + attributes: { + "data-qa": "add-new-client-button" + } }) }}
@@ -63,7 +69,7 @@

Base client details

@@ -97,7 +103,10 @@ html: toLinesHtml(baseClient.scopes) } ] - ] + ], + attributes: { + "data-qa": "base-client-details-table" + } }) }} {{ govukTable({ @@ -114,7 +123,10 @@ },{ text: baseClient.audit }] - ] + ], + attributes: { + "data-qa": "base-client-audit-table" + } }) }} @@ -148,7 +160,10 @@ text: baseClient.clientCredentials.databaseUserName } ] - ] + ], + attributes: { + "data-qa": "base-client-client-credentials-table" + } }) }} {% endif %} @@ -187,7 +202,10 @@ text: presenter.skipToAzureField } ] - ] + ], + attributes: { + "data-qa": "base-client-authorization-code-table" + } }) }} {% endif %} @@ -214,7 +232,10 @@ html: toLinesHtml(baseClient.config.allowedIPs) } ] - ] + ], + attributes: { + "data-qa": "base-client-config-table" + } }) }} @@ -275,7 +296,10 @@ text: presenter.serviceEnabledLabel } ] - ] + ], + attributes: { + "data-qa": "base-client-service-table" + } }) }} {% endif %} @@ -284,7 +308,7 @@

Deployment details

@@ -319,7 +343,10 @@ text: baseClient.deployment.teamSlack } ] - ] + ], + attributes: { + "data-qa": "base-client-deployment-contact-table" + } }) }} {{ govukTable({ @@ -380,8 +407,10 @@ text: baseClient.deployment.deploymentInfo } ] - - ] + ], + attributes: { + "data-qa": "base-client-deployment-platform-table" + } }) }} diff --git a/server/views/pages/base-clients.njk b/server/views/pages/base-clients.njk index 3c0d4c6..822bfb8 100644 --- a/server/views/pages/base-clients.njk +++ b/server/views/pages/base-clients.njk @@ -33,6 +33,9 @@ text: 'Role', classes: 'govuk-label--m' }, + attributes: { + 'data-qa': 'roleFilterInputBox' + }, value: presenter.filter.roleSearch }) }} @@ -127,7 +130,10 @@ items: [{ text: 'Add new client', href:"/base-clients/new", - classes: 'govuk-button--primary' + classes: 'govuk-button--primary', + attributes: { + 'data-qa': 'addNewBaseClientButton' + } }] }) }} diff --git a/server/views/pages/delete-client-instance.njk b/server/views/pages/delete-client-instance.njk index 47518d0..571c812 100644 --- a/server/views/pages/delete-client-instance.njk +++ b/server/views/pages/delete-client-instance.njk @@ -25,17 +25,24 @@ {% if isLastClient %} {{ govukWarningText({ text: "Deleting this client will also delete base-client '" + baseClient.baseClientId + "'.", - iconFallbackText: "Warning" + iconFallbackText: "Warning", + attributes: { + "data-qa": "delete-warning" + } }) }} {% endif %} {{ govukWarningText({ text: "Deleted clients cannot be restored!", - iconFallbackText: "Warning" + iconFallbackText: "Warning", + attributes: { + "data-qa": "delete-warning" + } }) }}
+ {% if error %} {{ govukInput({ label: { text: "Confirmation" @@ -44,21 +51,49 @@ html: "Type \"" + clientId + "\" to confirm" }, errorMessage: { - text: error + text: error, + attributes: { + "data-qa": "error-message" + } }, classes: "govuk-!-width-two-thirds", id: "confirm", - name: "confirm" + name: "confirm", + attributes: { + "data-qa": "confirm-input" + } }) }} + {% else %} + {{ govukInput({ + label: { + text: "Confirmation" + }, + hint: { + html: "Type \"" + clientId + "\" to confirm" + }, + classes: "govuk-!-width-two-thirds", + id: "confirm", + name: "confirm", + attributes: { + "data-qa": "confirm-input" + } + }) }} + {% endif %} {{ govukButton({ text: "Delete client instance", type: "submit", - classes: "govuk-button--warning" + classes: "govuk-button--warning", + attributes: { + "data-qa": "delete-button" + } }) }} {{ govukButton({ text: "Cancel", - href: "/base-clients/" + baseClient.baseClientId + href: "/base-clients/" + baseClient.baseClientId, + attributes: { + "data-qa": "cancel-button" + } }) }}
diff --git a/server/views/pages/edit-base-client-deployment.njk b/server/views/pages/edit-base-client-deployment.njk index 06fb71f..64c412d 100644 --- a/server/views/pages/edit-base-client-deployment.njk +++ b/server/views/pages/edit-base-client-deployment.njk @@ -44,7 +44,10 @@ text: baseClient.baseClientId } } - ] + ], + attributes: { + "data-qa": "base-client-summary-list" + } }) }} @@ -59,7 +62,10 @@ }, id: "team", name: "team", - value: baseClient.deployment.team + value: baseClient.deployment.team, + attributes: { + "data-qa": "deployment-team-input" + } }) }} {{ govukInput({ @@ -68,7 +74,10 @@ }, id: "team-contact", name: "teamContact", - value: baseClient.deployment.teamContact + value: baseClient.deployment.teamContact, + attributes: { + "data-qa": "deployment-team-contact-input" + } }) }} {{ govukInput({ @@ -77,7 +86,10 @@ }, id: "team-slack", name: "teamSlack", - value: baseClient.deployment.teamSlack + value: baseClient.deployment.teamSlack, + attributes: { + "data-qa": "deployment-team-slack-input" + } }) }} @@ -104,7 +116,10 @@ text: "Other" } ], - value: baseClient.deployment.hosting + value: baseClient.deployment.hosting, + attributes: { + "data-qa": "platform-hosting-radios" + } }) }}
@@ -115,7 +130,10 @@ }, id: "namespace", name: "namespace", - value: baseClient.deployment.namespace + value: baseClient.deployment.namespace, + attributes: { + "data-qa": "platform-namespace-input" + } }) }} {{ govukInput({ @@ -124,7 +142,10 @@ }, id: "deployment", name: "deployment", - value: baseClient.deployment.deployment + value: baseClient.deployment.deployment, + attributes: { + "data-qa": "platform-deployment-input" + } }) }} {{ govukInput({ @@ -133,7 +154,10 @@ }, id: "secret-name", name: "secretName", - value: baseClient.deployment.secretName + value: baseClient.deployment.secretName, + attributes: { + "data-qa": "platform-secret-name-input" + } }) }} {{ govukInput({ @@ -142,7 +166,10 @@ }, id: "client-id-key", name: "clientIdKey", - value: baseClient.deployment.clientIdKey + value: baseClient.deployment.clientIdKey, + attributes: { + "data-qa": "platform-client-id-input" + } }) }} {{ govukInput({ @@ -151,7 +178,10 @@ }, id: "secret-key", name: "secretKey", - value: baseClient.deployment.secretKey + value: baseClient.deployment.secretKey, + attributes: { + "data-qa": "platform-secret-key-input" + } }) }}
@@ -164,16 +194,22 @@ text: "Deployment info", isPageHeading: false }, - value: baseClient.deployment.deploymentInfo + value: baseClient.deployment.deploymentInfo, + attributes: { + "data-qa": "platform-deployment-info-input" + } }) }}
{{ govukButton({ text: "Save", type: "submit", - preventDoubleClick: true + preventDoubleClick: true, + attributes: { + "data-qa": "save-button" + } }) }} - Cancel + Cancel
diff --git a/server/views/pages/edit-base-client-details.njk b/server/views/pages/edit-base-client-details.njk index acec658..abd0bde 100644 --- a/server/views/pages/edit-base-client-details.njk +++ b/server/views/pages/edit-base-client-details.njk @@ -44,7 +44,10 @@ classes: "govuk-!-width-two-thirds", id: "base-client-id", value: baseClient.baseClientId, - disabled: true + disabled: true, + attributes: { + "data-qa": "base-client-id-input" + } }) }} {{ govukRadios({ @@ -59,14 +62,23 @@ items: [ { value: "SERVICE", - text: "Service" + text: "Service", + attributes: { + "data-qa": "base-client-service-radio" + } }, { value: "PERSONAL", - text: "Personal" + text: "Personal", + attributes: { + "data-qa": "base-client-personal-radio" + } } ], - value: baseClient.clientType + value: baseClient.clientType, + attributes: { + "data-qa": "base-client-type-radios" + } }) }} {{ govukSelect({ @@ -98,7 +110,10 @@ text: "Custom" } ], - value: presenter.accessTokenValidityDropdown + value: presenter.accessTokenValidityDropdown, + attributes: { + "data-qa": "base-client-access-token-validity-dropdown" + } }) }}
@@ -109,7 +124,10 @@ classes: "govuk-!-width-one-half", id: "custom-access-token-validity", name: "customAccessTokenValidity", - value: presenter.accessTokenValidityText + value: presenter.accessTokenValidityText, + attributes: { + "data-qa": "base-client-access-token-validity-input" + } }) }}
@@ -123,7 +141,10 @@ hint: { text: "read, write ..." }, - value: toLines(baseClient.scopes) + value: toLines(baseClient.scopes), + attributes: { + "data-qa": "base-client-approved-scopes-input" + } }) }}

Audit trail

@@ -137,7 +158,10 @@ hint: { text: "jira tickets, slack messages ..." }, - value: baseClient.audit + value: baseClient.audit, + attributes: { + "data-qa": "audit-trail-details-input" + } }) }}

Grant details

@@ -151,7 +175,10 @@ id: "grant-type", name: "grantType", value: "Client credentials", - disabled: true + disabled: true, + attributes: { + "data-qa": "grant-type-input" + } }) }} {{ govukTextarea({ @@ -161,7 +188,10 @@ text: "Authorities", isPageHeading: false }, - value: toLines(baseClient.clientCredentials.authorities) + value: toLines(baseClient.clientCredentials.authorities), + attributes: { + "data-qa": "grant-authorities-input" + } }) }} {{ govukInput({ @@ -171,7 +201,10 @@ classes: "govuk-!-width-two-thirds", id: "database-username", name: "databaseUsername", - value: baseClient.clientCredentials.databaseUsername + value: baseClient.clientCredentials.databaseUsername, + attributes: { + "data-qa": "grant-database-username-input" + } }) }} {% endif %} @@ -184,7 +217,10 @@ id: "grant-type", name: "grantType", value: "Authorization code", - disabled: true + disabled: true, + attributes: { + "data-qa": "grant-type-input" + } }) }} {{ govukTextarea({ @@ -194,7 +230,10 @@ text: "Registered redirect URIs", isPageHeading: false }, - value: toLines(baseClient.authorizationCode.redirectUris) + value: toLines(baseClient.authorizationCode.redirectUris), + attributes: { + "data-qa": "grant-redirect-uris-input" + } }) }} {{ govukInput({ label: { @@ -206,7 +245,10 @@ classes: "govuk-!-width-one-third", id: "jwt-fields", name: "jwtFields", - value: baseClient.authorizationCode.jwtFields + value: baseClient.authorizationCode.jwtFields, + attributes: { + "data-qa": "grant-jwt-fields-input" + } }) }} @@ -227,7 +269,10 @@ text: "Auto redirect", checked: baseClient.authorisationCode.azureAdLoginFlow } - ] + ], + attributes: { + "data-qa": "grant-azure-ad-login-flow-checkboxes" + } }) }} {% endif %} @@ -240,10 +285,13 @@ text: "allow client to expire", checked: presenter.expiry, conditional: { - html: "" + html: "" } } - ] + ], + attributes: { + "data-qa": "config-does-expire-checkbox" + } }) }} {{ govukTextarea({ @@ -256,16 +304,22 @@ hint: { html: "One IP address/CIDR notation per line
81.134.202.29/32 - mojvpn
35.176.93.186/32 - global-protect
35.178.209.113/32 - cloudplatform-1
3.8.51.207/32 - cloudplatform-2
35.177.252.54/32 - cloudplatform-3" }, - value: toLines(baseClient.config.allowedIPs) + value: toLines(baseClient.config.allowedIPs), + attributes: { + "data-qa": "config-allowed-ips-input" + } }) }}
{{ govukButton({ text: "Save", type: "submit", - preventDoubleClick: true + preventDoubleClick: true, + attributes: { + "data-qa": "save-button" + } }) }} - Cancel + Cancel
diff --git a/server/views/pages/new-base-client-details.njk b/server/views/pages/new-base-client-details.njk index 3b25733..99f9966 100644 --- a/server/views/pages/new-base-client-details.njk +++ b/server/views/pages/new-base-client-details.njk @@ -41,7 +41,10 @@ id: "base-client-id", name: "baseClientId", value: baseClient.baseClientId, - errorMessage: errorMessage + errorMessage: errorMessage, + attributes: { + "data-qa": "base-client-id-input" + } }) }} {{ govukRadios({ @@ -56,14 +59,23 @@ items: [ { value: "SERVICE", - text: "Service" + text: "Service", + attributes: { + "data-qa": "base-client-service-radio" + } }, { value: "PERSONAL", - text: "Personal" + text: "Personal", + attributes: { + "data-qa": "base-client-personal-radio" + } } ], - value: baseClient.clientType + value: baseClient.clientType, + attributes: { + "data-qa": "base-client-type-radios" + } }) }} {{ govukSelect({ @@ -95,6 +107,9 @@ text: "Custom" } ], + attributes: { + "data-qa": "base-client-access-token-validity-dropdown" + }, value: presenter.accessTokenValidityDropdown }) }} @@ -106,7 +121,10 @@ classes: "govuk-!-width-one-half", id: "custom-access-token-validity", name: "customAccessTokenValidity", - value: presenter.accessTokenValidityText + value: presenter.accessTokenValidityText, + attributes: { + "data-qa": "base-client-access-token-validity-input" + } }) }} @@ -120,7 +138,10 @@ classes: "govuk-!-width-one-third", id: "approved-scopes", name: "approvedScopes", - value: toLines(baseClient.scopes) + value: toLines(baseClient.scopes), + attributes: { + "data-qa": "base-client-approved-scopes-input" + } }) }}

Audit trail

@@ -134,7 +155,10 @@ hint: { text: "jira tickets, slack messages ..." }, - value: baseClient.audit + value: baseClient.audit, + attributes: { + "data-qa": "audit-trail-details-input" + } }) }}

Grant details

@@ -148,7 +172,10 @@ id: "grant-type", name: "grantType", value: "Client credentials", - disabled: true + disabled: true, + attributes: { + "data-qa": "grant-type-input" + } }) }} {{ govukTextarea({ @@ -158,7 +185,10 @@ text: "Authorities", isPageHeading: false }, - value: toLines(baseClient.clientCredentials.authorities) + value: toLines(baseClient.clientCredentials.authorities), + attributes: { + "data-qa": "grant-authorities-input" + } }) }} {{ govukInput({ @@ -168,7 +198,10 @@ classes: "govuk-!-width-two-thirds", id: "database-username", name: "databaseUsername", - value: baseClient.clientCredentials.databaseUsername + value: baseClient.clientCredentials.databaseUsername, + attributes: { + "data-qa": "grant-database-username-input" + } }) }} {% endif %} @@ -181,7 +214,10 @@ id: "grant-type", name: "grantType", value: "Authorization code", - disabled: true + disabled: true, + attributes: { + "data-qa": "grant-type-input" + } }) }} {{ govukTextarea({ @@ -191,7 +227,10 @@ text: "Registered redirect URIs", isPageHeading: false }, - value: toLines(baseClient.authorizationCode.redirectUris) + value: toLines(baseClient.authorizationCode.redirectUris), + attributes: { + "data-qa": "grant-redirect-uris-input" + } }) }} {{ govukInput({ label: { @@ -203,7 +242,10 @@ classes: "govuk-!-width-one-third", id: "jwt-fields", name: "jwtFields", - value: baseClient.authorizationCode.jwtFields + value: baseClient.authorizationCode.jwtFields, + attributes: { + "data-qa": "grant-jwt-fields-input" + } }) }} @@ -224,7 +266,10 @@ text: "Auto redirect", checked: baseClient.authorisationCode.azureAdLoginFlow } - ] + ], + attributes: { + "data-qa": "grant-azure-ad-login-flow-checkboxes" + } }) }} {% endif %} @@ -237,8 +282,11 @@ text: "allow client to expire", checked: presenter.expiry, conditional: { - html: "" - } + html: "" + }, + attributes: { + "data-qa": "config-does-expire-checkbox" + } } ] }) }} @@ -253,16 +301,22 @@ hint: { html: "One IP address/CIDR notation per line
81.134.202.29/32 - mojvpn
35.176.93.186/32 - global-protect
35.178.209.113/32 - cloudplatform-1
3.8.51.207/32 - cloudplatform-2
35.177.252.54/32 - cloudplatform-3" }, - value: toLines(baseClient.config.allowedIPs) + value: toLines(baseClient.config.allowedIPs), + attributes: { + "data-qa": "config-allowed-ips-input" + } }) }}
{{ govukButton({ text: "Save", type: "submit", - preventDoubleClick: true + preventDoubleClick: true, + attributes: { + "data-qa": "save-button" + } }) }} - Cancel + Cancel
diff --git a/server/views/pages/new-base-client-grant.njk b/server/views/pages/new-base-client-grant.njk index 5f116b9..b8c5bb5 100644 --- a/server/views/pages/new-base-client-grant.njk +++ b/server/views/pages/new-base-client-grant.njk @@ -30,14 +30,23 @@ items: [ { value: "client-credentials", - text: "Client credentials" + text: "Client credentials", + attributes: { + "data-qa": "client-credentials-radio" + } }, { value: "authorization-code", text: "Authorization code", - disabled: false + disabled: true, + attributes: { + "data-qa": "authorization-code-radio" + } } - ] + ], + attributes: { + "data-qa": "grant-type-radio-group" + } }) }} @@ -45,9 +54,12 @@ {{ govukButton({ text: "Continue", type: "submit", - preventDoubleClick: true + preventDoubleClick: true, + attributes: { + "data-qa": "continue-button" + } }) }} - Cancel + Cancel diff --git a/server/views/pages/new-base-client-success.njk b/server/views/pages/new-base-client-success.njk index af79057..9b76aac 100644 --- a/server/views/pages/new-base-client-success.njk +++ b/server/views/pages/new-base-client-success.njk @@ -29,13 +29,19 @@ [{ text: "new clientSecret" }, { text: secrets.clientSecret}], [{ text: "base64 clientId" }, { text: secrets.base64ClientId}], [{ text: "base64 clientSecret"}, { text: secrets.base64ClientSecret}] - ] + ], + attributes: { + "data-qa": "secrets-table" + } }) }}
{{ govukButton({ text: "Continue", - href: "/base-clients/" + baseClientId + href: "/base-clients/" + baseClientId, + attributes: { + "data-qa": "continue-button" + } }) }}
diff --git a/server/views/presenters/listBaseClientsPresenter.ts b/server/views/presenters/listBaseClientsPresenter.ts index 9fc0822..642526f 100644 --- a/server/views/presenters/listBaseClientsPresenter.ts +++ b/server/views/presenters/listBaseClientsPresenter.ts @@ -75,6 +75,9 @@ const indexTableRows = (data: BaseClient[], filter?: BaseClientListFilter) => { return dataItems.map(item => [ { html: `${item.baseClientId}`, + attributes: { + 'data-qa': 'baseClientList', + }, }, { html: item.count > 1 ? `${item.count}` : '', @@ -116,21 +119,29 @@ export const filterBaseClient = (baseClient: BaseClient, filter: BaseClientListF } } - if (baseClient.grantType === 'client_credentials' && !filter.clientCredentials) { + const grantType = baseClient.grantType ? baseClient.grantType.trim().toLowerCase() : '' + const clientType = baseClient.clientType ? baseClient.clientType.trim().toLowerCase() : '' + + if (grantType === 'client_credentials' && !filter.clientCredentials) { return false } - if (baseClient.grantType === 'authorisation_code' && !filter.authorisationCode) { + if (grantType === 'authorisation_code' && !filter.authorisationCode) { return false } - if (baseClient.clientType === 'PERSONAL' && !filter.personalClientType) { + if (clientType === 'personal' && !filter.personalClientType) { return false } - if (baseClient.clientType === 'SERVICE' && !filter.serviceClientType) { + if (clientType === 'service' && !filter.serviceClientType) { return false } - return filter.blankClientType + + if (clientType === '' && !filter.blankClientType) { + return false + } + + return true } export default (data: BaseClient[], filter?: BaseClientListFilter) => { diff --git a/server/views/presenters/viewBaseClientPresenter.test.ts b/server/views/presenters/viewBaseClientPresenter.test.ts index b3d680e..76878f1 100644 --- a/server/views/presenters/viewBaseClientPresenter.test.ts +++ b/server/views/presenters/viewBaseClientPresenter.test.ts @@ -43,8 +43,8 @@ describe('viewBaseClientPresenter', () => { // Then the dates are formatted as DD/MM/YYYY const expected = [ - 'delete', - 'delete', + 'delete', + 'delete', ] const actual = presenter.clientsTable.map(row => row[3].html) expect(expected).toEqual(actual) diff --git a/server/views/presenters/viewBaseClientPresenter.ts b/server/views/presenters/viewBaseClientPresenter.ts index 90839f8..e0443f7 100644 --- a/server/views/presenters/viewBaseClientPresenter.ts +++ b/server/views/presenters/viewBaseClientPresenter.ts @@ -12,10 +12,10 @@ export default (baseClient: BaseClient, clients: Client[]) => { html: item.created.toLocaleDateString('en-GB'), }, { - html: item.accessed.toLocaleDateString('en-GB'), + html: item.accessed ? item.accessed.toLocaleDateString('en-GB') : '', }, { - html: `delete`, + html: `delete`, }, ]), expiry: baseClient.config.expiryDate ? `Yes - days remaining ${daysRemaining(baseClient.config.expiryDate)}` : 'No',