Skip to content

ABAP Unit Authority Check Test issue in Public cloud #29

Description

@Mat-Tomi

when executed in one premise system - everything is ok. 100% coverage.
when executed in public cloud system - 75% coverage, because of issue:

Test execution skipped due to missing prerequisites
Missing Prerequisites - [ABAP Authority Check] - : AUTHORITY-CHECK TEST FAILURE: Error while adding authorization of the object set:
Restricted authorizations cannot be added for the user: Authorization for Authorization object S_TABU_NAM : TABLE='ZERRCODE' ACTVT='02' for user is not configured in the system.

table definition for test (z_error_code: numc 3):
@EndUserText.label : 'Error Code ###' @AbapCatalog.enhancement.category : #NOT_EXTENSIBLE @AbapCatalog.tableCategory : #TRANSPARENT @AbapCatalog.deliveryClass : #C @AbapCatalog.dataMaintenance : #ALLOWED define table zerrcode { key client : abap.clnt not null; key error_code : z_error_code not null; configdeprecationcode : config_deprecation_code; last_changed_at : abp_lastchange_tstmpl; local_last_changed_at : abp_locinst_lastchange_tstmpl; }

Class under test:

CLASS ycl_tdf_auth DEFINITION PUBLIC FINAL CREATE PUBLIC . PUBLIC SECTION. METHODS check_auth IMPORTING is_error_code TYPE zerrcode. PROTECTED SECTION. PRIVATE SECTION. ENDCLASS. CLASS ycl_tdf_auth IMPLEMENTATION. METHOD check_auth. AUTHORITY-CHECK OBJECT 'S_TABU_NAM' ID 'TABLE' FIELD 'ZERRCODE' ID 'ACTVT' FIELD '02'. IF sy-subrc = 0. INSERT zerrcode FROM @( is_error_code ). ENDIF. ENDMETHOD. ENDCLASS.

Test class:

CLASS ltc_auth_test DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS. PRIVATE SECTION. CLASS-DATA environment TYPE REF TO if_osql_test_environment. DATA: cut TYPE REF TO ycl_tdf_auth. CLASS-METHODS: class_setup, class_teardown. METHODS: setup. METHODS: "! Test with valid error code update_auth_check_valid FOR TESTING, "! Test with invalid error code update_auth_check_invalid FOR TESTING, "! Not for testing - helper method configure_db_testdoubles. ENDCLASS. CLASS ltc_auth_test IMPLEMENTATION. METHOD update_auth_check_valid. DATA: ls_error_code TYPE zerrcode. DATA: role_authorization_stabu TYPE cl_aunit_auth_check_types_def=>role_auth_objects, controller TYPE REF TO if_aunit_auth_check_controller. role_authorization_stabu = VALUE cl_aunit_auth_check_types_def=>role_auth_objects( ( object = 'S_TABU_NAM' authorizations = VALUE #( ( VALUE #( ( fieldname = 'TABLE' fieldvalues = VALUE #( ( lower_value = 'ZERRCODE' ) ) ) ( fieldname = 'ACTVT' fieldvalues = VALUE #( ( lower_value = '02' ) ) ) ) ) ) ) ). DATA(user_role_with_authorizations) = VALUE cl_aunit_auth_check_types_def=>user_role_authorizations( ( role_authorizations = role_authorization_stabu ) ). DATA(objset_with_authorizations) = cl_aunit_authority_check=>create_auth_object_set( user_role_with_authorizations ). controller = cl_aunit_authority_check=>get_controller( ). controller->restrict_authorizations_to( objset_with_authorizations ). ls_error_code = VALUE #( client = '001' error_code = '123' configdeprecationcode = ' ' ). cut->check_auth( is_error_code = ls_error_code ). SELECT SINGLE * FROM zerrcode WHERE error_code = @ls_error_code-error_code INTO @DATA(ls_record). cl_abap_unit_assert=>assert_initial( ). cl_abap_unit_assert=>assert_not_initial( act = ls_record ). controller->get_auth_check_execution_log( )->get_execution_status( IMPORTING failed_execution = DATA(failed_execution) passed_execution = DATA(passed_execution) ). cl_abap_unit_assert=>assert_not_initial( act = passed_execution ). cl_abap_unit_assert=>assert_initial( act = failed_execution ). ENDMETHOD. METHOD update_auth_check_invalid. DATA: ls_error_code TYPE zerrcode. DATA: role_authorization_stabu TYPE cl_aunit_auth_check_types_def=>role_auth_objects, controller TYPE REF TO if_aunit_auth_check_controller. " Simulate no authorization scenario role_authorization_stabu = VALUE cl_aunit_auth_check_types_def=>role_auth_objects( ). DATA(user_role_without_auth) = VALUE cl_aunit_auth_check_types_def=>user_role_authorizations( ( role_authorizations = role_authorization_stabu ) ). DATA(objset_without_authorizations) = cl_aunit_authority_check=>create_auth_object_set( user_role_without_auth ). controller = cl_aunit_authority_check=>get_controller( ). controller->restrict_authorizations_to( objset_without_authorizations ). ls_error_code = VALUE #( client = '001' error_code = '123' configdeprecationcode = ' ' ). cut->check_auth( is_error_code = ls_error_code ). SELECT SINGLE * FROM zerrcode WHERE error_code = @ls_error_code-error_code INTO @DATA(ls_record). cl_abap_unit_assert=>assert_initial( act = ls_record ). " Expect no change to database controller->get_auth_check_execution_log( )->get_execution_status( IMPORTING failed_execution = DATA(failed_execution) passed_execution = DATA(passed_execution) ). cl_abap_unit_assert=>assert_initial( act = passed_execution ). " No actions should have passed cl_abap_unit_assert=>assert_not_initial( act = failed_execution ). " Authorization check should fail ENDMETHOD. METHOD setup. cut = NEW ycl_tdf_auth( ). environment->clear_doubles( ). ENDMETHOD. METHOD class_setup. environment = cl_osql_test_environment=>create( i_dependency_list = VALUE #( ( 'zerrcode' ) ) ). ENDMETHOD. METHOD class_teardown. environment->destroy( ). ENDMETHOD. METHOD configure_db_testdoubles. DATA error_code_stub_data TYPE STANDARD TABLE OF zerrcode. error_code_stub_data = VALUE #( ( client = '001' error_code = '100' ) ( client = '001' error_code = '999' ) ). environment->insert_test_data( error_code_stub_data ). ENDMETHOD. ENDCLASS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions