Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc5f305

Browse files
authored
Merge pull request #600 from utPLSQL/feature/fix_dbms_crypto_privs_requirements
Fixed bad placement of calls to dbms_crypto.
2 parents 40af4e7 + df5063d commit fc5f305

8 files changed

Lines changed: 48 additions & 24 deletions

.travis/install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ set feedback off
3232
set feedback on
3333
--Needed for testing coverage outside of main UT3 schema.
3434
grant create any procedure, drop any procedure, execute any procedure, create any type, drop any type, execute any type, under any type, select any table, update any table, insert any table, delete any table, create any table, drop any table, alter any table, select any dictionary to $UT3_TESTER;
35+
revoke execute on dbms_crypto from $UT3_TESTER;
3536
exit
3637
SQL

source/expectations/data_values/ut_compound_data_diff_tmp.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ create global temporary table ut_compound_data_diff_tmp(
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
15-
diff_id raw(16),
15+
diff_id raw(128),
1616
item_no integer,
1717
constraint ut_compound_data_diff_tmp_pk primary key(diff_id,item_no)
1818
) on commit preserve rows;

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,33 @@ create or replace package body ut_compound_data_helper is
216216
return l_results;
217217
end;
218218

219+
function get_hash(a_data raw, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash is
220+
begin
221+
return dbms_crypto.hash(a_data, a_hash_type);
222+
end;
223+
224+
function get_hash(a_data clob, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash is
225+
begin
226+
return dbms_crypto.hash(a_data, a_hash_type);
227+
end;
228+
229+
function columns_hash(
230+
a_data_value_cursor ut_data_value_refcursor, a_exclude_xpath varchar2, a_include_xpath varchar2,
231+
a_hash_type binary_integer := dbms_crypto.hash_sh1
232+
) return t_hash is
233+
l_cols_hash t_hash;
234+
begin
235+
if not a_data_value_cursor.is_null then
236+
execute immediate
237+
q'[select dbms_crypto.hash(replace(x.item_data.getclobval(),'>CHAR<','>VARCHAR2<'),]'||a_hash_type||') ' ||
238+
' from ( select '||get_columns_filter(a_exclude_xpath, a_include_xpath)||
239+
' from (select :columns_info as item_data from dual ) ucd' ||
240+
' ) x'
241+
into l_cols_hash using a_exclude_xpath, a_include_xpath, a_data_value_cursor.columns_info;
242+
end if;
243+
return l_cols_hash;
244+
end;
245+
219246
begin
220247
g_type_name_map( dbms_sql.binary_bouble_type ) := 'BINARY_DOUBLE';
221248
g_type_name_map( dbms_sql.bfile_type ) := 'BFILE';

source/expectations/data_values/ut_compound_data_helper.pks

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,14 @@ create or replace package ut_compound_data_helper authid definer is
5252
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2
5353
) return tt_row_diffs;
5454

55+
subtype t_hash is raw(128);
56+
57+
function get_hash(a_data raw, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash;
58+
function get_hash(a_data clob, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash;
59+
function columns_hash(
60+
a_data_value_cursor ut_data_value_refcursor, a_exclude_xpath varchar2, a_include_xpath varchar2,
61+
a_hash_type binary_integer := dbms_crypto.hash_sh1
62+
) return t_hash;
63+
5564
end;
5665
/

source/expectations/data_values/ut_compound_data_tmp.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ create global temporary table ut_compound_data_tmp(
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
15-
data_id raw(16),
15+
data_id raw(32),
1616
item_no integer,
1717
item_data xmltype,
1818
constraint ut_compound_data_tmp_pk primary key(data_id, item_no)

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ create or replace type body ut_compound_data_value as
8989
l_ut_owner varchar2(250) := ut_utils.ut_owner;
9090
l_diff_row_count integer;
9191
l_actual ut_compound_data_value;
92-
l_diff_id raw(16);
92+
l_diff_id ut_compound_data_helper.t_hash;
9393
l_row_diffs ut_compound_data_helper.tt_row_diffs;
9494
begin
9595
if not a_other is of (ut_compound_data_value) then
@@ -100,7 +100,7 @@ create or replace type body ut_compound_data_value as
100100
dbms_lob.createtemporary(l_result,true);
101101

102102
--diff rows and row elements
103-
l_diff_id := dbms_crypto.hash(self.data_id||l_actual.data_id,2);
103+
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_actual.data_id);
104104
-- First tell how many rows are different
105105
execute immediate 'select count(*) from ' || l_ut_owner || '.ut_compound_data_diff_tmp where diff_id = :diff_id' into l_diff_row_count using l_diff_id;
106106

@@ -128,7 +128,7 @@ create or replace type body ut_compound_data_value as
128128
l_other ut_compound_data_value;
129129
l_ut_owner varchar2(250) := ut_utils.ut_owner;
130130
l_column_filter varchar2(32767);
131-
l_diff_id raw(16);
131+
l_diff_id ut_compound_data_helper.t_hash;
132132
l_result integer;
133133
--the XML stylesheet is applied on XML representation of data to exclude column names from comparison
134134
--column names and data-types are compared separately
@@ -152,7 +152,7 @@ create or replace type body ut_compound_data_value as
152152

153153
l_other := treat(a_other as ut_compound_data_value);
154154

155-
l_diff_id := dbms_crypto.hash(self.data_id||l_other.data_id,2);
155+
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_other.data_id);
156156
l_column_filter := ut_compound_data_helper.get_columns_filter(a_exclude_xpath, a_include_xpath);
157157
-- Find differences
158158
execute immediate 'insert into ' || l_ut_owner || '.ut_compound_data_diff_tmp ( diff_id, item_no )

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,6 @@ create or replace type body ut_data_value_refcursor as
186186
overriding member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer is
187187
l_result integer := 0;
188188
l_other ut_data_value_refcursor;
189-
function columns_hash(
190-
a_data_value_cursor ut_data_value_refcursor, a_exclude_xpath varchar2, a_include_xpath varchar2
191-
) return raw is
192-
l_cols_hash raw(32);
193-
begin
194-
if not a_data_value_cursor.is_null then
195-
execute immediate
196-
q'[select dbms_crypto.hash(replace(x.item_data.getclobval(),'>CHAR<','>VARCHAR2<'),3) ]' ||
197-
' from ( select '||ut_compound_data_helper.get_columns_filter(a_exclude_xpath, a_include_xpath)||
198-
' from (select :columns_info as item_data from dual ) ucd' ||
199-
' ) x'
200-
into l_cols_hash using a_exclude_xpath, a_include_xpath, a_data_value_cursor.columns_info;
201-
end if;
202-
return l_cols_hash;
203-
end;
204189
begin
205190
if not a_other is of (ut_data_value_refcursor) then
206191
raise value_error;
@@ -209,7 +194,9 @@ create or replace type body ut_data_value_refcursor as
209194
l_other := treat(a_other as ut_data_value_refcursor);
210195

211196
--if column names/types are not equal - build a diff of column names and types
212-
if columns_hash( self, a_exclude_xpath, a_include_xpath ) != columns_hash( l_other, a_exclude_xpath, a_include_xpath ) then
197+
if ut_compound_data_helper.columns_hash( self, a_exclude_xpath, a_include_xpath )
198+
!= ut_compound_data_helper.columns_hash( l_other, a_exclude_xpath, a_include_xpath )
199+
then
213200
l_result := 1;
214201
end if;
215202
l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath);

source/install.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,9 @@ prompt Installing PLSQL profiler objects into &&ut3_owner schema
141141
--expectations and matchers
142142
@@install_component.sql 'expectations/data_values/ut_compound_data_tmp.sql'
143143
@@install_component.sql 'expectations/data_values/ut_compound_data_diff_tmp.sql'
144-
@@install_component.sql 'expectations/data_values/ut_compound_data_helper.pks'
145-
@@install_component.sql 'expectations/data_values/ut_compound_data_helper.pkb'
146144
@@install_component.sql 'expectations/data_values/ut_data_value.tps'
147145
@@install_component.sql 'expectations/data_values/ut_compound_data_value.tps'
146+
@@install_component.sql 'expectations/data_values/ut_compound_data_helper.pks'
148147
@@install_component.sql 'expectations/data_values/ut_data_value_anydata.tps'
149148
@@install_component.sql 'expectations/data_values/ut_data_value_collection.tps'
150149
@@install_component.sql 'expectations/data_values/ut_data_value_object.tps'
@@ -180,6 +179,7 @@ prompt Installing PLSQL profiler objects into &&ut3_owner schema
180179
@@install_component.sql 'expectations/ut_expectation_compound.tps'
181180
@@install_component.sql 'expectations/data_values/ut_data_value.tpb'
182181
@@install_component.sql 'expectations/data_values/ut_compound_data_value.tpb'
182+
@@install_component.sql 'expectations/data_values/ut_compound_data_helper.pkb'
183183
@@install_component.sql 'expectations/data_values/ut_data_value_anydata.tpb'
184184
@@install_component.sql 'expectations/data_values/ut_data_value_object.tpb'
185185
@@install_component.sql 'expectations/data_values/ut_data_value_collection.tpb'

0 commit comments

Comments
 (0)