@@ -30,7 +30,6 @@ const options = {
30
30
const client = new ModelArmorClient ( options ) ;
31
31
const templateIdPrefix = `test-template-${ uuidv4 ( ) . substring ( 0 , 8 ) } ` ;
32
32
33
- let emptyTemplateId ;
34
33
let basicTemplateId ;
35
34
let basicSdpTemplateId ;
36
35
let advanceSdpTemplateId ;
@@ -261,6 +260,7 @@ describe('Model Armor tests', () => {
261
260
before ( async ( ) => {
262
261
projectId = await client . getProjectId ( ) ;
263
262
const { protos} = require ( '@google-cloud/modelarmor' ) ;
263
+
264
264
// Import necessary enums
265
265
const DetectionConfidenceLevel =
266
266
protos . google . cloud . modelarmor . v1 . DetectionConfidenceLevel ;
@@ -275,9 +275,7 @@ describe('Model Armor tests', () => {
275
275
. SdpBasicConfigEnforcement ;
276
276
const RaiFilterType = protos . google . cloud . modelarmor . v1 . RaiFilterType ;
277
277
278
- // Create empty template for sanitizeUserPrompt tests
279
- emptyTemplateId = `${ templateIdPrefix } -empty` ;
280
- await createTemplate ( emptyTemplateId , { } ) ;
278
+ await disableFloorSettings ( ) ;
281
279
282
280
// Create basic template with PI/Jailbreak and Malicious URI filters for sanitizeUserPrompt tests
283
281
basicTemplateId = `${ templateIdPrefix } -basic` ;
@@ -360,7 +358,6 @@ describe('Model Armor tests', () => {
360
358
} ) ;
361
359
362
360
templatesToDelete . push (
363
- `projects/${ projectId } /locations/${ locationId } /templates/${ emptyTemplateId } ` ,
364
361
`projects/${ projectId } /locations/${ locationId } /templates/${ basicTemplateId } ` ,
365
362
`projects/${ projectId } /locations/${ locationId } /templates/${ basicSdpTemplateId } ` ,
366
363
`projects/${ projectId } /locations/${ locationId } /templates/${ advanceSdpTemplateId } ` ,
@@ -371,10 +368,6 @@ describe('Model Armor tests', () => {
371
368
372
369
after ( async ( ) => {
373
370
for ( const templateName of templatesToDelete ) {
374
- // TODO(b/424365799): Uncomment below code once the mentioned issue is resolved
375
- // Disable floor settings to restore original state
376
- // await disableFloorSettings();
377
-
378
371
await deleteTemplate ( templateName ) ;
379
372
}
380
373
@@ -728,24 +721,6 @@ describe('Model Armor tests', () => {
728
721
) ;
729
722
} ) ;
730
723
731
- it ( 'should not detect issues in user prompt with empty template' , async ( ) => {
732
- const sanitizeUserPrompt = require ( '../snippets/sanitizeUserPrompt' ) ;
733
- const testUserPrompt =
734
- 'Can you describe this link? https://testsafebrowsing.appspot.com/s/malware.html,' ;
735
-
736
- const response = await sanitizeUserPrompt (
737
- projectId ,
738
- locationId ,
739
- emptyTemplateId ,
740
- testUserPrompt
741
- ) ;
742
-
743
- assert . equal (
744
- response . sanitizationResult . filterMatchState ,
745
- 'NO_MATCH_FOUND'
746
- ) ;
747
- } ) ;
748
-
749
724
// =================== Model Response Sanitization Tests ===================
750
725
751
726
it ( 'should detect malicious URL in model response' , async ( ) => {
@@ -826,24 +801,6 @@ describe('Model Armor tests', () => {
826
801
) ;
827
802
} ) ;
828
803
829
- it ( 'should not detect issues in model response with empty template' , async ( ) => {
830
- const sanitizeModelResponse = require ( '../snippets/sanitizeModelResponse' ) ;
831
- const testModelResponse =
832
- 'For following email [email protected] found following associated phone number: 954-321-7890 and this ITIN: 988-86-1234' ;
833
-
834
- const response = await sanitizeModelResponse (
835
- projectId ,
836
- locationId ,
837
- emptyTemplateId ,
838
- testModelResponse
839
- ) ;
840
-
841
- assert . equal (
842
- response . sanitizationResult . filterMatchState ,
843
- 'NO_MATCH_FOUND'
844
- ) ;
845
- } ) ;
846
-
847
804
it ( 'should detect PII in model response with basic SDP template' , async ( ) => {
848
805
const sanitizeModelResponse = require ( '../snippets/sanitizeModelResponse' ) ;
849
806
const testModelResponse =
@@ -874,27 +831,6 @@ describe('Model Armor tests', () => {
874
831
875
832
// =================== Model Response with User Prompt Tests ===================
876
833
877
- it ( 'should not detect issues in model response with user prompt using empty template' , async ( ) => {
878
- const sanitizeModelResponseWithUserPrompt = require ( '../snippets/sanitizeModelResponseWithUserPrompt' ) ;
879
- const testUserPrompt =
880
- 'How can I make my email address [email protected] make available to public for feedback' ;
881
- const testModelResponse =
882
- 'You can make support email such as [email protected] for getting feedback from your customer' ;
883
-
884
- const response = await sanitizeModelResponseWithUserPrompt (
885
- projectId ,
886
- locationId ,
887
- emptyTemplateId ,
888
- testModelResponse ,
889
- testUserPrompt
890
- ) ;
891
-
892
- assert . equal (
893
- response . sanitizationResult . filterMatchState ,
894
- 'NO_MATCH_FOUND'
895
- ) ;
896
- } ) ;
897
-
898
834
it ( 'should sanitize model response with user prompt using advanced SDP template' , async ( ) => {
899
835
const sanitizeModelResponseWithUserPrompt = require ( '../snippets/sanitizeModelResponseWithUserPrompt' ) ;
900
836
const testUserPrompt =
@@ -937,57 +873,66 @@ describe('Model Armor tests', () => {
937
873
'NO_MATCH_FOUND'
938
874
) ;
939
875
} ) ;
876
+ } ) ;
877
+
878
+ describe ( 'Model Armor floor setting tests' , ( ) => {
879
+ before ( async ( ) => {
880
+ projectId = await client . getProjectId ( ) ;
881
+ } ) ;
882
+
883
+ after ( async ( ) => {
884
+ await disableFloorSettings ( ) ;
885
+ } ) ;
940
886
941
- // =================== Floor Settings Tests ===================
887
+ it ( 'should update organization floor settings' , async ( ) => {
888
+ const updateOrganizationFloorSettings = require ( '../snippets/updateOrganizationFloorSettings' ) ;
889
+ const output = await updateOrganizationFloorSettings . main ( organizationId ) ;
890
+ // Check that the enableFloorSettingEnforcement=true
891
+ assert . equal ( output . enableFloorSettingEnforcement , true ) ;
892
+ } ) ;
942
893
943
- // TODO(b/424365799): Enable below tests once the mentioned issue is resolved
894
+ it ( 'should update folder floor settings' , async ( ) => {
895
+ const updateFolderFloorSettings = require ( '../snippets/updateFolderFloorSettings' ) ;
896
+ const output = await updateFolderFloorSettings . main ( folderId ) ;
897
+ // Check that the enableFloorSettingEnforcement=true
898
+ assert . equal ( output . enableFloorSettingEnforcement , true ) ;
899
+ } ) ;
944
900
945
- it . skip ( 'should get organization floor settings' , async ( ) => {
901
+ it ( 'should update project floor settings' , async ( ) => {
902
+ const updateProjectFloorSettings = require ( '../snippets/updateProjectFloorSettings' ) ;
903
+ const output = await updateProjectFloorSettings . main ( projectId ) ;
904
+ // Check that the enableFloorSettingEnforcement=true
905
+ assert . equal ( output . enableFloorSettingEnforcement , true ) ;
906
+ } ) ;
907
+
908
+ it ( 'should get organization floor settings' , async ( ) => {
946
909
const getOrganizationFloorSettings = require ( '../snippets/getOrganizationFloorSettings' ) ;
947
910
948
911
const output = await getOrganizationFloorSettings . main ( organizationId ) ;
949
912
950
913
const expectedName = `organizations/${ organizationId } /locations/global/floorSetting` ;
951
914
assert . equal ( output . name , expectedName ) ;
915
+ assert . exists ( output . enableFloorSettingEnforcement ) ;
952
916
} ) ;
953
917
954
- it . skip ( 'should get folder floor settings' , async ( ) => {
918
+ it ( 'should get folder floor settings' , async ( ) => {
955
919
const getFolderFloorSettings = require ( '../snippets/getFolderFloorSettings' ) ;
956
920
957
921
const output = await getFolderFloorSettings . main ( folderId ) ;
958
922
959
923
// Check for expected name format in output
960
924
const expectedName = `folders/${ folderId } /locations/global/floorSetting` ;
961
925
assert . equal ( output . name , expectedName ) ;
926
+ assert . exists ( output . enableFloorSettingEnforcement ) ;
962
927
} ) ;
963
928
964
- it . skip ( 'should get project floor settings' , async ( ) => {
929
+ it ( 'should get project floor settings' , async ( ) => {
965
930
const getProjectFloorSettings = require ( '../snippets/getProjectFloorSettings' ) ;
966
931
967
932
const output = await getProjectFloorSettings . main ( projectId ) ;
968
933
// Check for expected name format in output
969
934
const expectedName = `projects/${ projectId } /locations/global/floorSetting` ;
970
935
assert . equal ( output . name , expectedName ) ;
971
- } ) ;
972
-
973
- it . skip ( 'should update organization floor settings' , async ( ) => {
974
- const updateOrganizationFloorSettings = require ( '../snippets/updateOrganizationFloorSettings' ) ;
975
- const output = await updateOrganizationFloorSettings . main ( organizationId ) ;
976
- // Check that the enableFloorSettingEnforcement=true
977
- assert . equal ( output . enableFloorSettingEnforcement , true ) ;
978
- } ) ;
979
-
980
- it . skip ( 'should update folder floor settings' , async ( ) => {
981
- const updateFolderFloorSettings = require ( '../snippets/updateFolderFloorSettings' ) ;
982
- const output = await updateFolderFloorSettings . main ( folderId ) ;
983
- // Check that the enableFloorSettingEnforcement=true
984
- assert . equal ( output . enableFloorSettingEnforcement , true ) ;
985
- } ) ;
986
-
987
- it . skip ( 'should update project floor settings' , async ( ) => {
988
- const updateProjectFloorSettings = require ( '../snippets/updateProjectFloorSettings' ) ;
989
- const output = await updateProjectFloorSettings . main ( projectId ) ;
990
- // Check that the enableFloorSettingEnforcement=true
991
- assert . equal ( output . enableFloorSettingEnforcement , true ) ;
936
+ assert . exists ( output . enableFloorSettingEnforcement ) ;
992
937
} ) ;
993
938
} ) ;
0 commit comments