Files
threshold/internal/db/sqltest/tests/wh/user_dimension/session_update.sql
T
Timothy Messier 9514a76289 test(sqltest): Fix tests due to new auth_token insert trigger
With the addition of an after insert trigger to the auth_token table,
entries are added to the wh_user_dimension table when auth token's are
inserted with the 'token issued' status. This caused a number of tests
to fail that assumed the user dimension table would be empty prior to
inserting sessions. This introduces a number of changes to the tests:

- In the test setup, auth tokens are not created with an explicit
  expiration time and status. The expiration time ensures that the
  tokens are 'valid' for the test. The status allows test to make
  assertions on tokens in different statuses, and allow the status to
  change during the test.
- Tests make the correct assertions on the number of entries in the user
  dimension table after test setup.
- User dimension tests modify a user after the standard setup to ensure
  that a new user dimension is added when a session is inserted.
2024-02-23 15:44:08 +00:00

42 lines
1.2 KiB
PL/PgSQL

-- Copyright (c) HashiCorp, Inc.
-- SPDX-License-Identifier: BUSL-1.1
-- session_update tests the wh_user_dimesion when
-- a session is inserted and then updated.
begin;
select plan(3);
select wtt_load('widgets', 'iam', 'kms', 'auth', 'hosts', 'targets');
-- existing dimension via auth tokens
select is(count(*), 4::bigint)
from wh_user_dimension
where user_id = 'u_____walter';
-- insert first session, should result in a new user dimension
insert into session
( project_id , target_id , user_id , auth_token_id , certificate , endpoint , public_id)
values
('p____bwidget' , 't_________wb' , 'u_____walter' , 'tok___walter' , 'abc'::bytea , 'ep1' , 's1____walter');
insert into session_host_set_host
(session_id, host_set_id, host_id)
values
('s1____walter', 's___1wb-sths', 'h_____wb__01');
select is(count(*), 4::bigint)
from wh_user_dimension
where user_id = 'u_____walter';
-- update session, should not impact wh_user_dimension
update session set
version = 2
where
public_id = 's1____walter';
select is(count(*), 4::bigint)
from wh_user_dimension
where user_id = 'u_____walter';
select * from finish();
rollback;