Skip to content

Commit d875900

Browse files
Add remaining jira software paths and string literal handling, handle bug
1 parent 12aa54e commit d875900

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

crates/forge_analyzer/src/checkers.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
use core::fmt;
2-
use forge_permission_resolver::permissions_resolver::{check_url_for_permissions, RequestType};
2+
use forge_permission_resolver::permissions_resolver::{
3+
check_url_for_permissions, PermissionHashMap, RequestType,
4+
};
35
use forge_utils::FxHashMap;
46
use itertools::Itertools;
7+
use regex::Regex;
58
use smallvec::SmallVec;
69
use std::{
710
cmp::max,
11+
collections::HashMap,
812
collections::HashSet,
913
iter::{self, zip},
1014
mem,
1115
ops::ControlFlow,
1216
path::PathBuf,
1317
};
14-
1518
use tracing::{debug, info, warn};
1619

1720
use crate::interp::ProjectionVec;
@@ -1117,7 +1120,9 @@ impl<'cx> Dataflow<'cx> for PermissionDataflow {
11171120
interp.bitbucket_permission_resolver,
11181121
interp.bitbucket_regex_map,
11191122
),
1120-
_ => unreachable!("Invalid intrinsic function type"),
1123+
IntrinsicName::Other => {
1124+
(&PermissionHashMap::new(), &HashMap::<String, Regex>::new())
1125+
}
11211126
};
11221127

11231128
if intrinsic_argument.first_arg.is_none() {

crates/forge_analyzer/src/definitions.rs

+24-19
Original file line numberDiff line numberDiff line change
@@ -1001,18 +1001,28 @@ impl FunctionAnalyzer<'_> {
10011001
fn resolve_jira_api_type(url: &str) -> Option<IntrinsicName> {
10021002
// Pattern matching to classify, eg: api.[asApp | asUser]().requestJira(route`/rest/api/3/myself`);
10031003
match url {
1004+
// JSM requests
10041005
url if url.starts_with("/rest/servicedeskapi/") => {
10051006
Some(IntrinsicName::RequestJiraServiceManagement)
10061007
}
1007-
url if url.starts_with("/rest/agile/") => Some(IntrinsicName::RequestJiraSoftware),
1008-
// Accept Jira API v2.0 or v3.0
1008+
// Jira Software requests from https://developer.atlassian.com/cloud/jira/software/rest/intro/#introduction
1009+
url if url.starts_with("/rest/agile/")
1010+
|| url.starts_with("/rest/devinfo/")
1011+
|| url.starts_with("/rest/featureflags/")
1012+
|| url.starts_with("/rest/deployments/")
1013+
|| url.starts_with("/rest/builds")
1014+
|| url.starts_with("/rest/remotelinks/")
1015+
|| url.starts_with("/rest/security/")
1016+
|| url.starts_with("/rest/operations/")
1017+
|| url.starts_with("/rest/devopscomponents/") =>
1018+
{
1019+
Some(IntrinsicName::RequestJiraSoftware)
1020+
}
1021+
// Jira requests, accept Jira API v2.0 or v3.0
10091022
url if url.starts_with("/rest/api/2/") || url.starts_with("/rest/api/3/") => {
10101023
Some(IntrinsicName::RequestJira)
10111024
}
1012-
_ => {
1013-
warn!("Provided Jira API URL: {:?} is neither Jira, JS, JSM!", url);
1014-
None
1015-
}
1025+
_ => None,
10161026
}
10171027
}
10181028

@@ -1032,21 +1042,16 @@ impl FunctionAnalyzer<'_> {
10321042
// Resolve Jira API requests to either JSM/JS/Jira as all are bundled within requestJira()
10331043
match first_arg {
10341044
Expr::TaggedTpl(TaggedTpl { tpl, .. }) => {
1035-
if let Some(TplElement { raw, .. }) = tpl.quasis.first() {
1036-
resolve_jira_api_type(raw).unwrap_or_else(|| {
1037-
// Conservatively assume any of Jira APIs may be used if we can't statically determine which one
1038-
warn!("Falling back to any Jira request");
1039-
IntrinsicName::RequestJiraAny
1040-
})
1041-
} else {
1042-
panic!("No url identifiable to classify requestJira() type");
1043-
}
1044-
}
1045-
_ => {
1046-
warn!("Unable to classify requestJira() type");
1047-
IntrinsicName::RequestJiraAny
1045+
tpl.quasis.first().map(|elem| &elem.raw)
10481046
}
1047+
Expr::Lit(Lit::Str(str_lit)) => Some(&str_lit.value),
1048+
_ => None,
10491049
}
1050+
.and_then(|atom| resolve_jira_api_type(atom.as_ref()))
1051+
.unwrap_or_else(|| {
1052+
warn!("Could not resolve Jira API type, falling back to any Jira request");
1053+
IntrinsicName::RequestJiraAny
1054+
})
10501055
} else if *last == "requestBitbucket" {
10511056
IntrinsicName::RequestBitbucket
10521057
} else {

0 commit comments

Comments
 (0)