|
| 1 | +#!/usr/bin/env bash |
| 2 | +bash -n "$0" | exit 1 |
| 3 | + |
| 4 | +# Verify that cdb2_sqlreplay skips 'PUT TUNABLE externalauth' by default, and |
| 5 | +# replays it when --replay-externalauth is given. We assert on the tool's own |
| 6 | +# (verbose) behavior rather than flipping externalauth on a live db, since |
| 7 | +# enabling externalauth can break connectivity for a db with no auth backend. |
| 8 | + |
| 9 | +source ${TESTSROOTDIR}/tools/runit_common.sh |
| 10 | + |
| 11 | +CDB2_SQLREPLAY_EXE=${CDB2_SQLREPLAY_EXE:-${BUILDDIR}/tools/cdb2_sqlreplay/cdb2_sqlreplay} |
| 12 | + |
| 13 | +cdb2sql ${CDB2_OPTIONS} ${DBNAME} default "create table t1 { schema { int id } }" |
| 14 | + |
| 15 | +# Build a replay log. Each line is one JSON event as emitted by the event |
| 16 | +# logger. We interleave marker inserts with several 'put tunable externalauth' |
| 17 | +# variants (quoted, uppercase) plus a similarly-named tunable that must NOT be |
| 18 | +# skipped (externalauth_warn). |
| 19 | +cat > replay.log <<'EOF' |
| 20 | +{"type":"sql","time":1,"sql":"insert into t1(id) values(1)"} |
| 21 | +{"type":"sql","time":2,"sql":"put tunable externalauth 'off'"} |
| 22 | +{"type":"sql","time":3,"sql":"PUT TUNABLE externalauth 'off'"} |
| 23 | +{"type":"sql","time":4,"sql":"put tunable externalauth_warn 'off'"} |
| 24 | +{"type":"sql","time":5,"sql":"insert into t1(id) values(2)"} |
| 25 | +EOF |
| 26 | + |
| 27 | +######################################################################## |
| 28 | +# Default behavior: externalauth statements are skipped. |
| 29 | +######################################################################## |
| 30 | +echo "=== default replay (externalauth should be skipped) ===" |
| 31 | +${CDB2_SQLREPLAY_EXE} --verbose ${DBNAME} replay.log > default.out 2>&1 |
| 32 | +cat default.out |
| 33 | + |
| 34 | +# Both externalauth variants must be skipped ... |
| 35 | +skipped=$(grep -c "^skipping.*externalauth" default.out) |
| 36 | +assertres $skipped 2 |
| 37 | + |
| 38 | +# ... and the executed (bare) sql line for them must be absent. |
| 39 | +ran=$(grep -c "^put tunable externalauth 'off'$" default.out) |
| 40 | +assertres $ran 0 |
| 41 | +ran=$(grep -c "^PUT TUNABLE externalauth 'off'$" default.out) |
| 42 | +assertres $ran 0 |
| 43 | + |
| 44 | +# The lookalike tunable must NOT be skipped. |
| 45 | +skippedwarn=$(grep -c "skipping.*externalauth_warn" default.out) |
| 46 | +assertres $skippedwarn 0 |
| 47 | + |
| 48 | +# Replay must continue past the skipped statements: both markers inserted. |
| 49 | +cnt=$(cdb2sql --tabs ${CDB2_OPTIONS} ${DBNAME} default "select count(*) from t1") |
| 50 | +assertres $cnt 2 |
| 51 | + |
| 52 | +######################################################################## |
| 53 | +# --replay-externalauth: externalauth statements are replayed. |
| 54 | +######################################################################## |
| 55 | +cdb2sql ${CDB2_OPTIONS} ${DBNAME} default "truncate t1" |
| 56 | + |
| 57 | +echo "=== replay with --replay-externalauth (externalauth should run) ===" |
| 58 | +${CDB2_SQLREPLAY_EXE} --verbose --replay-externalauth ${DBNAME} replay.log > allow.out 2>&1 |
| 59 | +cat allow.out |
| 60 | + |
| 61 | +# Nothing should be skipped now. |
| 62 | +skipped=$(grep -c "^skipping" allow.out) |
| 63 | +assertres $skipped 0 |
| 64 | + |
| 65 | +# The externalauth statements must actually be handed to the server (verbose |
| 66 | +# prints the bare sql line right before running it). |
| 67 | +ran=$(grep -c "^put tunable externalauth 'off'$" allow.out) |
| 68 | +assertres $ran 1 |
| 69 | +ran=$(grep -c "^PUT TUNABLE externalauth 'off'$" allow.out) |
| 70 | +assertres $ran 1 |
| 71 | + |
| 72 | +# Every replayed statement (including externalauth) executed without error. |
| 73 | +errs=$(grep -c "Error: run rc" allow.out) |
| 74 | +assertres $errs 0 |
| 75 | + |
| 76 | +# Connection stays healthy and markers still replay. |
| 77 | +cnt=$(cdb2sql --tabs ${CDB2_OPTIONS} ${DBNAME} default "select count(*) from t1") |
| 78 | +assertres $cnt 2 |
| 79 | + |
| 80 | +echo "Success" |
| 81 | +exit 0 |
0 commit comments