test(sql) add tests to validate project scope for target_static_credential

This commit is contained in:
Damian Debkowski authored and Damian Debkowski committed 2022-08-22 12:15:20 -07:00
1 parent a56d7aa4d0
commit c4aa9a0358
2 files changed
+56

No files matched your search

@@ -404,6 +404,18 @@ begin;
('t_________wb', 'vl______wvl2', 'brokered'),
('t_________wb', 'vl______wvl3', 'brokered'),
('t_________wb', 'vl______wvl3', 'injected_application');
insert into credential_static_store
(scope_id, public_id, name, description)
values
('p____bwidget', 'cs______wup1', 'widget static store', 'None'),
('p____swidget', 'cs______wup2', 'widget static store', 'None');
insert into credential_static_username_password_credential
(store_id, public_id, name, description, username, password_encrypted, password_hmac, key_id)
values
('cs______wup1', 'cred____wup1', 'widget static username password credential', 'None', 'b_user', 'encrypted_password', 'hmac-value', 'kdkv___widget'),
('cs______wup2', 'cred____wup2', 'widget static username password credential', 'None', 's_user', 'encrypted_password', 'hmac-value', 'kdkv___widget');
end;
$$ language plpgsql;
@@ -0,0 +1,44 @@
begin;
select plan(3);
select wtt_load('widgets', 'iam', 'kms', 'auth', 'hosts', 'targets', 'credentials');
-- validate the setup data
select is(count(*), 1::bigint)
from credential_static cred
join credential_store cs on cred.store_id = cs.public_id
where cs.scope_id = 'p____bwidget'
and cs.public_id = 'cs______wup1'
and cred.public_id = 'cred____wup1';
insert into target
(scope_id, public_id)
values
('p____bwidget', 'test______wb');
prepare insert_valid_target_static_credential as
insert into target_static_credential
(target_id, credential_static_id, credential_purpose)
values
('test______wb', 'cred____wup1', 'application');
select lives_ok('insert_valid_target_static_credential', 'insert valid target_static_credential failed');
-- create a credential_static_store and target in a different project
insert into credential_static_store
(scope_id, public_id, name, description)
values
('p____swidget', 'test______cs', 'test static store', 'None');
insert into credential_static_username_password_credential
(store_id, public_id, name, description, username, password_encrypted, password_hmac, key_id)
values
('test______cs', 'test____cred', 'test static username password credential', 'None', 'b_user', 'encrypted_password', 'hmac-value', 'kdkv___widget');
prepare insert_invalid_target_static_credential as
insert into target_static_credential
(target_id, credential_static_id, credential_purpose)
values
('test______wb', 'test____cred', 'application');
select throws_ok('insert_invalid_target_static_credential', '23000', null, 'insert invalid target_credential_library succeeded');
select * from finish();
rollback;