From 21f2e7839e67e4d9ad31583259ec2ceb2a19b043 Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tvdijen@gmail.com>
Date: Fri, 26 Jan 2018 23:22:10 +0100
Subject: [PATCH] Add tests for parseNameIdPolicy

---
 .../SimpleSAML/Utils/Config/MetadataTest.php  | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php b/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php
index 98ffb7f0b..afcbb611e 100644
--- a/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php
+++ b/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php
@@ -259,4 +259,44 @@ class MetadataTest extends TestCase
             ),
         )));
     }
+
+    
+    /**
+     * Test \SimpleSAML\Utils\Config\Metadata::parseNameIdPolicy().
+     */
+    public function testParseNameIdPolicy()
+    {
+        // Test null or unset
+        $nameIdPolicy = null;
+        $this->assertEquals(Metadata::parseNameIdPolicy($nameIdPolicy), array('Format' => \SAML2\Constants::NAMEID_TRANSIENT));
+
+        // Test false
+        $nameIdPolicy = false;
+        $this->assertEquals(Metadata::parseNameIdPolicy($nameIdPolicy), null);
+
+        // Test string
+        $nameIdPolicy = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress';
+        $this->assertEquals(Metadata::parseNameIdPolicy($nameIdPolicy), array('Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'));
+
+        // Test array
+        $nameIdPolicy = array(
+            'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:persistent',
+            'AllowCreate' => false
+        );
+        $this->assertEquals(Metadata::parseNameIdPolicy($nameIdPolicy), array(
+            'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:persistent',
+            'AllowCreate' => false
+        ));
+
+        $nameIdPolicy = array(
+            'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:persistent',
+            'AllowCreate' => false,
+            'SPNameQualifier' => 'TEST'
+        );
+        $this->assertEquals(Metadata::parseNameIdPolicy($nameIdPolicy), array(
+            'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:persistent',
+            'AllowCreate' => false,
+            'SPNameQualifier' => 'TEST'
+        ));
+    }
 }
-- 
GitLab