[PATCH 1 of 5 forgotpwd] Drop usage of deprecated __secure__ and secure arguments and https-url config

Denis Laxalde denis.laxalde at logilab.fr
Thu May 16 17:43:37 CEST 2019


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1558010099 -7200
#      jeu. mai 16 14:34:59 2019 +0200
# Node ID 96c1f82b23562d4a5f3cd8c24a177f7009bad8a7
# Parent  353809ff753bbc09de17783f79ad01caa24cfe17
# Available At https://hg.logilab.org/review/cubes/forgotpwd
#              hg pull https://hg.logilab.org/review/cubes/forgotpwd -r 96c1f82b2356
Drop usage of deprecated __secure__ and secure arguments and https-url config

This fixes the following warnings:

  DeprecationWarning: [3.25] __secure__ argument is deprecated
  DeprecationWarning: [3.25] secure argument is deprecated

Accordingly, we now require cubicweb >= 3.25.

Notice that we drop a test case which sole purpose was to check that
things work with https-url option. Since this option does not exist
anymore, the test is now meaningless. On the other hand, we extend the
remaing tests for notification view (test_reset_password) to now check
for the presence of instance URL in sent email.

diff --git a/cubicweb_forgotpwd/__pkginfo__.py b/cubicweb_forgotpwd/__pkginfo__.py
--- a/cubicweb_forgotpwd/__pkginfo__.py
+++ b/cubicweb_forgotpwd/__pkginfo__.py
@@ -20,7 +20,7 @@ classifiers = [
     'Programming Language :: JavaScript',
     ]
 
-__depends__ = {'cubicweb': '>= 3.19.0',
+__depends__ = {'cubicweb': '>= 3.25.0',
                'pycrypto': None,
                'Pillow': None,
                }
diff --git a/cubicweb_forgotpwd/hooks.py b/cubicweb_forgotpwd/hooks.py
--- a/cubicweb_forgotpwd/hooks.py
+++ b/cubicweb_forgotpwd/hooks.py
@@ -52,7 +52,7 @@ See you soon on %(base_url)s !
 ''')
 
     def subject(self):
-        return self._cw._(u'[%s] Request to change your password' % self._cw.base_url(secure=True))
+        return self._cw._(u'[%s] Request to change your password' % self._cw.base_url())
 
     def recipients(self):
         fpasswd = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
@@ -67,7 +67,6 @@ See you soon on %(base_url)s !
         data['revocation_id'] = fpasswd.revocation_id
         key = encrypt(data, self._cw.vreg.config['forgotpwd-cypher-seed'])
         url = self._cw.build_url('forgottenpasswordrequest',
-                                 __secure__=True,
                                  key=key,)
         return {
             'resetlink': url,
@@ -75,6 +74,6 @@ See you soon on %(base_url)s !
             # NOTE: it would probably be better to display the expiration date
             #       (with correct timezone)
             'limit': self._cw.vreg.config['revocation-limit'],
-            'base_url': self._cw.base_url(secure=True),
+            'base_url': self._cw.base_url(),
             }
 
diff --git a/cubicweb_forgotpwd/views.py b/cubicweb_forgotpwd/views.py
--- a/cubicweb_forgotpwd/views.py
+++ b/cubicweb_forgotpwd/views.py
@@ -25,8 +25,7 @@ class ForgotPasswordLinkWidget(wdg.Field
     def render(self, form, field, renderer):
         req = form._cw
         ret = u'<span class="forgotpwdLink"><a href="%s">%s</a></span>' % (
-            xml_escape(req.build_url('forgottenpassword',
-                                     __secure__=True)),
+            xml_escape(req.build_url('forgottenpassword')),
             req._('Forgot your password?'))
         return ret
 
@@ -43,7 +42,7 @@ class ForgottenPasswordForm(forms.Fields
     form_buttons = [wdg.SubmitButton()]
     @property
     def action(self):
-        return self._cw.build_url(u'forgottenpassword_sendmail', __secure__=True)
+        return self._cw.build_url(u'forgottenpassword_sendmail')
 
     use_email = ff.StringField(widget=wdg.TextInput(), required=True, label=_(u'your email address'))
     captcha = ff.StringField(widget=captcha.CaptchaWidget(), required=True,
@@ -75,7 +74,7 @@ class ForgottenPasswordSendMailControlle
             msg = unicode(exc)
         else:
             msg = self._cw._(u'An email has been sent, follow instructions in there to change your password.')
-        raise Redirect(self._cw.build_url('pwdsent', __message=msg, __secure__=True))
+        raise Redirect(self._cw.build_url('pwdsent', __message=msg))
 
     def checked_data(self):
         '''only basic data check here (required attributes and password
@@ -116,7 +115,7 @@ class ForgottenPasswordRequestForm(forms
     form_buttons = [wdg.SubmitButton()]
     @property
     def action(self):
-        return self._cw.build_url(u'forgottenpassword-requestconfirm', __secure__=True)
+        return self._cw.build_url(u'forgottenpassword-requestconfirm')
 
     upassword = ff.StringField(widget=wdg.PasswordInput(), required=True)
 
@@ -130,7 +129,7 @@ class ForgottenPasswordRequestView(form.
                            self._cw.vreg.config['forgotpwd-cypher-seed'])
         except:
             msg = self._cw._(u'Invalid link. Please try again.')
-            raise Redirect(self._cw.build_url(u'forgottenpassword', __message=msg, __secure__=True))
+            raise Redirect(self._cw.build_url(u'forgottenpassword', __message=msg))
 
     def call(self):
         key = self.check_key()
@@ -151,7 +150,7 @@ class ForgottenPasswordRequestConfirm(co
                 'forgotpwd_change_passwd', use_email=data['use_email'],
                 revocation_id=data['revocation_id'], upassword=data['upassword'])
             cnx.commit()
-        raise Redirect(self._cw.build_url('pwdreset', __message=msg, __secure__=True))
+        raise Redirect(self._cw.build_url('pwdreset', __message=msg))
 
     def checked_data(self):
         cw = self._cw
diff --git a/debian/control b/debian/control
--- a/debian/control
+++ b/debian/control
@@ -13,7 +13,7 @@ Homepage: http://www.cubicweb.org/projec
 Package: cubicweb-forgotpwd
 Architecture: all
 Depends:
- python-cubicweb (>= 3.24),
+ python-cubicweb (>= 3.25),
  python-crypto,
  python-imaging,
  ${python:Depends},
diff --git a/test/unittest_notifications.py b/test/unittest_notifications.py
--- a/test/unittest_notifications.py
+++ b/test/unittest_notifications.py
@@ -20,25 +20,12 @@ class ForgotTC(CubicWebTC):
     def test_reset_password(self):
         MAILBOX[:] = []
         self.assertEqual(len(MAILBOX), 0)
+        self.config.global_set_option('base-url', 'http://babar.com/')
         with self.repo.internal_cnx() as cnx:
             cnx.call_service('forgotpwd_send_email', use_email=u'test_user1 at logilab.fr')
             cnx.commit()
         self.assertEqual(len(MAILBOX), 1)
-        self.assertNotIn('None', MAILBOX[0].content)
-
-    def test_reset_https(self):
-        MAILBOX[:] = []
-        self.config.global_set_option('base-url', 'http://babar.com/')
-        with self.repo.internal_cnx() as cnx:
-            cnx.call_service('forgotpwd_send_email', use_email=u'test_user2 at logilab.fr')
-            cnx.commit()
-        self.assertIn('http://babar.com/', MAILBOX[0].content)
-
-        self.config.global_set_option('https-url', 'https://babar.com/')
-        with self.repo.internal_cnx() as cnx:
-            cnx.call_service('forgotpwd_send_email', use_email=u'test_user3 at logilab.fr')
-            cnx.commit()
-        self.assertIn('https://babar.com/', MAILBOX[1].content)
+        self.assertIn('http://babar.com', MAILBOX[0].content)
 
 
 if __name__ == '__main__':



More information about the cubicweb-devel mailing list