You can instantiate the same SamlService service twice in a request when doing phpunit testing. Attached patch fixes the problem and is harmless.

Comments

moshe weitzman created an issue. See original summary.

moshe weitzman’s picture

StatusFileSize
new587 bytes

Woops - wrong line

moshe weitzman’s picture

StatusFileSize
new488 bytes
piggito’s picture

Status: Needs review » Reviewed & tested by the community

LGTM to validate constant to be not defined before setting value.
Ideally onelogin/php-saml should provide a setting parameter for cert folders but right now constant is the only way as explained at https://github.com/onelogin/php-saml/issues/231#issuecomment-312939684
Therefore IMO this is RTBC.

roderik’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! About time this got committed.

This is not exactly the right way if we want to keep the exact same behavior though. We don't want to enter the "else" condition and set variables that were otherwise not set, if the constant happens to be defined already.

I'm committing this:

--- a/src/SamlService.php
+++ b/src/SamlService.php
@@ -403,7 +403,9 @@ class SamlService {
     $cert_folder = $config->get('sp_cert_folder');
     if ($cert_folder) {
       // Set the folder so the Simple SAML toolkit knows where to look.
-      define('ONELOGIN_CUSTOMPATH', "$cert_folder/");
+      if (!defined('ONELOGIN_CUSTOMPATH')) {
+        define('ONELOGIN_CUSTOMPATH', "$cert_folder/");
+      }
     }
     else {
       $sp_cert = $config->get('sp_x509_certificate');

  • roderik committed 4a121a5 on 8.x-3.x authored by moshe weitzman
    Issue #3064958 by moshe weitzman, piggito, roderik: Drupal\Core\Entity\...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.