Bug 37157

Summary: Error 500 when loading identity provider list
Product: Koha Reporter: Hammat wele <hammat.wele>
Component: System AdministrationAssignee: Hammat wele <hammat.wele>
Status: Pushed to oldstable --- QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: caroline.cyr-la-rose, david, fridolin.somers, gmcharlt, lucas, nick, philippe.blouin, wainuiwitikapark
Version: MainKeywords: additional_work_needed
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
This fixes the listing of identity providers (Administration > Additional parameters > Identity providers) when special characters are used in the configuration and mapping fields (such as "scope": "élève"). Previously, using special characters in these fields caused a 500 error when viewing the Administration > Identity providers page.
Version(s) released in:
24.11.00,24.05.02,23.11.07
Circulation function:
Attachments: Bug 37157: Fix Malformed UTF-8 character in JSON string before decode_json
Bug 37157: Fix Malformed UTF-8 character in JSON string before decode_json
Bug 37157: Fix Malformed UTF-8 character in JSON string before decode_json

Description Hammat wele 2024-06-21 16:39:08 UTC
When we add a new identity provider and put some special characters in the Config or Mapping field, we got 500 error when we list the identity providers
Comment 1 Hammat wele 2024-06-21 17:11:11 UTC
Created attachment 167974 [details] [review]
Bug 37157: Fix Malformed UTF-8 character in JSON string before decode_json

When we add a new identity provider and put some special characters in the Config or Mapping field, we got 500 error when we list the identity providers

To test:
1. Apply this patch.
2. Add a new identity provider
    2.1. fill the form
    2.2. click on «Add default Oauth configuration» and on «Add default Oauth mapping»
    2.3. put some special characters in Configuration and Mapping field
3. Save the form
=> Confirm the identity providers list is shown correctly

Also prove t/db_dependent/api/v1/provider.t.
Comment 2 David Nind 2024-06-24 08:08:28 UTC
Created attachment 168009 [details] [review]
Bug 37157: Fix Malformed UTF-8 character in JSON string before decode_json

When we add a new identity provider and put some special characters in the Config or Mapping field, we got 500 error when we list the identity providers

To test:
1. Apply this patch.
2. Add a new identity provider
    2.1. fill the form
    2.2. click on «Add default Oauth configuration» and on «Add default Oauth mapping»
    2.3. put some special characters in Configuration and Mapping field
3. Save the form
=> Confirm the identity providers list is shown correctly

Also prove t/db_dependent/api/v1/provider.t.

Signed-off-by: David Nind <david@davidnind.com>
Comment 3 David Nind 2024-06-24 08:10:07 UTC
Hi Hammat.

1. I used these values:

   OATH configuration: 
   ...
     "scope": "élève"
   ...

   OATH mapping:
   ...
     "surname": "élève"
   ...

Note: At the moment I can't edit a provider, so I will add a bug for that if there isn't one.
Comment 4 Hammat wele 2024-06-25 12:05:34 UTC
(In reply to David Nind from comment #3)
> Hi Hammat.

> Note: At the moment I can't edit a provider, so I will add a bug for that if
> there isn't one.

Hi David, 
you're right we can't also edit a provider. the form is empty and we got an error when submitting

> so I will add a bug for that if there isn't one.

Good idea
Comment 5 David Nind 2024-06-25 12:14:25 UTC
It's Bug 36276 - Cannot edit Identity Provider after creation (had already been created).
Comment 6 Nick Clemens (kidclamp) 2024-06-26 18:38:49 UTC
Created attachment 168176 [details] [review]
Bug 37157: Fix Malformed UTF-8 character in JSON string before decode_json

When we add a new identity provider and put some special characters in the Config or Mapping field, we got 500 error when we list the identity providers

To test:
1. Apply this patch.
2. Add a new identity provider
    2.1. fill the form
    2.2. click on «Add default Oauth configuration» and on «Add default Oauth mapping»
    2.3. put some special characters in Configuration and Mapping field
3. Save the form
=> Confirm the identity providers list is shown correctly

Also prove t/db_dependent/api/v1/provider.t.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 7 Nick Clemens (kidclamp) 2024-06-26 18:40:04 UTC
One issue is that if I create the provider before this request. this doesn't fix it. I have to delete them from the database in order to be able to load. Could we have a DB update to fix/encode existing values?
Comment 8 Katrin Fischer 2024-06-27 09:52:57 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 9 Lucas Gass (lukeg) 2024-07-19 14:34:44 UTC
Backported to 24.05.x for upcoming 24.05.02
Comment 10 Fridolin Somers 2024-07-22 09:41:50 UTC
Pushed to 23.11.x for 23.11.07
Comment 11 David Nind 2024-07-22 21:35:45 UTC
Have added a release note.

Is additional work still required? See comment #7.

I've added additional_work_needed - please remove if this is no longer the case.
Comment 12 Wainui Witika-Park 2024-09-17 03:33:49 UTC
Not backporting to 23.05.x unless requested