From 0512ddb060dd4f7c6677568f2faf7349f212f36c Mon Sep 17 00:00:00 2001 From: Michael Gaffney Date: Fri, 10 Jun 2022 13:45:53 -0400 Subject: [PATCH] test(db): Add tests for inserts into target_credential_library --- .../target/target_credential_library.sql | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 internal/db/sqltest/tests/target/target_credential_library.sql diff --git a/internal/db/sqltest/tests/target/target_credential_library.sql b/internal/db/sqltest/tests/target/target_credential_library.sql new file mode 100644 index 000000000..58c824091 --- /dev/null +++ b/internal/db/sqltest/tests/target/target_credential_library.sql @@ -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_library cl + join credential_store cs on cl.store_id = cs.public_id + where cs.scope_id = 'p____bwidget' + and cs.public_id = 'vs_______wvs' + and cl.public_id = 'vl______wvl1'; + + insert into target + (scope_id, public_id) + values + ('p____bwidget', 'test______wb'); + + prepare insert_valid_target_credential_library as + insert into target_credential_library + (target_id, credential_library_id, credential_purpose) + values + ('test______wb', 'vl______wvl1', 'application'); + select lives_ok('insert_valid_target_credential_library', 'insert valid target_credential_library failed'); + + -- create a credential_store and credential_library in a different project + insert into credential_store + (scope_id, public_id) + values + ('p____swidget', 'test______cs'); + + insert into credential_library + (store_id, public_id, credential_type) + values + ('test______cs', 'test______cl', 'unspecified'); + + prepare insert_invalid_target_credential_library as + insert into target_credential_library + (target_id, credential_library_id, credential_purpose) + values + ('test______wb', 'test______cl', 'application'); + select throws_ok('insert_invalid_target_credential_library', '23000', null, 'insert invalid target_credential_library succeeded'); + + select * from finish(); +rollback;