Files
threshold/internal/db/sqltest/tests/session/delete_session_host.sql
T
Michael Gaffney 477e6df269 feat(sql): Add target and host history tables to session recording
This adds four columns to the `recording_session` table which are
foreign keys to the `iam_scope_hst`, `target_ssh_hst`,
`host_history_base`, and `host_catalog_history_base` tables. The foreign
key to the `iam_scope_hst` table references the project scope of the
target at the time of the recording.
2023-05-31 12:18:17 +00:00

29 lines
1.3 KiB
PL/PgSQL

-- Copyright (c) HashiCorp, Inc.
-- SPDX-License-Identifier: MPL-2.0
begin;
select plan(9);
-- Ensure session state table is populated
select is(count(*), 1::bigint) from session_state where session_id = 's1_____clare' and state='pending';
select is(count(*), 1::bigint) from session_state where session_id = 's1_____cindy' and state='terminated';
select is(count(*), 1::bigint) from session_state where session_id = 's1_____ciara' and state='canceling';
select is(count(*), 1::bigint) from session_state where session_id = 's1_____carly' and state='active';
-- Check that we have 5 sessions using this host
select is(count(*), 5::bigint) from session_host_set_host where host_id = 'h_____cb__01';
-- Delete host, expect no errors
delete from host where public_id = 'h_____cb__01';
select is(count(*), 0::bigint) from host where public_id = 'h_____cb__01';
-- Ensure we no longer have sessions associated with this host
select is(count(*), 0::bigint) from session_host_set_host where host_id = 'h_____cb__01';
-- Ensure sessions that were pending or active are now in canceling state
select is(count(*), 1::bigint) from session_state where state = 'canceling' and session_id = 's1_____clare';
select is(count(*), 1::bigint) from session_state where state = 'canceling' and session_id = 's1_____carly';
select * from finish();
rollback;