@@ -20,6 +20,8 @@ trait ReportExt {
20
20
#[ cfg( feature = "graphql_schema" ) ]
21
21
fn contains_perm_vuln ( & self , expected_len : usize ) -> bool ;
22
22
23
+ fn vuln_description_contains ( & self , check_name : & str , description_snippet : & str ) -> bool ;
24
+
23
25
fn contains_vulns ( & self , expected_len : i32 ) -> bool ;
24
26
25
27
fn contains_authz_vuln ( & self , expected_len : usize ) -> bool ;
@@ -59,6 +61,17 @@ impl ReportExt for Report {
59
61
== expected_len
60
62
}
61
63
64
+ #[ inline]
65
+ fn vuln_description_contains ( & self , check_name : & str , description_snippet : & str ) -> bool {
66
+ self . into_vulns ( )
67
+ . iter ( )
68
+ . filter ( |vuln| {
69
+ vuln. check_name ( ) == check_name && vuln. description ( ) . contains ( & description_snippet)
70
+ } )
71
+ . count ( )
72
+ == 1
73
+ }
74
+
62
75
#[ inline]
63
76
fn contains_vulns ( & self , expected_len : i32 ) -> bool {
64
77
self . into_vulns ( ) . len ( ) == expected_len as usize
@@ -887,3 +900,57 @@ fn authz_function_called_in_object_bitbucket() {
887
900
let scan_result = scan_directory_test ( test_forge_project) ;
888
901
assert ! ( scan_result. contains_vulns( 1 ) )
889
902
}
903
+
904
+ #[ test]
905
+ fn extra_permission_bitbucket ( ) {
906
+ let test_forge_project = MockForgeProject :: files_from_string (
907
+ "// src/index.tsx
908
+ import ForgeUI, { render, Fragment, Macro, Text } from '@forge/ui';
909
+ import api, { route, fetch } from '@forge/api';
910
+ const App = () => {
911
+ let testObject = {
912
+ someFunction() {
913
+ const res = api.asUser().requestBitbucket(route`/repositories/mockworkspace/mockreposlug/default-reviewers/jcg`, {
914
+ method: 'PUT',
915
+ body: {}
916
+ });
917
+ return res;
918
+ }
919
+ }
920
+ testObject.someFunction()
921
+ return (
922
+ <Fragment>
923
+ <Text>Hello world!</Text>
924
+ </Fragment>
925
+ );
926
+ };
927
+ export const run = render(<Macro app={<App />} />);
928
+
929
+ // manifest.yaml
930
+ modules:
931
+ macro:
932
+ - key: basic-hello-world
933
+ function: main
934
+ title: basic
935
+ handler: nothing
936
+ description: Inserts Hello world!
937
+ function:
938
+ - key: main
939
+ handler: index.run
940
+ app:
941
+ id: ari:cloud:ecosystem::app/07b89c0f-949a-4905-9de9-6c9521035986
942
+ permissions:
943
+ scopes:
944
+ - 'admin:repository:bitbucket'
945
+ - 'unused:permission:defined'"
946
+ ) ;
947
+
948
+ let scan_result = scan_directory_test ( test_forge_project) ;
949
+ println ! ( "scan_result {:#?}" , scan_result) ;
950
+ assert ! (
951
+ scan_result. contains_perm_vuln( 1 )
952
+ && scan_result. contains_vulns( 1 )
953
+ && scan_result
954
+ . vuln_description_contains( "Least-Privilege" , "unused:permission:defined" )
955
+ ) ;
956
+ }
0 commit comments