Skip to content

Commit

Permalink
test(sqltest): Fix tests due to new auth_token insert trigger
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tmessi committed Feb 23, 2024
1 parent 9e0d96b commit 9514a76
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 214 deletions.
12 changes: 6 additions & 6 deletions internal/db/sqltest/initdb.d/01_colors_persona.sql
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ begin;
('p____gcolors', 'hc__st_____g', 'Green Color Static Catalog');

insert into auth_token
(key_id, auth_account_id, public_id, token)
(key_id, auth_account_id, public_id, token, expiration_time, status)
values
('kdkv__colors', 'apa____clare', 'tok____clare', 'tok____clare'::bytea),
('kdkv__colors', 'apa____cindy', 'tok____cindy', 'tok____cindy'::bytea),
('kdkv__colors', 'apa____ciara', 'tok____ciara', 'tok____ciara'::bytea),
('kdkv__colors', 'apa____carly', 'tok____carly', 'tok____carly'::bytea),
('kdkv__colors', 'apa_____cora', 'tok_____cora', 'tok_____cora'::bytea);
('kdkv__colors', 'apa____clare', 'tok____clare', 'tok____clare'::bytea, now() + interval '15 days', 'token issued'),
('kdkv__colors', 'apa____cindy', 'tok____cindy', 'tok____cindy'::bytea, now() + interval '15 days', 'token issued'),
('kdkv__colors', 'apa____ciara', 'tok____ciara', 'tok____ciara'::bytea, now() + interval '15 days', 'auth token pending'),
('kdkv__colors', 'apa____carly', 'tok____carly', 'tok____carly'::bytea, now() + interval '15 days', 'token issued'),
('kdkv__colors', 'apa_____cora', 'tok_____cora', 'tok_____cora'::bytea, now() + interval '15 days', 'auth token pending');

insert into static_host
(catalog_id, public_id, address)
Expand Down
16 changes: 8 additions & 8 deletions internal/db/sqltest/initdb.d/03_widgets_persona.sql
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ begin;
(key_id, table_name, total_count)
values
('kdkv___widget', 'auth_token', 100);

end;
$$ language plpgsql;

Expand Down Expand Up @@ -172,13 +172,13 @@ begin;
update auth_account set iam_user_id = 'u_____wilson' where public_id = 'apa___wilson';

insert into auth_token
(key_id, auth_account_id, public_id, token)
(key_id, auth_account_id, public_id, token, expiration_time, status)
values
('kdkv___widget', 'apa___walter', 'tok___walter', 'tok___walter'::bytea),
('kdkv___widget', 'apa1__walter', 'tok1__walter', 'tok1__walter'::bytea),
('kdkv___widget', 'apa___warren', 'tok___warren', 'tok___warren'::bytea),
('kdkv___widget', 'apa___waylon', 'tok___waylon', 'tok___waylon'::bytea),
('kdkv___widget', 'apa___wilson', 'tok___wilson', 'tok___wilson'::bytea);
('kdkv___widget', 'apa___walter', 'tok___walter', 'tok___walter'::bytea, now() + interval '15 days', 'token issued'),
('kdkv___widget', 'apa1__walter', 'tok1__walter', 'tok1__walter'::bytea, now() + interval '15 days', 'token issued'),
('kdkv___widget', 'apa___warren', 'tok___warren', 'tok___warren'::bytea, now() + interval '15 days', 'token issued'),
('kdkv___widget', 'apa___waylon', 'tok___waylon', 'tok___waylon'::bytea, now() + interval '15 days', 'token issued'),
('kdkv___widget', 'apa___wilson', 'tok___wilson', 'tok___wilson'::bytea, now() + interval '15 days', 'auth token pending');

insert into auth_oidc_method
(scope_id, public_id, client_id, name, state, key_id, issuer)
Expand Down Expand Up @@ -206,7 +206,7 @@ begin;
('o_____widget', 'alm___widget', 'Widget LDAP', 'active-private');
insert into auth_ldap_url
(ldap_method_id, url, connection_priority)
values
values
('alm___widget', 'ldaps://ldap1', 1);

insert into auth_ldap_account
Expand Down
6 changes: 3 additions & 3 deletions internal/db/sqltest/tests/wh/upsert_user/insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ begin;
select wtt_load('widgets', 'iam', 'kms', 'auth', 'hosts', 'targets');

-- ensure no existing dimensions
select is(count(*), 0::bigint) from wh_user_dimension where user_id = 'u_____walter';
select is(count(*), 0::bigint) from wh_user_dimension where user_id = 'u_____wilson';

select lives_ok($$select wh_upsert_user('u_____walter', 'tok___walter')$$);
select lives_ok($$select wh_upsert_user('tok___wilson')$$);

-- upsert should insert a user_dimension
select is(count(*), 1::bigint) from wh_user_dimension where user_id = 'u_____walter';
select is(count(*), 1::bigint) from wh_user_dimension where user_id = 'u_____wilson';

select * from finish();
rollback;
12 changes: 6 additions & 6 deletions internal/db/sqltest/tests/wh/upsert_user/upsert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ begin;
select wtt_load('widgets', 'iam', 'kms', 'auth', 'hosts', 'targets');

-- ensure no existing dimensions
select is(count(*), 0::bigint) from wh_user_dimension where user_id = 'u_____walter';
select is(count(*), 0::bigint) from wh_user_dimension where user_id = 'u_____wilson';

insert into wh_user_dimension
(
Expand All @@ -25,20 +25,20 @@ begin;
values
(
'wud_____1',
'u_____walter', 'Walter', 'This is Walter',
'apa___walter', 'password auth account', 'walter', 'Account for Walter',
'u_____wilson', 'Wilson', 'This is Wilson',
'apa___wilson', 'password auth account', 'wilson', 'Account for Wilson',
'None', 'None', 'None',
'apm___widget', 'password auth method', 'Widget Auth Password', 'None',
'None',
'o_____widget', 'Widget Inc', 'None',
'Current', '2021-07-21T12:01'::timestamptz, 'infinity'::timestamptz
);

select lives_ok($$select wh_upsert_user('u_____walter', 'tok___walter')$$);
select lives_ok($$select wh_upsert_user('tok___wilson')$$);

-- upsert should insert a user_dimension
select is(count(*), 2::bigint) from wh_user_dimension where user_id = 'u_____walter';
select is(count(*), 1::bigint) from wh_user_dimension where user_id = 'u_____walter' and current_row_indicator = 'Current';
select is(count(*), 2::bigint) from wh_user_dimension where user_id = 'u_____wilson';
select is(count(*), 1::bigint) from wh_user_dimension where user_id = 'u_____wilson' and current_row_indicator = 'Current';

select * from finish();
rollback;
Loading

0 comments on commit 9514a76

Please sign in to comment.