@@ -469,6 +469,8 @@ def patcher
469469 end
470470
471471 describe 'track_user_events' do
472+ before { allow ( Datadog ) . to receive ( :logger ) . and_return ( spy ( Datadog ::Core ::Logger ) ) }
473+
472474 describe '#enabled' do
473475 subject ( :enabled ) { settings . appsec . track_user_events . enabled }
474476
@@ -479,6 +481,17 @@ def patcher
479481 end
480482 end
481483
484+ context 'when deprication message should be emitted' do
485+ let ( :track_user_events_enabled ) { 'true' }
486+
487+ it 'writes the deprication message' do
488+ expect ( Datadog ::Core ) . to receive ( :log_deprecation ) do |_ , &block |
489+ expect ( block . call ) . to match ( /setting has been deprecated for removal/ )
490+ end
491+ expect ( enabled ) . to eq ( true )
492+ end
493+ end
494+
482495 context 'is not defined' do
483496 let ( :track_user_events_enabled ) { nil }
484497
@@ -562,6 +575,18 @@ def patcher
562575 settings . appsec . track_user_events . mode = track_user_events_mode
563576 end
564577
578+ context 'when deprication message should be emitted' do
579+ let ( :track_user_events_mode ) { 'extended' }
580+
581+ it 'writes the deprication message' do
582+ expect ( Datadog ::Core ) . to receive ( :log_deprecation ) do |_ , &block |
583+ expect ( block . call ) . to match ( /setting has been deprecated for removal/ )
584+ end
585+
586+ set_appsec_track_user_events_mode
587+ end
588+ end
589+
565590 context 'when given a supported value' do
566591 let ( :track_user_events_mode ) { 'extended' }
567592
@@ -582,6 +607,74 @@ def patcher
582607 end
583608 end
584609
610+ describe 'auto_user_instrumentation.mode' do
611+ before { allow ( Datadog ) . to receive ( :logger ) . and_return ( logger ) }
612+
613+ let ( :logger ) { instance_double ( Datadog ::Core ::Logger ) }
614+
615+ context 'when valid value is set' do
616+ before { settings . appsec . auto_user_instrumentation . mode = 'disabled' }
617+
618+ it { expect ( settings . appsec . auto_user_instrumentation . mode ) . to eq ( 'disabled' ) }
619+ end
620+
621+ context 'when valid short value is set' do
622+ before { settings . appsec . auto_user_instrumentation . mode = 'anon' }
623+
624+ it 'expands the alias value to the long version' do
625+ expect ( settings . appsec . auto_user_instrumentation . mode ) . to eq ( 'anonymization' )
626+ end
627+ end
628+
629+ context 'when invalid value is set' do
630+ it 'sets the value to the default and writes a warning message' do
631+ expect ( logger ) . to receive ( :warn ) . with ( /value provided is not supported/ )
632+ settings . appsec . auto_user_instrumentation . mode = 'unknown'
633+
634+ expect ( settings . appsec . auto_user_instrumentation . mode ) . to eq ( 'identification' )
635+ end
636+ end
637+
638+ context 'when valid DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE is set' do
639+ around do |example |
640+ ClimateControl . modify ( 'DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE' => 'disabled' ) do
641+ example . run
642+ end
643+ end
644+
645+ it { expect ( settings . appsec . auto_user_instrumentation . mode ) . to eq ( 'disabled' ) }
646+ end
647+
648+ context 'when valid DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE short value is set' do
649+ around do |example |
650+ ClimateControl . modify ( 'DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE' => 'anon' ) do
651+ example . run
652+ end
653+ end
654+
655+ it 'expands the alias value to the long version' do
656+ expect ( settings . appsec . auto_user_instrumentation . mode ) . to eq ( 'anonymization' )
657+ end
658+ end
659+
660+ context 'when invalid DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE is set' do
661+ around do |example |
662+ ClimateControl . modify ( 'DD_APPSEC_AUTO_USER_INSTRUMENTATION_MODE' => 'unknown' ) do
663+ example . run
664+ end
665+ end
666+
667+ it 'sets the value to the default and writes a warning message' do
668+ expect ( logger ) . to receive ( :warn ) . with ( /value provided is not supported/ )
669+ expect ( settings . appsec . auto_user_instrumentation . mode ) . to eq ( 'identification' )
670+ end
671+ end
672+
673+ context 'when no value or env variable is set' do
674+ it { expect ( settings . appsec . auto_user_instrumentation . mode ) . to eq ( 'identification' ) }
675+ end
676+ end
677+
585678 describe 'block' do
586679 describe 'templates' do
587680 [
0 commit comments