2023-02-02 17:15:17 -08:00
|
|
|
-- Copyright (c) HashiCorp, Inc.
|
2022-07-20 16:24:46 -07:00
|
|
|
-- SPDX-License-Identifier: BUSL-1.1
|
2023-02-02 17:15:17 -08:00
|
|
|
|
2022-06-15 15:14:16 -07:00
|
|
|
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
|
2022-07-20 16:24:46 -07:00
|
|
|
where cs.project_id = 'p____bwidget'
|
2022-06-15 15:14:16 -07:00
|
|
|
and cs.public_id = 'cs______wup1'
|
|
|
|
|
and cred.public_id = 'cred____wup1';
|
|
|
|
|
|
|
|
|
|
insert into target
|
2022-07-20 16:24:46 -07:00
|
|
|
(project_id, public_id)
|
2022-06-15 15:14:16 -07:00
|
|
|
values
|
|
|
|
|
('p____bwidget', 'test______wb');
|
|
|
|
|
|
|
|
|
|
prepare insert_valid_target_static_credential as
|
|
|
|
|
insert into target_static_credential
|
2022-07-20 16:24:46 -07:00
|
|
|
(project_id, target_id, credential_static_id, credential_purpose)
|
2022-06-15 15:14:16 -07:00
|
|
|
values
|
2022-09-16 15:00:04 -07:00
|
|
|
('p____bwidget', 'test______wb', 'cred____wup1', 'brokered'),
|
|
|
|
|
('p____bwidget', 'test______wb', 'cred____wjson1', 'brokered');
|
2022-06-15 15:14:16 -07:00
|
|
|
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
|
2022-07-20 16:24:46 -07:00
|
|
|
(project_id, public_id, name, description)
|
2022-06-15 15:14:16 -07:00
|
|
|
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
|
2022-07-20 16:24:46 -07:00
|
|
|
(project_id, target_id, credential_static_id, credential_purpose)
|
2022-06-15 15:14:16 -07:00
|
|
|
values
|
2022-07-20 16:24:46 -07:00
|
|
|
('p____bwidget', 'test______wb', 'test____cred', 'brokered');
|
|
|
|
|
select throws_ok('insert_invalid_target_static_credential', '23503', null, 'insert invalid target_credential_library succeeded');
|
2022-06-15 15:14:16 -07:00
|
|
|
|
|
|
|
|
select * from finish();
|
|
|
|
|
rollback;
|