github.com/letsencrypt/boulder@v0.20251208.0/test/vtcomboserver/install_trigger.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  #
     4  # Note: This script exists to support the integration test at
     5  # test/integration/cert_storage_failed_test.go. Because Vitess doesn’t support
     6  # creating triggers through normal SQL, this script waits for the Vitess
     7  # database to come up and then installs a trigger that simulates an error when
     8  # inserting into the certificates table under a specific condition.
     9  #
    10  
    11  set -eu
    12  
    13  VT_DB="vt_${MYSQL_DATABASE:-boulder_sa_integration}_0"
    14  SOCK="/vt/vtdataroot/vt_0000000001/mysql.sock"
    15  MYSQL_ARGS=(-uroot -S "$SOCK")
    16  TIMEOUT=120
    17  
    18  #
    19  # Helpers
    20  #
    21  
    22  exit_msg() {
    23    echo "$*" >&2
    24    exit 2
    25  }
    26  
    27  table_exists() {
    28    local result
    29    result="$(mysql "${MYSQL_ARGS[@]}" -Nse \
    30      "SELECT 1 FROM information_schema.tables WHERE table_schema='${VT_DB}' AND table_name='certificates' LIMIT 1" \
    31      || true)"
    32    [ "$result" = "1" ]
    33  }
    34  
    35  # Wait for the certificates table to be created
    36  printf '[install_trigger] waiting for %s.certificates to appear...\n' "$VT_DB"
    37  
    38  i=0
    39  while [ "$i" -lt "$TIMEOUT" ]
    40  do
    41    if table_exists
    42    then
    43      break
    44    fi
    45    sleep 1
    46    i=$((i+1))
    47  done
    48  
    49  if ! table_exists
    50  then
    51    exit_msg "[install_trigger] ERROR: ${VT_DB}.certificates not found after ${TIMEOUT}s"
    52  fi
    53  
    54  # Install trigger that simulates an error when inserting into the certificates
    55  # table for TestIssuanceCertStorageFailed in /test/integration/cert_storage_failed_test.go.
    56  printf '[install_trigger] installing trigger on %s.certificates\n' "$VT_DB"
    57  mysql "${MYSQL_ARGS[@]}" "$VT_DB" <<'SQL'
    58  DELIMITER $$
    59  DROP TRIGGER IF EXISTS fail_ready $$
    60  CREATE TRIGGER fail_ready
    61  BEFORE INSERT ON certificates
    62  FOR EACH ROW
    63  BEGIN
    64    DECLARE reversedName1 VARCHAR(255);
    65    SELECT reversedName INTO reversedName1
    66      FROM issuedNames
    67      WHERE serial = NEW.serial
    68        AND reversedName LIKE 'com.wantserror.%';
    69    IF reversedName1 IS NOT NULL AND reversedName1 != '' THEN
    70      SIGNAL SQLSTATE '45000'
    71        SET MESSAGE_TEXT = 'Pretend there was an error inserting into certificates';
    72    END IF;
    73  END $$
    74  DELIMITER ;
    75  SQL
    76  
    77  printf '[install_trigger] done\n'