From f55dcd717a946651492142ed198853b1c667254b Mon Sep 17 00:00:00 2001 From: kali Date: Thu, 10 Jan 2013 02:00:21 +0900 Subject: renamed connection page --- data/leap_client.pro | 2 +- pkg/dev-reqs.pip | 4 + src/leap/eip/checks.py | 22 +-- src/leap/gui/firstrun/__init__.py | 5 +- src/leap/gui/firstrun/connect.py | 200 +++++++++++++++++++++++++ src/leap/gui/firstrun/intro.py | 2 +- src/leap/gui/firstrun/providersetup.py | 14 +- src/leap/gui/firstrun/regvalidation.py | 210 --------------------------- src/leap/gui/firstrun/wizard.py | 4 +- src/leap/gui/progress.py | 5 +- src/leap/gui/tests/test_firstrun_login.py | 2 +- src/leap/gui/tests/test_firstrun_register.py | 2 +- src/leap/gui/tests/test_firstrun_wizard.py | 4 +- 13 files changed, 232 insertions(+), 244 deletions(-) create mode 100644 pkg/dev-reqs.pip create mode 100644 src/leap/gui/firstrun/connect.py delete mode 100644 src/leap/gui/firstrun/regvalidation.py diff --git a/data/leap_client.pro b/data/leap_client.pro index a9a9a932..57764a23 100644 --- a/data/leap_client.pro +++ b/data/leap_client.pro @@ -14,7 +14,7 @@ SOURCES += ../src/leap/gui/firstrun/providerinfo.py SOURCES += ../src/leap/gui/firstrun/providerselect.py SOURCES += ../src/leap/gui/firstrun/providersetup.py SOURCES += ../src/leap/gui/firstrun/register.py -SOURCES += ../src/leap/gui/firstrun/regvalidation.py +SOURCES += ../src/leap/gui/firstrun/connect.py SOURCES += ../src/leap/gui/firstrun/wizard.py # where to generate ts files -- tx will pick from here diff --git a/pkg/dev-reqs.pip b/pkg/dev-reqs.pip new file mode 100644 index 00000000..44799a26 --- /dev/null +++ b/pkg/dev-reqs.pip @@ -0,0 +1,4 @@ +ipython +ipdb +pdb4qt +pygeoip diff --git a/src/leap/eip/checks.py b/src/leap/eip/checks.py index a002e2d9..b14e5dd3 100644 --- a/src/leap/eip/checks.py +++ b/src/leap/eip/checks.py @@ -164,13 +164,12 @@ class ProviderCertChecker(object): try: self.fetcher.get(uri, verify=verify) - except requests.exceptions.SSLError as exc: + except requests.exceptions.SSLError: # as exc: logger.error("SSLError") - # XXX RAISE! See #638 - #raise eipexceptions.HttpsBadCertError - logger.warning('BUG #638 CERT VERIFICATION FAILED! ' - '(this should be CRITICAL)') - logger.warning('SSLError: %s', exc.message) + raise eipexceptions.HttpsBadCertError + #logger.warning('BUG #638 CERT VERIFICATION FAILED! ' + #'(this should be CRITICAL)') + #logger.warning('SSLError: %s', exc.message) except requests.exceptions.ConnectionError: logger.error('ConnectionError') @@ -225,12 +224,7 @@ class ProviderCertChecker(object): return fgetfn(*args, **kwargs) try: - # XXX FIXME!!!! - # verify=verify - # Workaround for #638. return to verification - # when That's done!!! - #req = self.fetcher.get(uri, verify=False) - req = getfn(uri, verify=False) + req = getfn(uri, verify=verify) req.raise_for_status() except requests.exceptions.SSLError: @@ -444,8 +438,8 @@ class EIPConfigChecker(object): # FIXME FIXME FIXME self.defaultprovider.load( from_uri=uri, - fetcher=self.fetcher, - verify=False) + fetcher=self.fetcher) + #verify=False) self.defaultprovider.save() def fetch_eip_service_config(self, skip_download=False, diff --git a/src/leap/gui/firstrun/__init__.py b/src/leap/gui/firstrun/__init__.py index d380b75a..2a523d6a 100644 --- a/src/leap/gui/firstrun/__init__.py +++ b/src/leap/gui/firstrun/__init__.py @@ -6,6 +6,7 @@ except ValueError: pass import intro +import connect import last import login import mixins @@ -13,10 +14,10 @@ import providerinfo import providerselect import providersetup import register -import regvalidation __all__ = [ 'intro', + 'connect', 'last', 'login', 'mixins', @@ -24,4 +25,4 @@ __all__ = [ 'providerselect', 'providersetup', 'register', - 'regvalidation'] # ,'wizard'] + ] # ,'wizard'] diff --git a/src/leap/gui/firstrun/connect.py b/src/leap/gui/firstrun/connect.py new file mode 100644 index 00000000..920ada50 --- /dev/null +++ b/src/leap/gui/firstrun/connect.py @@ -0,0 +1,200 @@ +""" +Provider Setup Validation Page, +used in First Run Wizard +""" +import logging + +from PyQt4 import QtGui + +#import requests + +from leap.gui.progress import ValidationPage +from leap.util.web import get_https_domain_and_port + +from leap.base import auth +from leap.gui.constants import APP_LOGO + +logger = logging.getLogger(__name__) + + +class ConnectionPage(ValidationPage): + + def __init__(self, parent=None): + super(ConnectionPage, self).__init__(parent) + self.current_page = "connect" + + title = self.tr("Connecting...") + # XXX uh... really? + subtitle = self.tr("Checking connection with provider.") + + self.setTitle(title) + self.setSubTitle(subtitle) + + self.setPixmap( + QtGui.QWizard.LogoPixmap, + QtGui.QPixmap(APP_LOGO)) + + def _do_checks(self, update_signal=None): + """ + executes actual checks in a separate thread + + we initialize the srp protocol register + and try to register user. + """ + wizard = self.wizard() + full_domain = self.field('provider_domain') + domain, port = get_https_domain_and_port(full_domain) + _domain = u"%s:%s" % (domain, port) if port != 443 else unicode(domain) + + verify = True + + ########################################### + # Set Credentials. + # username and password are in different fields + # if they were stored in log_in or sign_up pages. + from_login = wizard.from_login + + unamek_base = 'userName' + passwk_base = 'userPassword' + unamek = 'login_%s' % unamek_base if from_login else unamek_base + passwk = 'login_%s' % passwk_base if from_login else passwk_base + + username = self.field(unamek) + password = self.field(passwk) + credentials = username, password + + eipconfigchecker = wizard.eipconfigchecker(domain=_domain) + #XXX change for _domain (sanitized) + pCertChecker = wizard.providercertchecker( + domain=full_domain) + + yield(("head_sentinel", 0), lambda: None) + + ################################################## + # 1) fetching eip service config + ################################################## + def fetcheipconf(): + try: + eipconfigchecker.fetch_eip_service_config( + domain=full_domain) + + # XXX get specific exception + except Exception as exc: + return self.fail(exc.message) + + yield((self.tr("Fetching provider config..."), 40), + fetcheipconf) + + ################################################## + # 2) getting client certificate + ################################################## + + def fetcheipcert(): + try: + downloaded = pCertChecker.download_new_client_cert( + credentials=credentials, + verify=verify) + if not downloaded: + logger.error('Could not download client cert.') + return False + + except auth.SRPAuthenticationError as exc: + return self.fail(self.tr( + "Authentication error: %s" % exc.message)) + else: + return True + + yield((self.tr("Fetching eip certificate"), 80), + fetcheipcert) + + ################ + # end ! + ################ + self.set_done() + yield(("end_sentinel", 100), lambda: None) + + def on_checks_validation_ready(self): + """ + called after _do_checks has finished + (connected to checker thread finished signal) + """ + # this should be called CONNECT PAGE AGAIN. + # here we go! :) + if self.is_done(): + full_domain = self.field('provider_domain') + domain, port = get_https_domain_and_port(full_domain) + _domain = u"%s:%s" % ( + domain, port) if port != 443 else unicode(domain) + self.run_eip_checks_for_provider_and_connect(_domain) + + def run_eip_checks_for_provider_and_connect(self, domain): + wizard = self.wizard() + conductor = wizard.conductor + start_eip_signal = getattr( + wizard, + 'start_eipconnection_signal', None) + + if conductor: + conductor.set_provider_domain(domain) + conductor.run_checks() + self.conductor = conductor + errors = self.eip_error_check() + if not errors and start_eip_signal: + start_eip_signal.emit() + + else: + logger.warning( + "No conductor found. This means that " + "probably the wizard has been launched " + "in an stand-alone way.") + + # XXX look for a better place to signal + # we are done. + # We could probably have a fake validatePage + # that checks if the domain transfer has been + # done to conductor object, triggers the start_signal + # and does the go_next() + self.set_done() + + def eip_error_check(self): + """ + a version of the main app error checker, + but integrated within the connecting page of the wizard. + consumes the conductor error queue. + pops errors, and add those to the wizard page + """ + logger.debug('eip error check from connecting page') + errq = self.conductor.error_queue + # XXX missing! + + def _do_validation(self): + """ + called after _do_checks has finished + (connected to checker thread finished signal) + """ + from_login = self.wizard().from_login + prevpage = "login" if from_login else "signup" + + wizard = self.wizard() + if self.errors: + logger.debug('going back with errors') + logger.error(self.errors) + name, first_error = self.pop_first_error() + wizard.set_validation_error( + prevpage, + first_error) + self.go_back() + else: + logger.debug('should go next, wait for user to click next') + #self.go_next() + + def nextId(self): + wizard = self.wizard() + #if not wizard: + #return + return wizard.get_page_index('lastpage') + + def initializePage(self): + super(ConnectionPage, self).initializePage() + self.set_undone() + self.completeChanged.emit() diff --git a/src/leap/gui/firstrun/intro.py b/src/leap/gui/firstrun/intro.py index 0a7484e2..0425b764 100644 --- a/src/leap/gui/firstrun/intro.py +++ b/src/leap/gui/firstrun/intro.py @@ -50,7 +50,7 @@ class IntroPage(QtGui.QWizardPage): layout.addWidget(radiobuttonGroup) self.setLayout(layout) - self.registerField('is_signup', self.sign_up) + #self.registerField('is_signup', self.sign_up) def validatePage(self): return True diff --git a/src/leap/gui/firstrun/providersetup.py b/src/leap/gui/firstrun/providersetup.py index 1a362794..48a89091 100644 --- a/src/leap/gui/firstrun/providersetup.py +++ b/src/leap/gui/firstrun/providersetup.py @@ -20,8 +20,8 @@ class ProviderSetupValidationPage(ValidationPage): self.current_page = "providersetupvalidation" # XXX needed anymore? - is_signup = self.field("is_signup") - self.is_signup = is_signup + #is_signup = self.field("is_signup") + #self.is_signup = is_signup self.setTitle(self.tr("Provider setup")) self.setSubTitle( @@ -158,14 +158,12 @@ class ProviderSetupValidationPage(ValidationPage): def nextId(self): wizard = self.wizard() - if not wizard: - return - is_signup = self.field('is_signup') - if is_signup is True: - next_ = 'signup' - if is_signup is False: + from_login = wizard.from_login + if from_login: # XXX bad name. change to connect again. next_ = 'signupvalidation' + else: + next_ = 'signup' return wizard.get_page_index(next_) def initializePage(self): diff --git a/src/leap/gui/firstrun/regvalidation.py b/src/leap/gui/firstrun/regvalidation.py deleted file mode 100644 index 6135a290..00000000 --- a/src/leap/gui/firstrun/regvalidation.py +++ /dev/null @@ -1,210 +0,0 @@ -""" -Provider Setup Validation Page, -used in First Run Wizard -""" -# XXX This page is called regvalidation -# but it's implementing functionality in the former -# connect page. -# We should remame it to connect again, when we integrate -# the login branch of the wizard. - -import logging -#import json -#import socket - -from PyQt4 import QtGui - -#import requests - -from leap.gui.progress import ValidationPage -from leap.util.web import get_https_domain_and_port - -from leap.base import auth -from leap.gui.constants import APP_LOGO - -logger = logging.getLogger(__name__) - - -class RegisterUserValidationPage(ValidationPage): - - def __init__(self, parent=None): - super(RegisterUserValidationPage, self).__init__(parent) - self.current_page = "signupvalidation" - - title = self.tr("Connecting...") - # XXX uh... really? - subtitle = self.tr("Checking connection with provider.") - - self.setTitle(title) - self.setSubTitle(subtitle) - - self.setPixmap( - QtGui.QWizard.LogoPixmap, - QtGui.QPixmap(APP_LOGO)) - - def _do_checks(self, update_signal=None): - """ - executes actual checks in a separate thread - - we initialize the srp protocol register - and try to register user. - """ - wizard = self.wizard() - full_domain = self.field('provider_domain') - domain, port = get_https_domain_and_port(full_domain) - _domain = u"%s:%s" % (domain, port) if port != 443 else unicode(domain) - - # FIXME #BUG 638 FIXME FIXME FIXME - verify = False # !!!!!!!!!!!!!!!! - # FIXME #BUG 638 FIXME FIXME FIXME - - ########################################### - # Set Credentials. - # username and password are in different fields - # if they were stored in log_in or sign_up pages. - is_signup = self.field("is_signup") - - unamek_base = 'userName' - passwk_base = 'userPassword' - unamek = 'login_%s' % unamek_base if not is_signup else unamek_base - passwk = 'login_%s' % passwk_base if not is_signup else passwk_base - - username = self.field(unamek) - password = self.field(passwk) - credentials = username, password - - eipconfigchecker = wizard.eipconfigchecker(domain=_domain) - #XXX change for _domain (sanitized) - pCertChecker = wizard.providercertchecker( - domain=full_domain) - - yield(("head_sentinel", 0), lambda: None) - - ################################################## - # 1) fetching eip service config - ################################################## - def fetcheipconf(): - try: - eipconfigchecker.fetch_eip_service_config( - domain=full_domain) - - # XXX get specific exception - except Exception as exc: - return self.fail(exc.message) - - yield((self.tr("Fetching provider config..."), 40), - fetcheipconf) - - ################################################## - # 2) getting client certificate - ################################################## - - def fetcheipcert(): - try: - downloaded = pCertChecker.download_new_client_cert( - credentials=credentials, - verify=verify) - if not downloaded: - logger.error('Could not download client cert.') - return False - - except auth.SRPAuthenticationError as exc: - return self.fail(self.tr( - "Authentication error: %s" % exc.message)) - else: - return True - - yield((self.tr("Fetching eip certificate"), 80), - fetcheipcert) - - ################ - # end ! - ################ - self.set_done() - yield(("end_sentinel", 100), lambda: None) - - def on_checks_validation_ready(self): - """ - called after _do_checks has finished - (connected to checker thread finished signal) - """ - # this should be called CONNECT PAGE AGAIN. - # here we go! :) - if self.is_done(): - full_domain = self.field('provider_domain') - domain, port = get_https_domain_and_port(full_domain) - _domain = u"%s:%s" % ( - domain, port) if port != 443 else unicode(domain) - self.run_eip_checks_for_provider_and_connect(_domain) - - def run_eip_checks_for_provider_and_connect(self, domain): - wizard = self.wizard() - conductor = wizard.conductor - start_eip_signal = getattr( - wizard, - 'start_eipconnection_signal', None) - - if conductor: - conductor.set_provider_domain(domain) - conductor.run_checks() - self.conductor = conductor - errors = self.eip_error_check() - if not errors and start_eip_signal: - start_eip_signal.emit() - - else: - logger.warning( - "No conductor found. This means that " - "probably the wizard has been launched " - "in an stand-alone way.") - - # XXX look for a better place to signal - # we are done. - # We could probably have a fake validatePage - # that checks if the domain transfer has been - # done to conductor object, triggers the start_signal - # and does the go_next() - self.set_done() - - def eip_error_check(self): - """ - a version of the main app error checker, - but integrated within the connecting page of the wizard. - consumes the conductor error queue. - pops errors, and add those to the wizard page - """ - logger.debug('eip error check from connecting page') - errq = self.conductor.error_queue - # XXX missing! - - def _do_validation(self): - """ - called after _do_checks has finished - (connected to checker thread finished signal) - """ - is_signup = self.field("is_signup") - prevpage = "signup" if is_signup else "login" - - wizard = self.wizard() - if self.errors: - logger.debug('going back with errors') - logger.error(self.errors) - name, first_error = self.pop_first_error() - wizard.set_validation_error( - prevpage, - first_error) - self.go_back() - else: - logger.debug('should go next, wait for user to click next') - #self.go_next() - - def nextId(self): - wizard = self.wizard() - if not wizard: - return - return wizard.get_page_index('lastpage') - - def initializePage(self): - super(RegisterUserValidationPage, self).initializePage() - self.set_undone() - self.completeChanged.emit() diff --git a/src/leap/gui/firstrun/wizard.py b/src/leap/gui/firstrun/wizard.py index 408d4597..427f9df8 100755 --- a/src/leap/gui/firstrun/wizard.py +++ b/src/leap/gui/firstrun/wizard.py @@ -59,8 +59,8 @@ def get_pages_dict(): ('providersetupvalidation', firstrun.providersetup.ProviderSetupValidationPage), ('signup', firstrun.register.RegisterUserPage), - ('signupvalidation', - firstrun.regvalidation.RegisterUserValidationPage), + ('connect', + firstrun.connect.ConnectionPage), ('lastpage', firstrun.last.LastPage) )) diff --git a/src/leap/gui/progress.py b/src/leap/gui/progress.py index ffea80de..fceeb2f6 100644 --- a/src/leap/gui/progress.py +++ b/src/leap/gui/progress.py @@ -118,11 +118,12 @@ class StepsTableWidget(QtGui.QTableWidget): self.setSelectionMode( QtGui.QAbstractItemView.NoSelection) width = self.width() + # WTF? Here init width is 100... # but on populating is 456... :( + #logger.debug('init table. width=%s' % width) # XXX do we need this initial? - logger.debug('init table. width=%s' % width) self.horizontalHeader().resizeSection(0, width * 0.7) # this disables the table grid. @@ -318,7 +319,7 @@ class WithStepsMixIn(object): table = self.stepsTableWidget FIRST_COLUMN_PERCENT = 0.70 width = table.width() - logger.debug('populate table. width=%s' % width) + #logger.debug('populate table. width=%s' % width) table.horizontalHeader().resizeSection(0, width * FIRST_COLUMN_PERCENT) def set_item_icon(self, img=ICON_CHECKMARK, current=True): diff --git a/src/leap/gui/tests/test_firstrun_login.py b/src/leap/gui/tests/test_firstrun_login.py index fa800c23..6c45b8ef 100644 --- a/src/leap/gui/tests/test_firstrun_login.py +++ b/src/leap/gui/tests/test_firstrun_login.py @@ -100,7 +100,7 @@ class RegisterUserPageUITestCase(qunittest.TestCase): pages = OrderedDict(( (self.pagename, TestPage), ('providersetupvalidation', - firstrun.regvalidation.RegisterUserValidationPage))) + firstrun.connect.ConnectionPage))) self.wizard = firstrun.wizard.FirstRunWizard(None, pages_dict=pages) self.page = self.wizard.page(self.wizard.get_page_index(self.pagename)) diff --git a/src/leap/gui/tests/test_firstrun_register.py b/src/leap/gui/tests/test_firstrun_register.py index 3447fe9d..d3be8897 100644 --- a/src/leap/gui/tests/test_firstrun_register.py +++ b/src/leap/gui/tests/test_firstrun_register.py @@ -113,7 +113,7 @@ class RegisterUserPageUITestCase(qunittest.TestCase): pages = OrderedDict(( (self.pagename, TestPage), ('signupvalidation', - firstrun.regvalidation.RegisterUserValidationPage))) + firstrun.connect.ConnectionPage))) self.wizard = firstrun.wizard.FirstRunWizard(None, pages_dict=pages) self.page = self.wizard.page(self.wizard.get_page_index(self.pagename)) diff --git a/src/leap/gui/tests/test_firstrun_wizard.py b/src/leap/gui/tests/test_firstrun_wizard.py index d51e9945..b6c34000 100644 --- a/src/leap/gui/tests/test_firstrun_wizard.py +++ b/src/leap/gui/tests/test_firstrun_wizard.py @@ -29,8 +29,8 @@ PAGES_DICT = dict(( ('providersetupvalidation', firstrun.providersetup.ProviderSetupValidationPage), ('signup', firstrun.register.RegisterUserPage), - ('signupvalidation', - firstrun.regvalidation.RegisterUserValidationPage), + ('connect', + firstrun.connect.ConnectionPage), ('lastpage', firstrun.last.LastPage) )) -- cgit v1.2.3