Skip to content

Commit

Permalink
Merge branch 'v0.2.0' into Issue-#5-base64
Browse files Browse the repository at this point in the history
  • Loading branch information
damies13 committed Apr 9, 2023
2 parents f8819ca + beb7b51 commit 3a53606
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Tests/BrowserLibraryHarFiles/Tryton/tryton_1680844256.har
Original file line number Diff line number Diff line change
Expand Up @@ -17280,4 +17280,4 @@
}
]
}
}
}
217 changes: 217 additions & 0 deletions Tests/BrowserLibraryHarFiles/Tryton/tryton_1680844256.robot

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions src/har2rfreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def find_estep(self, respno, kwname):
def find_variable(self, key, value, lastresort=True):

self.debugmsg(6, "")
self.debugmsg(6, "key:", key, " value:", value)
self.debugmsg(5, " key:", key, " value:", value)

# reset parserdata
self.parserdata = {}
Expand Down Expand Up @@ -565,15 +565,14 @@ def process_list(self, key, listdata):

def saveparam(self, name, value):
#


newname = name
self.debugmsg(9, "newname:", newname)
if name in self.workingdata["paramnames"]:
i = 0
while newname in self.workingdata["paramnames"]:
self.debugmsg(9, "newname:", newname)
i += 1
newname = name + "_{}".format(i)
newname = "{}_{}".format(name, i)

self.debugmsg(9, "newname:", newname)

Expand All @@ -591,7 +590,7 @@ def saveparam(self, name, value):
if value not in self.workingdata["paramvalues"]:
self.workingdata["paramvalues"][value] = "${"+newname+"}"

self.debugmsg(9, "saved", "${"+newname+"}", "=", value)
self.debugmsg(5, "saved", "${"+newname+"}", "=", value)
return newname

def add_test_case(self, tcname):
Expand Down
41 changes: 34 additions & 7 deletions src/modules/h2r_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ def __init__(self, parent):
# Register Paersers
#

ep = "00:self.h2r_base.exiting_paramkey"
ep = "00:self.h2r_base.existing_paramkey"
if ep not in self.parent.parsers:
self.parent.parsers[ep] = {}

ep = "01:self.h2r_base.exiting_paramval"
ep = "01:self.h2r_base.existing_paramval"
if ep not in self.parent.parsers:
self.parent.parsers[ep] = {}

ep = "03:self.h2r_base.existing_paramsubval"
if ep not in self.parent.parsers:
self.parent.parsers[ep] = {}

Expand Down Expand Up @@ -57,7 +61,7 @@ def __init__(self, parent):
# Paersers
#

def exiting_paramkey(self):
def existing_paramkey(self):
self.parent.debugmsg(6, "has key already been found")

searchvals = self.parent.parserdata["searchvals"]
Expand Down Expand Up @@ -93,7 +97,7 @@ def exiting_paramkey(self):



def exiting_paramval(self):
def existing_paramval(self):
self.parent.debugmsg(6, "has value already been found")
kwname = self.parent.parserdata["kwname"]
key = self.parent.parserdata["key"]
Expand All @@ -119,15 +123,38 @@ def exiting_paramval(self):
if self.parent.workingdata["paramvalues"][searchval] in possiblekeys:
newvalue = self.parent.workingdata["paramvalues"][searchval]
return newvalue
if len(searchval)>10:
if len(searchval)>2:
newvalue = self.parent.workingdata["paramvalues"][searchval]
return newvalue

return None

def existing_paramsubval(self):
self.parent.debugmsg(6, "has value already been found")
kwname = self.parent.parserdata["kwname"]
key = self.parent.parserdata["key"]

possiblekeys = []
possiblekeyn = []
for searchkey in self.parent.parserdata["searchkeys"]:
possiblekeys.append("${"+searchkey+"}")
possiblekeyn.append(searchkey)
i = 1
newname = searchkey+"_"+str(i)
while newname in self.parent.workingdata["paramnames"]:
possiblekeys.append("${"+newname+"}")
possiblekeyn.append(newname)
i += 1
newname = searchkey+"_"+str(i)
# self.debugmsg(9, "newname:", newname)
self.parent.debugmsg(6, "possiblekeys:", possiblekeys)

for searchval in self.parent.parserdata["searchvals"]:

for pval in self.parent.workingdata["paramvalues"]:
if searchval in pval:
self.parent.debugmsg(6, "searchval (", searchval, ") is substring of existing pval (", pval, ")")
pvalkey = self.parent.workingdata["paramvalues"][pval]
self.parent.debugmsg(6, "pvalkey:", pvalkey)
self.parent.debugmsg(6, "searchval (", searchval, ") is substring of existing pval (", pval, ") pvalkey:", pvalkey)

pvalkeyname = pvalkey
if pvalkey[:2] == "${":
Expand Down
3 changes: 2 additions & 1 deletion src/modules/h2r_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def html_body(self):
self.parent.debugmsg(5, "ptn:", ptn, " found match:", match)
# matchurls = list(match.groups())
# self.parent.debugmsg(6, "matchurls:", matchurls)
i = 1
i = 0 # needs to be 0 because of re.findall not re.search (if re.search should be 1)
for matchurl in match:
if matchurl == searchval:
self.parent.debugmsg(5, "i:", i, " matchurl:", matchurl, " searchval:", searchval)
Expand All @@ -335,6 +335,7 @@ def html_body(self):
# line = "${"+newkey+"}= evaluate re.findall(\"" + reptn + "\", \"\"\"${resp_"+str(resp)+".text}\"\"\")[" + str(i) + "] re"
line = "${"+newkey+"}= evaluate re.findall(\"\"\"" + ptn + "\"\"\", \"\"\"${resp_"+str(resp)+".text}\"\"\")[" + str(i) + "] re"

self.parent.debugmsg(5, "line:", line)
self.parent.outdata["*** Keywords ***"][ekwname].insert(estep, line)
newvalue = "${"+newkey+"}"
self.parent.debugmsg(5, "newvalue:", newvalue)
Expand Down
33 changes: 23 additions & 10 deletions src/modules/h2r_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ def response_headers(self):
self.parent.debugmsg(6, "headers Parser")

searchkeys = self.parent.parserdata["searchkeys"]
self.parent.debugmsg(7, "searchkeys:", self.parent.parserdata["searchkeys"])
searchvals = self.parent.parserdata["searchvals"]
self.parent.debugmsg(7, "searchvals:", self.parent.parserdata["searchvals"])
kwname = self.parent.parserdata["kwname"]
self.parent.debugmsg(6, "kwname:", self.parent.parserdata["kwname"])
key = self.parent.parserdata["key"]
self.parent.debugmsg(6, "key:", self.parent.parserdata["key"])

for searchval in searchvals.keys():
self.parent.debugmsg(8, "searchval:", searchval)
Expand All @@ -79,8 +83,13 @@ def response_headers(self):
for e in self.parent.workingdata["history"]:

resp = e["entrycount"]+1
self.parent.debugmsg(6, "resp:", resp, " entrycount:", e["entrycount"])
ekwname = e["kwname"]
self.parent.debugmsg(6, "ekwname:", ekwname)
estep = self.parent.find_estep(resp, ekwname)
self.parent.debugmsg(6, "estep:", estep)

resp = e["entrycount"]

# check headers
self.parent.debugmsg(7, "is searchval in headers:", searchval)
Expand All @@ -104,29 +113,31 @@ def response_headers(self):

newkey = self.parent.saveparam(key, searchval)

line = "Set Global Variable ${"+newkey+"} ${resp_"+str(resp + estep)+".headers[\""+hkey+"\"]}"
self.parent.outdata["*** Keywords ***"][ekwname].append(line)
line = "Set Global Variable ${"+newkey+"} ${resp_"+str(resp)+".headers[\""+hkey+"\"]}"
# self.parent.outdata["*** Keywords ***"][ekwname].append(line)
self.parent.outdata["*** Keywords ***"][ekwname].insert(estep, line)

newvalue = "${"+newkey+"}"
return newvalue

if len(searchval) > 10 and searchval in h["value"]:
hkey = h["name"]
self.parent.debugmsg(8, "found searchval (",searchval,") as hkey (",hkey,") for key (",key,") in header for ", e["request"]["url"])
self.parent.debugmsg(6, "found searchval (",searchval,") as hkey (",hkey,") for key (",key,") in header for ", e["request"]["url"])
hvalue = h["value"]
newkey = self.parent.saveparam(hkey, hvalue)


# Set Global Variable ${Location} ${resp_0.headers["Location"]}
line = "Set Global Variable ${"+newkey+"} ${resp_"+str(resp + estep)+".headers[\""+hkey+"\"]}"
line = "Set Global Variable ${"+newkey+"} ${resp_"+str(resp)+".headers[\""+hkey+"\"]}"

self.parent.debugmsg(8, "line:", line)
self.parent.debugmsg(8, "ekwname:", ekwname, " estep:", estep)
self.parent.debugmsg(6, "line:", line)
self.parent.debugmsg(6, "ekwname:", ekwname, " estep:", estep)

self.parent.debugmsg(9, "ekwname[]:", self.parent.outdata["*** Keywords ***"][ekwname])
self.parent.outdata["*** Keywords ***"][ekwname].append(line)
# self.parent.outdata["*** Keywords ***"][ekwname].append(line)
self.parent.outdata["*** Keywords ***"][ekwname].insert(estep, line)

self.parent.debugmsg(8, "hvalue:", hvalue, " searchval:", searchval)
self.parent.debugmsg(6, "hvalue:", hvalue, " searchval:", searchval)

newkey0 = newkey
newkey = self.parent.saveparam(key, searchval)
Expand All @@ -141,9 +152,11 @@ def response_headers(self):
if elen > 0:
line = "${"+newkey+"}= Get Substring ${" + newkey0 + "} " + str(vpos) + " -" + str(elen)
self.parent.outdata["*** Keywords ***"][ekwname].append(line)
# self.parent.outdata["*** Keywords ***"][ekwname].insert(estep + 1, line)
else:
line = "${"+newkey+"}= Get Substring ${" + newkey0 + "} " + str(vpos)
self.parent.outdata["*** Keywords ***"][ekwname].append(line)
# self.parent.outdata["*** Keywords ***"][ekwname].insert(estep + 1, line)


newvalue = "${"+newkey+"}"
Expand Down Expand Up @@ -277,7 +290,7 @@ def request_uripath(self, entry):
return entry

def request_headers(self, entry):
self.parent.debugmsg(6, "headers processor")
self.parent.debugmsg(6, "headers processor, kwname:", entry["kwname"])
self.parent.debugmsg(9, "entry:", entry)

self.parent.debugmsg(8, "sessiondata:", self.parent.workingdata["sessiondata"])
Expand Down Expand Up @@ -310,7 +323,7 @@ def request_headers(self, entry):


def request_cookies(self, entry):
self.parent.debugmsg(6, "headers cookies")
self.parent.debugmsg(6, "headers cookies, kwname:", entry["kwname"])
self.parent.debugmsg(9, "entry:", entry)

# The original code didn't have do anthing to handle cookies beyond the original session
Expand Down
14 changes: 14 additions & 0 deletions src/modules/h2r_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ def url_path(self):

if path != opath:
retarr.append(path)
self.parent.debugmsg(5, "path:", path)
# return path

if path == opath and path[0] == '/':
subopath = opath[1:]
subpath = self.parent.find_variable(key + "_path", subopath, False)
self.parent.debugmsg(7, "subpath:", subpath)
if subpath != subopath:
path = '/' + subpath
self.parent.debugmsg(5, "path:", path)
retarr.append(path)
# return path

if path == opath:
patharr = path.split("/")
Expand All @@ -135,6 +147,7 @@ def url_path(self):
if newpathbeg != pathbeg or newpathend != pathend:
path = newpathbeg + newpathend
retarr.append(path)
# return path

# try to find match for end of the path
patharr = path.split("/")
Expand Down Expand Up @@ -168,6 +181,7 @@ def url_path(self):
if newpathbeg != pathbeg or newpathend != pathend:
path = newpathbeg + newpathend
retarr.append(path)
# return path

self.parent.debugmsg(8, "match.group(2):", match.group(2))
if match.group(2) is not None and len(match.group(2))>1:
Expand Down

0 comments on commit 3a53606

Please sign in to comment.