@@ -654,92 +654,104 @@ class MonitorRunnerIT : AlertingRestTestCase() {
654
654
}
655
655
656
656
fun `test execute AD monitor doesn't return search result without user` () {
657
- val user = randomUser()
658
- val detectorId = randomAlphaOfLength(5 )
659
- prepareTestAnomalyResult(detectorId, user)
660
- // for old monitor before enable FGAC, the user field is empty
661
- val monitor = randomADMonitor(inputs = listOf (adSearchInput(detectorId)), triggers = listOf (adMonitorTrigger()), user = null )
662
- val response = executeMonitor(monitor, params = DRYRUN_MONITOR )
663
- val output = entityAsMap(response)
664
- @Suppress(" UNCHECKED_CAST" )
665
- (output[" trigger_results" ] as HashMap <String , Any >).forEach {
666
- _, v -> assertTrue((v as HashMap <String , Boolean >)[" triggered" ] as Boolean )
657
+ // TODO: change to REST API call to test security enabled case
658
+ if (! securityEnabled()) {
659
+ val user = randomUser()
660
+ val detectorId = randomAlphaOfLength(5 )
661
+ prepareTestAnomalyResult(detectorId, user)
662
+ // for old monitor before enable FGAC, the user field is empty
663
+ val monitor = randomADMonitor(inputs = listOf (adSearchInput(detectorId)), triggers = listOf (adMonitorTrigger()), user = null )
664
+ val response = executeMonitor(monitor, params = DRYRUN_MONITOR )
665
+ val output = entityAsMap(response)
666
+ @Suppress(" UNCHECKED_CAST" )
667
+ (output[" trigger_results" ] as HashMap <String , Any >).forEach {
668
+ _, v -> assertTrue((v as HashMap <String , Boolean >)[" triggered" ] as Boolean )
669
+ }
670
+ assertEquals(monitor.name, output[" monitor_name" ])
671
+ @Suppress(" UNCHECKED_CAST" )
672
+ val searchResult = (output.objectMap(" input_results" )[" results" ] as List <Map <String , Any >>).first()
673
+ @Suppress(" UNCHECKED_CAST" )
674
+ val total = searchResult.stringMap(" hits" )?.get(" total" ) as Map <String , String >
675
+ assertEquals(" Incorrect search result" , 1 , total[" value" ])
676
+ @Suppress(" UNCHECKED_CAST" )
677
+ val maxAnomalyGrade = searchResult.stringMap(" aggregations" )?.get(" max_anomaly_grade" ) as Map <String , String >
678
+ assertEquals(" Incorrect search result" , 0.75 , maxAnomalyGrade[" value" ])
667
679
}
668
- assertEquals(monitor.name, output[" monitor_name" ])
669
- @Suppress(" UNCHECKED_CAST" )
670
- val searchResult = (output.objectMap(" input_results" )[" results" ] as List <Map <String , Any >>).first()
671
- @Suppress(" UNCHECKED_CAST" )
672
- val total = searchResult.stringMap(" hits" )?.get(" total" ) as Map <String , String >
673
- assertEquals(" Incorrect search result" , 1 , total[" value" ])
674
- @Suppress(" UNCHECKED_CAST" )
675
- val maxAnomalyGrade = searchResult.stringMap(" aggregations" )?.get(" max_anomaly_grade" ) as Map <String , String >
676
- assertEquals(" Incorrect search result" , 0.75 , maxAnomalyGrade[" value" ])
677
680
}
678
681
679
682
fun `test execute AD monitor doesn't return search result with empty backend role` () {
680
- val user = randomUser()
681
- val detectorId = randomAlphaOfLength(5 )
682
- prepareTestAnomalyResult(detectorId, user)
683
- // for old monitor before enable FGAC, the user field is empty
684
- val monitor = randomADMonitor(inputs = listOf (adSearchInput(detectorId)), triggers = listOf (adMonitorTrigger()),
685
- user = User (user.name, listOf (), user.roles, user.customAttNames))
686
- val response = executeMonitor(monitor, params = DRYRUN_MONITOR )
687
- val output = entityAsMap(response)
688
- @Suppress(" UNCHECKED_CAST" )
689
- (output[" trigger_results" ] as HashMap <String , Any >).forEach {
690
- _, v -> assertTrue((v as HashMap <String , Boolean >)[" triggered" ] as Boolean )
683
+ // TODO: change to REST API call to test security enabled case
684
+ if (! securityEnabled()) {
685
+ val user = randomUser()
686
+ val detectorId = randomAlphaOfLength(5 )
687
+ prepareTestAnomalyResult(detectorId, user)
688
+ // for old monitor before enable FGAC, the user field is empty
689
+ val monitor = randomADMonitor(inputs = listOf (adSearchInput(detectorId)), triggers = listOf (adMonitorTrigger()),
690
+ user = User (user.name, listOf (), user.roles, user.customAttNames))
691
+ val response = executeMonitor(monitor, params = DRYRUN_MONITOR )
692
+ val output = entityAsMap(response)
693
+ @Suppress(" UNCHECKED_CAST" )
694
+ (output[" trigger_results" ] as HashMap <String , Any >).forEach {
695
+ _, v -> assertTrue((v as HashMap <String , Boolean >)[" triggered" ] as Boolean )
696
+ }
697
+ assertEquals(monitor.name, output[" monitor_name" ])
698
+ @Suppress(" UNCHECKED_CAST" )
699
+ val searchResult = (output.objectMap(" input_results" )[" results" ] as List <Map <String , Any >>).first()
700
+ @Suppress(" UNCHECKED_CAST" )
701
+ val total = searchResult.stringMap(" hits" )?.get(" total" ) as Map <String , String >
702
+ assertEquals(" Incorrect search result" , 1 , total[" value" ])
703
+ @Suppress(" UNCHECKED_CAST" )
704
+ val maxAnomalyGrade = searchResult.stringMap(" aggregations" )?.get(" max_anomaly_grade" ) as Map <String , String >
705
+ assertEquals(" Incorrect search result" , 0.9 , maxAnomalyGrade[" value" ])
691
706
}
692
- assertEquals(monitor.name, output[" monitor_name" ])
693
- @Suppress(" UNCHECKED_CAST" )
694
- val searchResult = (output.objectMap(" input_results" )[" results" ] as List <Map <String , Any >>).first()
695
- @Suppress(" UNCHECKED_CAST" )
696
- val total = searchResult.stringMap(" hits" )?.get(" total" ) as Map <String , String >
697
- assertEquals(" Incorrect search result" , 1 , total[" value" ])
698
- @Suppress(" UNCHECKED_CAST" )
699
- val maxAnomalyGrade = searchResult.stringMap(" aggregations" )?.get(" max_anomaly_grade" ) as Map <String , String >
700
- assertEquals(" Incorrect search result" , 0.9 , maxAnomalyGrade[" value" ])
701
707
}
702
708
703
709
fun `test execute AD monitor returns search result with same backend role` () {
704
- val detectorId = randomAlphaOfLength(5 )
705
- val user = randomUser()
706
- prepareTestAnomalyResult(detectorId, user)
707
- // Test monitor with same user
708
- val monitor = randomADMonitor(inputs = listOf (adSearchInput(detectorId)), triggers = listOf (adMonitorTrigger()), user = user)
709
- val response = executeMonitor(monitor, params = DRYRUN_MONITOR )
710
- val output = entityAsMap(response)
711
- @Suppress(" UNCHECKED_CAST" )
712
- (output[" trigger_results" ] as HashMap <String , Any >).forEach {
713
- _, v -> assertTrue((v as HashMap <String , Boolean >)[" triggered" ] as Boolean )
710
+ // TODO: change to REST API call to test security enabled case
711
+ if (! securityEnabled()) {
712
+ val detectorId = randomAlphaOfLength(5 )
713
+ val user = randomUser()
714
+ prepareTestAnomalyResult(detectorId, user)
715
+ // Test monitor with same user
716
+ val monitor = randomADMonitor(inputs = listOf (adSearchInput(detectorId)), triggers = listOf (adMonitorTrigger()), user = user)
717
+ val response = executeMonitor(monitor, params = DRYRUN_MONITOR )
718
+ val output = entityAsMap(response)
719
+ @Suppress(" UNCHECKED_CAST" )
720
+ (output[" trigger_results" ] as HashMap <String , Any >).forEach {
721
+ _, v -> assertTrue((v as HashMap <String , Boolean >)[" triggered" ] as Boolean )
722
+ }
723
+ @Suppress(" UNCHECKED_CAST" )
724
+ val searchResult = (output.objectMap(" input_results" )[" results" ] as List <Map <String , Any >>).first()
725
+ @Suppress(" UNCHECKED_CAST" )
726
+ val total = searchResult.stringMap(" hits" )?.get(" total" ) as Map <String , String >
727
+ assertEquals(" Incorrect search result" , 3 , total[" value" ])
728
+ @Suppress(" UNCHECKED_CAST" )
729
+ val maxAnomalyGrade = searchResult.stringMap(" aggregations" )?.get(" max_anomaly_grade" ) as Map <String , String >
730
+ assertEquals(" Incorrect search result" , 0.8 , maxAnomalyGrade[" value" ])
714
731
}
715
- @Suppress(" UNCHECKED_CAST" )
716
- val searchResult = (output.objectMap(" input_results" )[" results" ] as List <Map <String , Any >>).first()
717
- @Suppress(" UNCHECKED_CAST" )
718
- val total = searchResult.stringMap(" hits" )?.get(" total" ) as Map <String , String >
719
- assertEquals(" Incorrect search result" , 3 , total[" value" ])
720
- @Suppress(" UNCHECKED_CAST" )
721
- val maxAnomalyGrade = searchResult.stringMap(" aggregations" )?.get(" max_anomaly_grade" ) as Map <String , String >
722
- assertEquals(" Incorrect search result" , 0.8 , maxAnomalyGrade[" value" ])
723
732
}
724
733
725
734
fun `test execute AD monitor returns no search result with different backend role` () {
726
- val detectorId = randomAlphaOfLength(5 )
727
- val user = randomUser()
728
- prepareTestAnomalyResult(detectorId, user)
729
- // Test monitor with different user
730
- val monitor = randomADMonitor(inputs = listOf (adSearchInput(detectorId)),
731
- triggers = listOf (adMonitorTrigger()), user = randomUser())
732
- val response = executeMonitor(monitor, params = DRYRUN_MONITOR )
733
- val output = entityAsMap(response)
734
- @Suppress(" UNCHECKED_CAST" )
735
- (output[" trigger_results" ] as HashMap <String , Any >).forEach {
736
- _, v -> assertFalse((v as HashMap <String , Boolean >)[" triggered" ] as Boolean )
735
+ // TODO: change to REST API call to test security enabled case
736
+ if (! securityEnabled()) {
737
+ val detectorId = randomAlphaOfLength(5 )
738
+ val user = randomUser()
739
+ prepareTestAnomalyResult(detectorId, user)
740
+ // Test monitor with different user
741
+ val monitor = randomADMonitor(inputs = listOf (adSearchInput(detectorId)),
742
+ triggers = listOf (adMonitorTrigger()), user = randomUser())
743
+ val response = executeMonitor(monitor, params = DRYRUN_MONITOR )
744
+ val output = entityAsMap(response)
745
+ @Suppress(" UNCHECKED_CAST" )
746
+ (output[" trigger_results" ] as HashMap <String , Any >).forEach {
747
+ _, v -> assertFalse((v as HashMap <String , Boolean >)[" triggered" ] as Boolean )
748
+ }
749
+ @Suppress(" UNCHECKED_CAST" )
750
+ val searchResult = (output.objectMap(" input_results" )[" results" ] as List <Map <String , Any >>).first()
751
+ @Suppress(" UNCHECKED_CAST" )
752
+ val total = searchResult.stringMap(" hits" )?.get(" total" ) as Map <String , String >
753
+ assertEquals(" Incorrect search result" , 0 , total[" value" ])
737
754
}
738
- @Suppress(" UNCHECKED_CAST" )
739
- val searchResult = (output.objectMap(" input_results" )[" results" ] as List <Map <String , Any >>).first()
740
- @Suppress(" UNCHECKED_CAST" )
741
- val total = searchResult.stringMap(" hits" )?.get(" total" ) as Map <String , String >
742
- assertEquals(" Incorrect search result" , 0 , total[" value" ])
743
755
}
744
756
745
757
private fun prepareTestAnomalyResult (detectorId : String , user : User ) {
0 commit comments