From 9b3e42bdbb196ce0c1a146236b6b4488f56d0ab3 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Mon, 13 Jul 2026 15:38:45 +0300 Subject: [PATCH 1/7] Print error and exit if AWS credentials are not present Make it easier to understand what's happening if you run one of the bin scripts that try to load environment variables from AWS parameter store but forget to run with AWS credentials available. --- bin/load_env_vars.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/load_env_vars.sh b/bin/load_env_vars.sh index 8542a9d..ff8d631 100644 --- a/bin/load_env_vars.sh +++ b/bin/load_env_vars.sh @@ -128,6 +128,11 @@ function set_e2e_env_vars() { exit 1 fi + if ! aws sts get-caller-identity > /dev/null 2>&1; then + echo "Could not access AWS resources; make sure you've assumed a role in the AWS account you're targeting." >&2 + exit 1 + fi + export SETTINGS__FORM_IDS__S3="$(s3_form_id $environment)" export SETTINGS__FORMS_ADMIN__URL="$(admin_url $environment)" export SETTINGS__FORMS_ADMIN__AUTH__USERNAME="$(get_param /${environment}/automated-tests/e2e/auth0/email-username)" From c449def11a9e499a36be059b0b90645a5b9d3c62 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Mon, 13 Jul 2026 14:58:34 +0300 Subject: [PATCH 2/7] Stop saving environment variable values to disk `bin/dockerfile_test.sh` was saving environment variables needed to run the end to end tests in a file to be able to pass them to Docker; this is less than ideal because some of the values of the environment variables should be kept secret. We only need to pass the names of the environment variables to the Docker CLI, it can retrieve the values itself; this commit updates the Dockerfile test script to cut out the values before they are saved. --- bin/dockerfile_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/dockerfile_test.sh b/bin/dockerfile_test.sh index c635fb7..d9a652e 100755 --- a/bin/dockerfile_test.sh +++ b/bin/dockerfile_test.sh @@ -50,7 +50,7 @@ fi echo 'Running the tests against dev environment' -env | grep -e AWS_ -e SETTINGS__ > ./env.list +env | grep -e AWS_ -e SETTINGS__ | cut -d = -f 1 > ./env.list docker run --env-file ./env.list --rm \ -e SMOKE_TEST_FORM_URL \ From ad87383110f2ae709ed93319325c3540148a92fc Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Mon, 13 Jul 2026 12:01:58 +0300 Subject: [PATCH 3/7] Add Active Support gem to dependencies Add Active Support to our Gemfile so we can use some of the core extensions in our code. --- Gemfile | 1 + Gemfile.lock | 1 + 2 files changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index 70c83a1..5f1ef69 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source "https://rubygems.org" ruby file: ".ruby-version" +gem "activesupport" gem "aws-sdk-s3", "~> 1.226" gem "capybara" gem "config" diff --git a/Gemfile.lock b/Gemfile.lock index 8f3182a..34898ad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -230,6 +230,7 @@ PLATFORMS x86_64-linux-musl DEPENDENCIES + activesupport aws-sdk-s3 (~> 1.226) capybara config From 3c58ea3443b4c5f7a00875b14aec35c8cc07117a Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Mon, 13 Jul 2026 13:30:28 +0300 Subject: [PATCH 4/7] Remove legacy configuration --- bin/dockerfile_test.sh | 7 ------ spec/smoke_tests/smoke_test_runner_spec.rb | 14 +++++------ spec/support/aws_helpers.rb | 14 ++++------- spec/support/feature_helpers.rb | 27 ++++++++-------------- 4 files changed, 20 insertions(+), 42 deletions(-) diff --git a/bin/dockerfile_test.sh b/bin/dockerfile_test.sh index d9a652e..92c8451 100755 --- a/bin/dockerfile_test.sh +++ b/bin/dockerfile_test.sh @@ -30,13 +30,6 @@ if [[ -z "$IMAGE_TO_TEST" ]]; then docker build -t "$IMAGE_TO_TEST" . fi -# Map legacy environment variables to settings -export SETTINGS__FORMS_ADMIN__URL="${SETTINGS__FORMS_ADMIN__URL:-$FORMS_ADMIN_URL}" -export SETTINGS__FORMS_ADMIN__AUTH__USERNAME="${SETTINGS__FORMS_ADMIN__AUTH__USERNAME:-$AUTH0_EMAIL_USERNAME}" -export SETTINGS__FORMS_ADMIN__AUTH__PASSWORD="${SETTINGS__FORMS_ADMIN__AUTH__PASSWORD:-$AUTH0_USER_PASSWORD}" -export SETTINGS__FORMS_PRODUCT_PAGE__URL="${SETTINGS__FORMS_PRODUCT_PAGE__URL:-$PRODUCT_PAGES_URL}" -export SETTINGS__FORMS_RUNNER__URL="${SETTINGS__FORMS_RUNNER__URL:-$FORMS_RUNNER_URL}" - if [ -z "$SETTINGS__FORMS_ADMIN__URL" ] || \ [ -z "$SETTINGS__FORMS_ADMIN__AUTH__USERNAME" ] || \ [ -z "$SETTINGS__FORMS_ADMIN__AUTH__PASSWORD" ] || \ diff --git a/spec/smoke_tests/smoke_test_runner_spec.rb b/spec/smoke_tests/smoke_test_runner_spec.rb index 15fb2fc..30b5439 100644 --- a/spec/smoke_tests/smoke_test_runner_spec.rb +++ b/spec/smoke_tests/smoke_test_runner_spec.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true +require "active_support" +require "active_support/core_ext/object/blank" + feature "Runner Smoke Test", type: :feature do let(:smoke_test_form_url) do - # TODO: Update this once we're confident no one is setting $SMOKE_TEST_FORM_URL - # https://trello.com/c/tIYmMZ3e/3457-remove-backwards-compatibility-for-legacy-e2e-test-env-vars - if Settings.form_ids.smoke_test - "#{Settings.forms_runner.url}/form/#{Settings.form_ids.smoke_test}" - else - ENV["SMOKE_TEST_FORM_URL"] { raise "Settings.form_ids.smoke_test is not set" } - end + raise "Settings.form_runner.url is not set" unless Settings.forms_runner.url.present? + raise "Settings.form_ids.smoke_test is not set" unless Settings.form_ids.smoke_test.present? + + "#{Settings.forms_runner.url}/form/#{Settings.form_ids.smoke_test}" end before do diff --git a/spec/support/aws_helpers.rb b/spec/support/aws_helpers.rb index 802e241..eecc782 100644 --- a/spec/support/aws_helpers.rb +++ b/spec/support/aws_helpers.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "active_support" +require "active_support/core_ext/object/blank" require "aws-sdk-s3" module AwsHelpers @@ -86,9 +88,7 @@ def s3_client end def assume_role - @role_arn = Settings.aws.s3_submission_iam_role_arn - - raise "Settings.aws.s3_submission_iam_role_arn is not set" if @role_arn.nil? || @role_arn.empty? + @role_arn = Settings.aws.s3_submission_iam_role_arn.presence or raise "Settings.aws.s3_submission_iam_role_arn is not set" role_session_name = "forms-e2e" Aws::AssumeRoleCredentials.new( @@ -99,13 +99,7 @@ def assume_role end def get_submissions_bucket - # TODO: Update this once we're confident no one is setting $AWS_S3_BUCKET - # https://trello.com/c/tIYmMZ3e/3457-remove-backwards-compatibility-for-legacy-e2e-test-env-vars - bucket = Settings.aws.s3_submission_bucket_name || Settings.aws.file_upload_s3_bucket_name || ENV["AWS_S3_BUCKET"] - - raise "Settings.aws.s3_submission_bucket_name is not set" if bucket.nil? || bucket.empty? - - bucket + Settings.aws.s3_submission_bucket_name.presence or raise "Settings.aws.s3_submission_bucket_name is not set" end def find_submission_key(submission_reference, bucket, form_id) diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index 918cc33..7007447 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true +require "active_support" +require "active_support/core_ext/object/blank" require "rotp" + require_relative "./notify_helpers" require_relative "./aws_helpers" @@ -32,21 +35,15 @@ def answer_for(question_type) end def forms_admin_url - # TODO: Update this once we're confident no one is setting $FORMS_ADMIN_URL - # https://trello.com/c/tIYmMZ3e/3457-remove-backwards-compatibility-for-legacy-e2e-test-env-vars - Settings.forms_admin.url || ENV.fetch("FORMS_ADMIN_URL") { raise "Settings.forms_admin.url is not set" } + Settings.forms_admin.url.presence or raise "Settings.forms_admin.url is not set" end def forms_product_page_url - # TODO: Update this once we're confident no one is setting $PRODUCT_PAGES_URL - # https://trello.com/c/tIYmMZ3e/3457-remove-backwards-compatibility-for-legacy-e2e-test-env-vars - Settings.forms_product_page.url || ENV.fetch("PRODUCT_PAGES_URL") { raise "Settings.forms_product_page.url is not set" } + Settings.forms_product_page.url.presence or raise "Settings.forms_product_page.url is not set" end def forms_runner_url - # TODO: Update this once we're confident no one is setting $FORMS_RUNNER_URL - # https://trello.com/c/tIYmMZ3e/3457-remove-backwards-compatibility-for-legacy-e2e-test-env-vars - Settings.forms_runner.url || ENV.fetch("FORMS_RUNNER_URL") { raise "Settings.forms_runner.url is not set" } + Settings.forms_runner.url.presence or raise "Settings.forms_runner.url is not set" end def submission_status_url @@ -503,9 +500,7 @@ def check_submission(submission_reference) end def s3_form_is_filled_in_by_form_filler - # TODO: Update this once we're confident no one is using $S3_FORM_ID - # https://trello.com/c/tIYmMZ3e/3457-remove-backwards-compatibility-for-legacy-e2e-test-env-vars - form_id = Settings.form_ids.s3 || ENV.fetch("S3_FORM_ID") { raise "Settings.form_ids.s3 is not set" } + form_id = Settings.form_ids.s3.presence or raise "Settings.form_ids.s3 is not set" s3_form_live_link = "#{forms_runner_url}/form/#{form_id}" @@ -579,15 +574,11 @@ def sign_in end def auth0_email_address - # TODO: Update this once we're confident no one is setting $AUTH0_EMAIL_USERNAME - # https://trello.com/c/tIYmMZ3e/3457-remove-backwards-compatibility-for-legacy-e2e-test-env-vars - Settings.forms_admin.auth.username || ENV.fetch("AUTH0_EMAIL_USERNAME") { raise "Settings.forms_admin.auth.username is not set" } + Settings.forms_admin.auth.username.presence or raise "Settings.forms_admin.auth.username is not set" end def auth0_password - # TODO: Remove this once we're confident no one is setting $AUTH0_USER_PASSWORD - # https://trello.com/c/tIYmMZ3e/3457-remove-backwards-compatibility-for-legacy-e2e-test-env-vars - Settings.forms_admin.auth.password || ENV.fetch("AUTH0_USER_PASSWORD") { raise "Settings.forms_admin.auth.password is not set" } + Settings.forms_admin.auth.password.presence or raise "Settings.forms_admin.auth.password is not set" end def sign_in_to_auth0 From 8e52839245fc53f964e9bb4857d60345f5ee899a Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Mon, 13 Jul 2026 14:39:52 +0300 Subject: [PATCH 5/7] Rename development configuration to local Renames the file for settings for running the tests against a local development server to "local", to distinguish it from the "dev" development environment in AWS. This matches what we call `Settings.forms_env` for local development in forms-admin [[1]]. Note that we also update the default for the environment name so that local development is the still the default environment, so this change shouldn't affect people unless they are explicitly setting the environment to `development` for some reason. [1]: https://github.com/govuk-forms/forms-admin/blob/354f8053d60794a75ddae50941b4b87d738ac25c/config/settings.yml#L110 --- config/settings/{development.yml => local.yml} | 0 spec/spec_helper.rb | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename config/settings/{development.yml => local.yml} (100%) diff --git a/config/settings/development.yml b/config/settings/local.yml similarity index 100% rename from config/settings/development.yml rename to config/settings/local.yml diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index acee357..1693b01 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ require "debug" -ENV["SETTINGS__FORMS_ENV"] ||= "development" +ENV["SETTINGS__FORMS_ENV"] ||= "local" require_relative "../config/environment" From 9cdb4cc9dbfcfd31e51f0647ed543cd6aee0b16a Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Mon, 13 Jul 2026 15:14:39 +0300 Subject: [PATCH 6/7] Add settings file for each AWS environment Add files with configuration for end to end tests for each environment in AWS. The files are named `aws_#{environment_name}`, with the environment name retrieved from `SETTINGS__FORMS_ENV`, which is normally set by forms-deploy or the scripts in the bin folder. --- config/environment.rb | 1 + config/settings/aws_dev.yml | 17 +++++++++++++++++ config/settings/aws_production.yml | 17 +++++++++++++++++ config/settings/aws_staging.yml | 17 +++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 config/settings/aws_dev.yml create mode 100644 config/settings/aws_production.yml create mode 100644 config/settings/aws_staging.yml diff --git a/config/environment.rb b/config/environment.rb index d75861a..c7fad65 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -3,4 +3,5 @@ require_relative "initializers/config" env = ENV["SETTINGS__FORMS_ENV"] +env = "aws_#{env}" unless env == "local" Config.load_and_set_settings(Config.setting_files(__dir__, env)) diff --git a/config/settings/aws_dev.yml b/config/settings/aws_dev.yml new file mode 100644 index 0000000..f68a5c7 --- /dev/null +++ b/config/settings/aws_dev.yml @@ -0,0 +1,17 @@ +form_ids: + smoke_test: 11120 + s3: 12457 + +forms_admin: + url: https://admin.dev.forms.service.gov.uk + +forms_product_page: + url: https://www.dev.forms.service.gov.uk + +forms_runner_url: + url: https://submit.dev.forms.service.gov.uk + +aws: + s3_submission_bucket_name: govuk-forms-submissions-to-s3-test + s3_submission_iam_role_arn: arn:aws:iam::498160065950:role/govuk-s3-end-to-end-test-dev + email_receiver_s3_bucket_name: govuk-forms-dev-test-emails diff --git a/config/settings/aws_production.yml b/config/settings/aws_production.yml new file mode 100644 index 0000000..e89a8de --- /dev/null +++ b/config/settings/aws_production.yml @@ -0,0 +1,17 @@ +form_ids: + smoke_test: 2570 + s3: 5086 + +forms_admin: + url: https://admin.forms.service.gov.uk + +forms_product_page: + url: https://www.forms.service.gov.uk + +forms_runner_url: + url: https://submit.forms.service.gov.uk + +aws: + s3_submission_bucket_name: govuk-forms-submissions-to-s3-test + s3_submission_iam_role_arn: arn:aws:iam::443944947292:role/govuk-s3-end-to-end-test-production + email_receiver_s3_bucket_name: govuk-forms-production-test-emails diff --git a/config/settings/aws_staging.yml b/config/settings/aws_staging.yml new file mode 100644 index 0000000..6a6b4b3 --- /dev/null +++ b/config/settings/aws_staging.yml @@ -0,0 +1,17 @@ +form_ids: + smoke_test: 12148 + s3: 13657 + +forms_admin: + url: https://admin.staging.forms.service.gov.uk + +forms_product_page: + url: https://www.staging.forms.service.gov.uk + +forms_runner_url: + url: https://submit.staging.forms.service.gov.uk + +aws: + s3_submission_bucket_name: govuk-forms-submissions-to-s3-test + s3_submission_iam_role_arn: arn:aws:iam::972536609845:role/govuk-s3-end-to-end-test-staging + email_receiver_s3_bucket_name: govuk-forms-staging-test-emails From 44d5b24747754bf96c1f9a55caff78a6c1db6578 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Mon, 13 Jul 2026 15:18:45 +0300 Subject: [PATCH 7/7] Simplify script for loading settings Now that most of the configuration settings needed to run the end to end tests are in settings files (see previous commit), we can reduce the amount of Bash needed in the bin scripts and focus on loading just secrets from AWS parameter store. --- README.md | 2 +- bin/dockerfile_test.sh | 11 ++- bin/end_to_end.sh | 4 +- bin/load_env_vars.sh | 157 ----------------------------------------- bin/secrets.sh | 34 +++++++++ bin/smoke_tests.sh | 3 - 6 files changed, 41 insertions(+), 170 deletions(-) delete mode 100644 bin/load_env_vars.sh create mode 100644 bin/secrets.sh diff --git a/README.md b/README.md index f8dc4a8..e6783e4 100644 --- a/README.md +++ b/README.md @@ -186,4 +186,4 @@ The tests expect an editor user exist with an Auth0 database connection configur The user should belong to an active group, called "End to end tests", as a group admin to allow publishing a form. -The login details should be stored in AWS parameter store. See bin/load_env_vars.sh for configuring the enviroment varibles required. +The login details should be stored in AWS parameter store. See bin/secrets.sh for configuring the enviroment varibles required. diff --git a/bin/dockerfile_test.sh b/bin/dockerfile_test.sh index 92c8451..276f5a5 100755 --- a/bin/dockerfile_test.sh +++ b/bin/dockerfile_test.sh @@ -30,15 +30,12 @@ if [[ -z "$IMAGE_TO_TEST" ]]; then docker build -t "$IMAGE_TO_TEST" . fi -if [ -z "$SETTINGS__FORMS_ADMIN__URL" ] || \ - [ -z "$SETTINGS__FORMS_ADMIN__AUTH__USERNAME" ] || \ +if [ -z "$SETTINGS__FORMS_ADMIN__AUTH__USERNAME" ] || \ [ -z "$SETTINGS__FORMS_ADMIN__AUTH__PASSWORD" ] || \ - [ -z "$SETTINGS__FORMS_PRODUCT_PAGE__URL" ] || \ [ -z "$SETTINGS__GOVUK_NOTIFY__API_KEY" ]; then - echo "Loading env vars from parameter store" - source $SCRIPT_DIR/load_env_vars.sh - set_e2e_env_vars 'dev' - set_smoke_test_env_vars 'dev' + echo "Loading secrets from parameter store" + source $SCRIPT_DIR/secrets.sh + export_secrets 'dev' fi echo 'Running the tests against dev environment' diff --git a/bin/end_to_end.sh b/bin/end_to_end.sh index 9ca7cd8..d7499a0 100755 --- a/bin/end_to_end.sh +++ b/bin/end_to_end.sh @@ -21,8 +21,8 @@ gds aws forms-dev-readonly -- $0 dev exit 0 fi -source ./load_env_vars.sh -set_e2e_env_vars "$environment" +source ./secrets.sh +export_secrets "$environment" cd .. bundle install diff --git a/bin/load_env_vars.sh b/bin/load_env_vars.sh deleted file mode 100644 index ff8d631..0000000 --- a/bin/load_env_vars.sh +++ /dev/null @@ -1,157 +0,0 @@ -#!/bin/bash - -function admin_url() { - local environment="$1" - - case $environment in - "dev") echo "https://admin.dev.forms.service.gov.uk" ;; - "staging") echo "https://admin.staging.forms.service.gov.uk" ;; - "production") echo "https://admin.forms.service.gov.uk" ;; - *) - echo "Unknown environment: ${environment}" - exit 1 - ;; - esac -} - -function product_pages_url() { - local environment="$1" - - case $environment in - "dev") echo "https://www.dev.forms.service.gov.uk" ;; - "staging") echo "https://www.staging.forms.service.gov.uk" ;; - "production") echo "https://www.forms.service.gov.uk" ;; - *) - echo "Unknown environment: ${environment}" - exit 1 - ;; - esac -} - -function runner_url() { - local environment="$1" - - case $environment in - "dev") echo "https://submit.dev.forms.service.gov.uk" ;; - "staging") echo "https://submit.staging.forms.service.gov.uk" ;; - "production") echo "https://submit.forms.service.gov.uk" ;; - *) - echo "Unknown environment: ${environment}" - exit 1 - ;; - esac -} - -function aws_account_id() { - aws sts get-caller-identity --query Account --output text -} - -function aws_s3_role_arn() { - local environment="$1" - local account_id="$(aws_account_id)" - - case $environment in - "dev"|"staging"|"production") echo "arn:aws:iam::${account_id}:role/govuk-s3-end-to-end-test-${environment}" ;; - *) - echo "unknown environment: ${environment}" - exit 1 - ;; - esac -} - -function aws_s3_bucket() { - local environment="$1" - - case $environment in - "dev"|"staging"|"production") echo "govuk-forms-submissions-to-s3-test" ;; - *) - echo "unknown environment: ${environment}" - exit 1 - ;; - esac -} - -function email_receiver_s3_bucket() { - local environment="$1" - - case $environment in - "dev"|"staging"|"production") echo "govuk-forms-${environment}-test-emails" ;; - *) - echo "unknown environment: ${environment}" - exit 1 - ;; - esac -} - -function smoke_test_form_id() { - local environment="$1" - - case $environment in - "dev") echo "11120" ;; - "staging") echo "12148" ;; - "production") echo "2570" ;; - *) - echo "Unknown environment: ${environment}" - exit 1 - ;; - esac -} - -function s3_form_id() { - local environment="$1" - - case $environment in - "dev") echo "12457" ;; - "staging") echo "13657" ;; - "production") echo "5086" ;; - *) - echo "Unknown environment: ${environment}" - exit 1 - ;; - esac -} - -function get_param() { - path="$1" - - aws ssm get-parameter \ - --with-decrypt \ - --name "$path" \ - --output text \ - --query 'Parameter.Value' -} - -function set_e2e_env_vars() { - local environment="$1" - if [ -z "$environment" ]; then - echo "usage 'set_env_vars dev|staging|production'" - exit 1 - fi - - if ! aws sts get-caller-identity > /dev/null 2>&1; then - echo "Could not access AWS resources; make sure you've assumed a role in the AWS account you're targeting." >&2 - exit 1 - fi - - export SETTINGS__FORM_IDS__S3="$(s3_form_id $environment)" - export SETTINGS__FORMS_ADMIN__URL="$(admin_url $environment)" - export SETTINGS__FORMS_ADMIN__AUTH__USERNAME="$(get_param /${environment}/automated-tests/e2e/auth0/email-username)" - export SETTINGS__FORMS_ADMIN__AUTH__PASSWORD="$(get_param /${environment}/automated-tests/e2e/auth0/auth0-user-password)" - export SETTINGS__FORMS_PRODUCT_PAGE__URL="$(product_pages_url $environment)" - export SETTINGS__FORMS_RUNNER__URL="$(runner_url $environment)" - export SETTINGS__AWS__S3_SUBMISSION_BUCKET_NAME="$(aws_s3_bucket $environment)" - export SETTINGS__AWS__S3_SUBMISSION_IAM_ROLE_ARN="$(aws_s3_role_arn $environment)" - export SETTINGS__GOVUK_NOTIFY__API_KEY="$(get_param /${environment}/automated-tests/e2e/notify/api-key)" - export SETTINGS__SUBMISSION_STATUS_API__SECRET="$(get_param /${environment}/automated-tests/e2e/runner/submission_status_api_shared_secret)" - export SETTINGS__FORMS_ENV="$environment" - export SETTINGS__GOVUK_ONE_LOGIN__USER_EMAIL="$(get_param /${environment}/automated-tests/e2e/one-login/user-email)" - export SETTINGS__GOVUK_ONE_LOGIN__USER_PASSWORD="$(get_param /${environment}/automated-tests/e2e/one-login/user-password)" - export SETTINGS__GOVUK_ONE_LOGIN__USER_OTP_SECRET_KEY="$(get_param /${environment}/automated-tests/e2e/one-login/user-otp-secret-key)" - export SETTINGS__AWS__EMAIL_RECEIVER_S3_BUCKET_NAME="$(email_receiver_s3_bucket $environment)" -} - -function set_smoke_test_env_vars() { - local environment="$1" - export SETTINGS__FORM_IDS__SMOKE_TEST="$(smoke_test_form_id "$environment")" - export SETTINGS__FORMS_ENV="$environment" -} diff --git a/bin/secrets.sh b/bin/secrets.sh new file mode 100644 index 0000000..707dd9a --- /dev/null +++ b/bin/secrets.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +function get_param() { + path="$1" + + aws ssm get-parameter \ + --with-decrypt \ + --name "$path" \ + --output text \ + --query 'Parameter.Value' +} + +function export_secrets() { + local environment="$1" + if [ -z "$environment" ]; then + echo "usage 'set_env_vars dev|staging|production'" + exit 1 + fi + + if ! aws sts get-caller-identity > /dev/null 2>&1; then + echo "Could not access AWS resources; make sure you've assumed a role in the AWS account you're targeting." >&2 + exit 1 + fi + + export SETTINGS__FORMS_ENV="$environment" + + export SETTINGS__FORMS_ADMIN__AUTH__USERNAME="$(get_param /${environment}/automated-tests/e2e/auth0/email-username)" + export SETTINGS__FORMS_ADMIN__AUTH__PASSWORD="$(get_param /${environment}/automated-tests/e2e/auth0/auth0-user-password)" + export SETTINGS__GOVUK_NOTIFY__API_KEY="$(get_param /${environment}/automated-tests/e2e/notify/api-key)" + export SETTINGS__GOVUK_ONE_LOGIN__USER_EMAIL="$(get_param /${environment}/automated-tests/e2e/one-login/user-email)" + export SETTINGS__GOVUK_ONE_LOGIN__USER_PASSWORD="$(get_param /${environment}/automated-tests/e2e/one-login/user-password)" + export SETTINGS__GOVUK_ONE_LOGIN__USER_OTP_SECRET_KEY="$(get_param /${environment}/automated-tests/e2e/one-login/user-otp-secret-key)" + export SETTINGS__SUBMISSION_STATUS_API__SECRET="$(get_param /${environment}/automated-tests/e2e/runner/submission_status_api_shared_secret)" +} diff --git a/bin/smoke_tests.sh b/bin/smoke_tests.sh index 0cf1909..29fa2cf 100755 --- a/bin/smoke_tests.sh +++ b/bin/smoke_tests.sh @@ -13,9 +13,6 @@ Usage: $0 exit 0 fi -source ./load_env_vars.sh -set_smoke_test_env_vars "$1" - cd .. bundle install