Commit c1a5a4ce authored by Christophe Francois's avatar Christophe Francois Committed by Vincent A

[myedenred] Fix js fetching before login

JS filenames are randomized and must be fetched. One of the random
strings has been moved from a <script> tag to another js file that we
need to fetch.
parent cb957a57
......@@ -30,7 +30,7 @@ from weboob.tools.decorators import retry
from .pages import (
LoginPage, AccountsPage, TransactionsPage,
JsParamsPage, JsUserPage, HomePage,
JsParamsPage, JsUserPage, JsAppPage, HomePage,
AuthorizePage,
)
......@@ -60,6 +60,7 @@ class MyedenredBrowser(OAuth2PKCEMixin, PagesBrowser):
TransactionsPage,
)
params_js = URL(r'https://www.myedenred.fr/js/parameters.(?P<random_str>\w+).js', JsParamsPage)
app_js = URL(r'https://www.myedenred.fr/js/app.(?P<random_str>\w+).js', JsAppPage)
connexion_js = URL(r'https://myedenred.fr/js/connexion.(?P<random_str>\w+).js', JsUserPage)
authorize = URL(r'https://sso.eu.edenred.io/connect/authorize', AuthorizePage)
......@@ -76,7 +77,10 @@ class MyedenredBrowser(OAuth2PKCEMixin, PagesBrowser):
def _fetch_auth_parameters(self):
self.home.go()
params_random_str = self.page.get_href_randomstring('parameters')
connexion_random_str = self.page.get_href_randomstring('connexion')
app_random_str = self.page.get_href_randomstring('app')
self.app_js.go(random_str=app_random_str)
connexion_random_str = self.page.get_js_randomstring('connexion')
self.params_js.go(random_str=params_random_str)
js_parameters = self.page.get_json_content()
......
......@@ -56,10 +56,19 @@ class HomePage(RejectableHTMLPage):
# tag on the page. That would require to do something like `//link[25]`
# to get the correct link, and if they modify/add/remove one link then the
# regex is going to crash or give us the wrong result.
href = re.search(r'link href=/js/%s.(\w+).js' % filename, self.text)
href = re.search(r'/js/%s.(\w+).js' % filename, self.text)
return href.group(1)
class JsAppPage(RejectableHTMLPage):
def get_js_randomstring(self, filename):
# Same as get_href_randomstring, some values have been moved to this js file
# It constructs the js url so the regex has several matches,
# we take the first one that isn't just the filename parameter
matches = re.findall(r'%s:"(\w+?)"' % filename, self.text)
return next((m for m in matches if m != filename))
class JsParamsPage(RejectableHTMLPage):
def get_json_content(self):
json_data = re.search(r"JSON\.parse\('(.*)'\)", self.text)
......
Markdown is supported
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