From 850c7faafe48aa3f928955023a469cad9196fc17 Mon Sep 17 00:00:00 2001
From: Patrick Uiterwijk <puiterwijk@redhat.com>
Date: Oct 11 2016 13:37:11 +0000
Subject: [PATCH 1/3] Fix OpenID Connect client updating


Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Reviewed-by: Pierre-Yves Chibon <pingou@pingoured.fr>

---

diff --git a/ipsilon/providers/openidc/admin.py b/ipsilon/providers/openidc/admin.py
index fb4bf5d..b4a70d6 100644
--- a/ipsilon/providers/openidc/admin.py
+++ b/ipsilon/providers/openidc/admin.py
@@ -106,7 +106,7 @@ class ClientAdminPage(AdminPage):
                                    (name, value), severity=logging.DEBUG)
                 new_db_values[name] = value
 
-        client_id = kwargs['Client ID']
+        client_id = kwargs.get('Client ID')
         if self.new_client and client_id:
             if re.search(INVALID_IN_CLIENT_ID, client_id):
                 message = 'Invalid character in client ID'
diff --git a/ipsilon/providers/openidc/store.py b/ipsilon/providers/openidc/store.py
index 9e0a315..21d5354 100644
--- a/ipsilon/providers/openidc/store.py
+++ b/ipsilon/providers/openidc/store.py
@@ -62,8 +62,8 @@ class OpenIDCStore(Store):
             del client['ipsilon_internal']['client_id']
 
         info = {}
-        for key, datum in client:
-            info[key] = json.loads(datum)
+        for key in client:
+            info[key] = json.dumps(client[key])
 
         if client_id.startswith('D-'):
             # This is a dynamically registered client
@@ -71,7 +71,7 @@ class OpenIDCStore(Store):
             self.save_unique_data('client', {client_id: info})
         else:
             # This is a statically configured client
-            self.static_store.save_options('client', {client_id: info})
+            self.static_store.save_options('client', client_id, info)
 
     def getDynamicClients(self):
         clients = {}

From 6af1b82956f0d516cec7142d77d3d2c5b69c66a6 Mon Sep 17 00:00:00 2001
From: Patrick Uiterwijk <puiterwijk@redhat.com>
Date: Oct 11 2016 13:37:13 +0000
Subject: [PATCH 2/3] Add test helper for general settings updates


Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Reviewed-by: Pierre-Yves Chibon <pingou@pingoured.fr>

---

diff --git a/tests/helpers/http.py b/tests/helpers/http.py
index 2fad577..6c5bf09 100755
--- a/tests/helpers/http.py
+++ b/tests/helpers/http.py
@@ -475,6 +475,30 @@ class HttpSessions(object):
         if r.status_code != 200:
             raise ValueError('Failed to post IDP data [%s]' % repr(r))
 
+    def update_options(self, idp, relurl, options):
+        """
+        Update options on a specific page.
+
+        relurl must be the relative url to the admin page, not starting with /.
+
+        options must be a dict of options to change.
+        """
+        idpsrv = self.servers[idp]
+        idpuri = idpsrv['baseuri']
+
+        url = '%s%s/admin/%s' % (
+            idpuri, self.get_idp_uri(idp), relurl)
+        headers = {'referer': url}
+        r = idpsrv['session'].post(url, data=options, headers=headers)
+        if r.status_code != 200:
+            raise ValueError('Failed to update settings [%s]' % repr(r))
+        if not 'alert alert-success' in r.text:
+            raise Exception('No success message returned')
+        for key in options:
+            if options[key] not in r.text:
+                raise Exception('Option value %s (key %s) not found' %
+                                (options[key], key))
+
     def enable_plugin(self, idp, plugtype, plugin):
         """
         Enable a login stack plugin.

From 2cd0142139d4d9c9acdab63a08eb715e98a0f323 Mon Sep 17 00:00:00 2001
From: Patrick Uiterwijk <puiterwijk@redhat.com>
Date: Oct 11 2016 13:37:15 +0000
Subject: [PATCH 3/3] Test OpenID Connect client updating


Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Reviewed-by: Pierre-Yves Chibon <pingou@pingoured.fr>

---

diff --git a/tests/helpers/http.py b/tests/helpers/http.py
index 6c5bf09..d17de7e 100755
--- a/tests/helpers/http.py
+++ b/tests/helpers/http.py
@@ -492,7 +492,7 @@ class HttpSessions(object):
         r = idpsrv['session'].post(url, data=options, headers=headers)
         if r.status_code != 200:
             raise ValueError('Failed to update settings [%s]' % repr(r))
-        if not 'alert alert-success' in r.text:
+        if 'alert alert-success' not in r.text:
             raise Exception('No success message returned')
         for key in options:
             if options[key] not in r.text:
diff --git a/tests/openidc.py b/tests/openidc.py
index 8f06a4d..a7c350d 100755
--- a/tests/openidc.py
+++ b/tests/openidc.py
@@ -262,6 +262,17 @@ if __name__ == '__main__':
         sys.exit(1)
     print " SUCCESS"
 
+    print "openidc: Update first SP client name ...",
+    try:
+        sess.update_options(
+            idpname,
+            'providers/openidc/admin/client/%s' % reg_resp['client_id'],
+            {'Client Name': 'Test suite client updated'})
+    except ValueError, e:
+        print >> sys.stderr, " ERROR: %s" % repr(e)
+        sys.exit(1)
+    print " SUCCESS"
+
     print "openidc: Retrieving token info ...",
     try:
         # Testing token without client auth

