Skip to content
Snippets Groups Projects
Commit 67cf12c0 authored by Fawwaz Anugrah Wiradhika Dharmasatya's avatar Fawwaz Anugrah Wiradhika Dharmasatya
Browse files

fix: handle nested if

parent 81c32edc
Branches
No related merge requests found
......@@ -76,14 +76,12 @@ class ACLAnalyzer():
# Gak ada dekorator/dekorator gak cocok
# Traverse fungsinya
while node:
print(node)
# Cek detail untuk beberapa tipe node
if node.type in ['call','assignment']:
# Cek call method
# Format: [attribute,argument_list] | [identifier,argument_list]
child_list = flatten_node(node.children)
fun_name = ""
print(child_list)
var_name = ""
for i in range(len(child_list)):
if child_list[i] in [':',',',]:
......@@ -120,7 +118,6 @@ class ACLAnalyzer():
# Cek
acl_result = None
if is_route:
print("masuk")
acl_result = self.check_acl_list(route,function_name)
if acl_result!=None:
# Ada pengecekan
......@@ -129,7 +126,6 @@ class ACLAnalyzer():
else:
fun_name += child_list[i]
if var_name:
print("as")
try:
acl_result = self.acl_info.acl_context[var_name]
var_name = ""
......@@ -415,7 +411,6 @@ class ACLAnalyzer():
def check_acl_list(self,route:ElementContext,name:str,ctx:list[str]=[])->list[str]|None:
#TODO handle variabel dan kelas dan import
# Format name: fun atau self.fun
print("kesini")
acl_list = (role for role in self.acl_info.principal_list)
for acl_class in self.project_info.acl_class:
acl_class.cfg.reset()
......
......@@ -48,7 +48,16 @@ class ACReader():
if len(route)!=2:
# Harus dalam format route:principal
raise ValueError("Invalid ACL Data")
route_acl[route[0]] = route[1].split(",")
# kasus ada penanda seluruh principal boleh (*)
is_all = False
for p in route[1]:
if "*" in p:
is_all = True
break
if is_all:
route_acl[route[0]] = [principal for principal in principal_list]
else:
route_acl[route[0]] = route[1].split(",")
elif line_type=='detail':
# Parse detail
processed_line = line.strip().replace(" ","")
......
......@@ -177,8 +177,6 @@ class CFG():
node = self.cursor.node
# simpan branch berikutnya
# self.cursor.goto_parent()
# print(self.cursor.node,self.cursor.node.children)
# print("ASS",self.cursor.node.parent.children)
# while has_sibling and self.cursor.node.type not in ['elif_clause','else_clause']:
# has_sibling = self.cursor.goto_next_sibling()
has_sibling = True
......@@ -187,24 +185,18 @@ class CFG():
has_sibling = self.cursor.goto_next_sibling()
if(not has_sibling):
tmp_ptr = self.cursor.copy()
# print("original",self.cursor.node)
self.cursor.goto_parent()
# print("next",self.cursor.node)
self.cursor.goto_next_sibling()
# print("nexr2",self.cursor.node)
# print(starting_node)
# while not has_sibling:
# prev_node = self.cursor.node
# self.cursor.goto_parent()
# has_sibling = self.cursor.goto_next_sibling()
# if CFG.is_node_equal(prev_node,self.cursor.node):
# break
# self.cursor.goto_parent()
# self.cursor.goto_next_sibling()
while not has_sibling:
prev_node = self.cursor.node
self.cursor.goto_parent()
has_sibling = self.cursor.goto_next_sibling()
if CFG.is_node_equal(prev_node,self.cursor.node):
break
self.next_branch = self.cursor.copy()
self.cursor.reset_to(tmp_ptr)
else:
self.next_branch = self.cursor.copy()
print("A",node,node.text)
print("B",self.next_branch.node)
return node
elif(self.cursor.node.type=='elif_clause'):
# Ada percabangan
......
......@@ -34,11 +34,9 @@ class MainMenu():
# Baca file ACL
try:
self.acl_data = ACReader(self.acl_path).read()
print(self.acl_data)
format_log("ACL data acquired.")
self.project_ctx = FileReader(self.project_path).analyze_project()
format_log("ACL and routes context gathered...")
print(self.project_ctx)
except FileNotFoundError:
format_log("File not found. Exiting...",status='error')
else:
......
......@@ -71,7 +71,6 @@ class RouteSanitizationAnalyzer():
# Gak ada dekorator/dekorator gak cocok
# Traverse fungsinya
while node:
print(node)
# Cek detail untuk beberapa tipe node
if node.type in ['call','assignment']:
# Cek call method
......@@ -238,7 +237,6 @@ class RouteSanitizationAnalyzer():
components += flatten_node(child.children)
# Cek tiap componentnya
fun_name = ""
print("COMP",components)
for i in range(len(components)):
if components[i] in ['and','or','not']:
continue
......@@ -264,7 +262,6 @@ class RouteSanitizationAnalyzer():
else:
function_name = ".".join(parts)
# Cek
print(function_name)
if function_name and self.is_in_acl_list(route,function_name,components[i+1:]):
return True
fun_name = ""
......@@ -275,7 +272,6 @@ class RouteSanitizationAnalyzer():
# Tambahkan nama fungsinya
fun_name += components[i]
node = route.cfg.traverse()
print("noda",node)
return False
def analyze_module(self,route:ElementContext)->list[str]:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment