From d9a27ebb9975ce9c496dcfa73aa4cc2e4975aadd Mon Sep 17 00:00:00 2001
From: vrioux <vrioux@ctech.ca>
Date: Wed, 28 Sep 2016 08:52:28 -0400
Subject: [PATCH] first try at writing tests

---
 .../consent/lib/Auth/Process/ConsentTest.php  | 109 ++++++++++++++++++
 1 file changed, 109 insertions(+)
 create mode 100644 tests/modules/consent/lib/Auth/Process/ConsentTest.php

diff --git a/tests/modules/consent/lib/Auth/Process/ConsentTest.php b/tests/modules/consent/lib/Auth/Process/ConsentTest.php
new file mode 100644
index 000000000..fdc0accd9
--- /dev/null
+++ b/tests/modules/consent/lib/Auth/Process/ConsentTest.php
@@ -0,0 +1,109 @@
+<?php
+/**
+ * Test for the consent:Process filter.
+ *
+ * @author Vincent Rioux <vrioux@ctech.ca>
+ * @package SimpleSAMLphp
+ */
+
+namespace SimpleSAML\Test\Module\consent\Auth\Process;
+
+
+class ProcessTest extends \PHPUnit_Framework_TestCase
+{
+
+    /*
+     * Helper function to run the filter with a given configuration.
+     *
+     * @param array $config  The filter configuration.
+     * @param array $request  The request state.
+     * @return array  The state array after processing.
+     */
+    private function processFilter(array $config, array $request)
+    {
+        //$filter = new \SimpleSAML\Module\saml\consent\Process\FilterScopes($config, null);
+        $filter = new sspmod_consent_Auth_Process_Consent($config, null);
+        $filter->process($request);
+        return $request;
+    }
+
+
+    /**
+     * Test valid consent disable.
+     */
+    public function testValidConsentDisableRegex()
+    {
+        // test consent disable regex with match
+        $config = array(
+            'consent.disable' => array(
+                'type'=>'regex', 'pattern'=>'/.*\.example\.org.*/i',
+            ),
+        );
+        $request = array(
+            'Source'     => array(
+                'SingleSignOnService' => array(
+                    array(
+                        'Binding'  => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
+                        'Location' => 'https://www.example.org/saml2/idp/SSOService.php',
+                    ),
+                ),
+            ),
+            'Attributes' => array(
+                'eduPersonPrincipalName' => array('jdoe@example.com'),
+            ),
+        );
+        $result = $this->processFilter($config, $request);
+        $this->assertEquals($request['Attributes'], $result['Attributes']);
+
+        // test consent disable regex without match
+        $config = array(
+            'consent.disable' => array(
+                'type'=>'regex', 'pattern'=>'/.*\.otherexample\.org.*/i',
+            ),
+        );
+        $request = array(
+            'Source'     => array(
+                'SingleSignOnService' => array(
+                    array(
+                        'Binding'  => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
+                        'Location' => 'https://www.example.org/saml2/idp/SSOService.php',
+                    ),
+                ),
+            ),
+            'Attributes' => array(
+                'eduPersonPrincipalName' => array('jdoe@example.com'),
+            ),
+        );
+        $result = $this->processFilter($config, $request);
+        $this->assertEquals(array(), $result['Attributes']);
+    }
+
+
+    /**
+     * Test invalid consent disable.
+     */
+    public function testInvalidConsentDisable()
+    {
+        // test consent disable regex with wrong value format in config
+        $config = array(
+            'consent.disable' => array(
+                'type'=>'regex', '/.*\.example\.org.*/i',
+            ),
+        );
+        $request = array(
+            'Source'     => array(
+                'SingleSignOnService' => array(
+                    array(
+                        'Binding'  => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
+                        'Location' => 'https://www.example.org/saml2/idp/SSOService.php',
+                    ),
+                ),
+            ),
+            'Attributes' => array(
+                'eduPersonPrincipalName' => array('jdoe@example.com'),
+            ),
+        );
+        $result = $this->processFilter($config, $request);
+        $this->assertEquals(array(), $result['Attributes']);
+    }
+}
-- 
GitLab