From c6d43867a981bf0246d09403421110066df7f9df Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Thu, 7 Mar 2019 17:36:43 +0100
Subject: [PATCH] iparapheur: don't pass explicit parameters to transport
 (#31226)

---
 .../migrations/0006_auto_20190307_1805.py     | 30 +++++++++++++++++++
 passerelle/contrib/iparapheur/models.py       |  6 ++--
 passerelle/contrib/iparapheur/soap.py         | 15 ++--------
 tests/test_iparapheur.py                      |  4 +--
 4 files changed, 37 insertions(+), 18 deletions(-)
 create mode 100644 passerelle/contrib/iparapheur/migrations/0006_auto_20190307_1805.py

diff --git a/passerelle/contrib/iparapheur/migrations/0006_auto_20190307_1805.py b/passerelle/contrib/iparapheur/migrations/0006_auto_20190307_1805.py
new file mode 100644
index 0000000..c9d977c
--- /dev/null
+++ b/passerelle/contrib/iparapheur/migrations/0006_auto_20190307_1805.py
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-03-07 17:05
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('iparapheur', '0005_remove_iparapheur_log_level'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='iparapheur',
+            old_name='password',
+            new_name='basic_auth_password',
+        ),
+        migrations.RenameField(
+            model_name='iparapheur',
+            old_name='username',
+            new_name='basic_auth_username',
+        ),
+        migrations.RenameField(
+            model_name='iparapheur',
+            old_name='keystore',
+            new_name='client_certificate',
+        ),
+    ]
diff --git a/passerelle/contrib/iparapheur/models.py b/passerelle/contrib/iparapheur/models.py
index 581a2de..c3d7248 100644
--- a/passerelle/contrib/iparapheur/models.py
+++ b/passerelle/contrib/iparapheur/models.py
@@ -72,11 +72,11 @@ class IParapheur(BaseResource):
             help_text=_('WSDL URL'))
     verify_cert = models.BooleanField(default=True,
             verbose_name=_('Check HTTPS Certificate validity'))
-    username = models.CharField(max_length=128, blank=True,
+    basic_auth_username = models.CharField(max_length=128, blank=True,
             verbose_name=_('Username'))
-    password = models.CharField(max_length=128, blank=True,
+    basic_auth_password = models.CharField(max_length=128, blank=True,
             verbose_name=_('Password'))
-    keystore = models.FileField(upload_to='iparapheur', null=True, blank=True,
+    client_certificate = models.FileField(upload_to='iparapheur', null=True, blank=True,
             verbose_name=_('Keystore'),
             help_text=_('Certificate and private key in PEM format'))
 
diff --git a/passerelle/contrib/iparapheur/soap.py b/passerelle/contrib/iparapheur/soap.py
index c37ffd2..f007a79 100644
--- a/passerelle/contrib/iparapheur/soap.py
+++ b/passerelle/contrib/iparapheur/soap.py
@@ -50,23 +50,12 @@ class Transport(HttpAuthenticated):
         self.model = model
         HttpAuthenticated.__init__(self, **kwargs)
 
-    def get_requests_kwargs(self):
-        kwargs = {}
-        if self.model.username:
-            kwargs['auth'] = (self.model.username, self.model.password)
-        if self.model.keystore:
-            kwargs['cert'] = (self.model.keystore.path, self.model.keystore.path)
-        if not self.model.verify_cert:
-            kwargs['verify'] = False
-        return kwargs
-
     def open(self, request):
         # only use our custom handler to fetch service resources, not schemas
         # from other namespaces
         if 'www.w3.org' in request.url:
             return HttpAuthenticated.open(self, request)
-        resp = self.model.requests.get(request.url, headers=request.headers,
-                **self.get_requests_kwargs())
+        resp = self.model.requests.get(request.url, headers=request.headers)
         return StringIO.StringIO(resp.content)
 
     def send(self, request):
@@ -74,7 +63,7 @@ class Transport(HttpAuthenticated):
         self.addcredentials(request)
         try:
             resp = self.model.requests.post(request.url, data=request.message,
-                headers=request.headers, **self.get_requests_kwargs())
+                headers=request.headers)
         except(RequestException,) as e:
             raise TransportError(e.message.message, None)
 
diff --git a/tests/test_iparapheur.py b/tests/test_iparapheur.py
index 9a6ae47..0879318 100644
--- a/tests/test_iparapheur.py
+++ b/tests/test_iparapheur.py
@@ -32,8 +32,8 @@ def conn():
                     keytype='API',
                     key=API_KEY)
     conn = IParapheur.objects.create(title='parapheur', slug='parapheur',
-                                     wsdl_url=WSDL_URL, username='test',
-                                     password='secret')
+                                     wsdl_url=WSDL_URL, basic_auth_username='test',
+                                     basic_auth_password='secret')
     obj_type = ContentType.objects.get_for_model(IParapheur)
     AccessRight.objects.create(codename='can_access',
                     apiuser=api, resource_type=obj_type,
-- 
2.20.1

