raphael 3 years ago
parent
commit
50d86f6bb7

+ 7
- 1
.env.test View File

@@ -1,4 +1,10 @@
1
+APP_ENV=test
2
+APP_URL_PREFIX="/phoenix"
3
+APP_LANGUAGE="fr"
4
+
1 5
 # define your env variables for the test env here
2
-KERNEL_CLASS='Symfony\Component\HttpKernel\Kernel\AppKernel'
6
+KERNEL_CLASS='Logipro\Phoenix\Kernel\AppKernel'
3 7
 APP_SECRET='s$cretf0rt3st'
4 8
 SYMFONY_DEPRECATIONS_HELPER=999999
9
+
10
+DATABASE_TEST_URL="sqlite:///%kernel.project_dir%/var/app.db"

+ 6
- 1
composer.json View File

@@ -10,6 +10,11 @@
10 10
 			"Logipro\\Phoenix\\" : "src/Phoenix"
11 11
 		}
12 12
 	},
13
+	"autoload-dev": {
14
+        "psr-4": {
15
+            "Logipro\\Phoenix\\tests\\": "tests"
16
+        }
17
+    },
13 18
 	"require" : {
14 19
 		"symfony/flex" : "~1.1",
15 20
 		"symfony/console" : "~4.0",
@@ -43,7 +48,7 @@
43 48
 		"stripe/stripe-php": "^6.37",
44 49
 		"symfony/http-client": "~4.0",
45 50
 		"logipro/scormbundle": "dev-master",
46
-		"sensio/framework-extra-bundle": "^5.4",
51
+		"sensio/framework-extra-bundle": "^5.5",
47 52
 		"php-translation/symfony-bundle": "^0.9.1",
48 53
 		"wikimedia/composer-merge-plugin": "dev-master",
49 54
 		"symfony/filesystem": "~4.0"

+ 7
- 2
src/Phoenix/Component/PhxCrypt.php View File

@@ -6,7 +6,12 @@ class PhxCrypt
6 6
     private static $cryptPassword = "__Pas.s:Word_!/_";
7 7
     private static $cryptIV = '1234567812345678';
8 8
 
9
-    public static function crypt($data,$withDate = true)
9
+    protected static function serialize($data) : string
10
+    {
11
+        return serialize($data);
12
+    }
13
+
14
+    public static function crypt($data)
10 15
     {
11 16
         if (is_string($data))
12 17
         {
@@ -15,7 +20,7 @@ class PhxCrypt
15 20
         
16 21
         $data['_d_'] = time();
17 22
 
18
-        $data = serialize($data);
23
+        $data = self::serialize($data);
19 24
 		$openSslCrypt = openssl_encrypt($data, 'aes128',self::$cryptPassword,0,self::$cryptIV);
20 25
         return rtrim(strtr(($openSslCrypt), '+/', '-_'), '=');
21 26
     }

+ 9
- 1
src/Phoenix/Controller/LearningSpace/LoginController.php View File

@@ -15,6 +15,7 @@ use Logipro\Phoenix\Form\CatalogType\CatalogDefinePasswordType;
15 15
 use Logipro\Phoenix\Entity\Account\Constraints\Password\PasswordValidator;
16 16
 use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
17 17
 use Logipro\Phoenix\Service\LoginService;
18
+use Symfony\Component\HttpFoundation\Response;
18 19
 
19 20
 class LoginController extends LearningSpaceController
20 21
 {
@@ -103,15 +104,22 @@ class LoginController extends LearningSpaceController
103 104
 		}
104 105
 		$token = $request->get('token');
105 106
 
107
+		$tokenData = null;
108
+		if (!$token) {
109
+			throw $this->createNotFoundException($this->translate('error_403_message'));
110
+		}
106 111
 		$tokenData = PasswordRecoverNotifyLearner::decrytUrlArg($token);
107 112
 		if (!$tokenData) {
113
+
114
+			$response = new Response('',404);
115
+
108 116
 			// token expiré
109 117
 			$parameters = array(
110 118
 				'text' => $this->translate('ls_password_expired'),
111 119
 				'path' => 'ls_homepage',
112 120
 				'go' => $this->translate('ls_password_return')
113 121
 			);
114
-			return $this->phxRender('bundles/TwigBundle/Exception/definePassword.html.twig', $parameters);
122
+			return $this->phxRender('bundles/TwigBundle/Exception/definePassword.html.twig', $parameters, $response);
115 123
 		}
116 124
 
117 125
 		$respository = $this->getRepository(LearnerAccount::class);

+ 15
- 0
tests/Phoenix/Component/ExpiredPhxCrypt.php View File

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace Logipro\Phoenix\tests\Phoenix\Component;
4
+
5
+use Logipro\Phoenix\Component\PhxCrypt;
6
+
7
+class ExpiredPhxCrypt extends PhxCrypt
8
+{
9
+    protected static function serialize($data): string
10
+    {
11
+        $data['_d_'] = 0;
12
+        
13
+        return parent::serialize($data);
14
+    }
15
+}

+ 75
- 0
tests/Phoenix/Controller/LearningSpace/LoginControllerTest.php View File

@@ -0,0 +1,75 @@
1
+<?php
2
+
3
+namespace Logipro\Phoenix\tests\Phoenix\Controller\NewBackOffice;
4
+
5
+
6
+use Symfony\Component\Routing\Exception\RouteNotFoundException;
7
+use Logipro\Phoenix\EventSubscriber\LearningSpace\PasswordRecoverNotifyLearner;
8
+use Logipro\Phoenix\Component\PhxCrypt;
9
+use Logipro\Phoenix\tests\Phoenix\Component\ExpiredPhxCrypt;
10
+use Logipro\Phoenix\tests\PhxWebTestCase;
11
+
12
+class LoginControllerTest extends PhxWebTestCase
13
+{
14
+    public function testManageDefinePasswordWitoutToken()
15
+    {
16
+        $client = static::createClient();
17
+        $client->request('GET', $this->getRoutePath('ls_password_define'));
18
+        $this->assertEquals(404, $client->getResponse()->getStatusCode());
19
+    }
20
+
21
+    public function testManageDefinePasswordWithEmpty()
22
+    {
23
+        $client = static::createClient();
24
+
25
+        $parameters['token'] = '';
26
+        $client->request('GET', $this->getRoutePath('ls_password_define'), $parameters);
27
+
28
+        $this->assertEquals(404, $client->getResponse()->getStatusCode());
29
+    }
30
+
31
+    public function testManageDefinePasswordWithExpiredToken()
32
+    {
33
+        $client = static::createClient();
34
+
35
+        $tokenData = array(
36
+            'learnerAccountId' => 0,
37
+            'route' => 'ls_homepage'
38
+        );
39
+        $parameters['token'] = ExpiredPhxCrypt::crypt($tokenData);
40
+        $client->request('GET', $this->getRoutePath('ls_password_define'), $parameters);
41
+
42
+        $this->assertEquals(404, $client->getResponse()->getStatusCode());
43
+    }
44
+
45
+    public function testManageDefinePasswordWitoutLearnerAccount()
46
+    {
47
+        $client = static::createClient();
48
+
49
+        $tokenData = array(
50
+            'learnerAccountId' => 0,
51
+            'route' => 'ls_homepage'
52
+        );
53
+        $parameters['token'] = PhxCrypt::crypt($tokenData);
54
+        $client->request('GET', $this->getRoutePath('ls_password_define'), $parameters);
55
+        $this->assertEquals(404, $client->getResponse()->getStatusCode());
56
+    }
57
+
58
+
59
+    /**
60
+     * sera développé quand on aura les fixtures de dev dans cette branche
61
+     */
62
+    /*public function testManageDefinePasswordWithLearnerAccount()
63
+    {
64
+        $client = static::createClient();
65
+
66
+        $tokenData = array(
67
+            'learnerAccountId' => ,
68
+            'route' => 'ls_homepage'
69
+        );
70
+        $parameters['token'] = PhxCrypt::crypt($tokenData);
71
+        $client->request('GET', $this->getRoutePath('ls_password_define'), $parameters);
72
+
73
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());;
74
+    }*/
75
+}

+ 3
- 5
tests/Phoenix/Controller/NewBackOffice/Session/Follow/SessionFixedControllerTest.php View File

@@ -1,10 +1,8 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\Tests\Controller\NewBackOffice\Session\Follow;
2
+namespace Logipro\Phoenix\tests\Phoenix\Controller\NewBackOffice\Session\Follow;
3 3
 
4
-use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
5
-
6
-
7
-class SessionFiexedControllerTest extends WebTestCase
4
+use Logipro\Phoenix\tests\PhxWebTestCase;
5
+class SessionFiexedControllerTest extends PhxWebTestCase
8 6
 {  
9 7
 
10 8
     /*

+ 1
- 1
tests/Phoenix/Service/AuthTokenGeneratorTest.php View File

@@ -1,5 +1,5 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\tests\Service;
2
+namespace Logipro\Phoenix\tests\Phoenix\Service;
3 3
 
4 4
 use PHPUnit\Framework\TestCase;
5 5
 use Logipro\Phoenix\Service\AuthTokenGenerator;

+ 1
- 1
tests/Phoenix/Service/Comment/CommentHandlerTest.php View File

@@ -1,5 +1,5 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\Tests\Service\Comment;
2
+namespace Logipro\Phoenix\tests\Phoenix\Service\Comment;
3 3
 
4 4
 use PHPUnit\Framework\TestCase;
5 5
 use Logipro\Phoenix\Entity\Comment;

+ 1
- 1
tests/Phoenix/Service/FormHandlerTest.php View File

@@ -1,5 +1,5 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\Tests\Service;
2
+namespace Logipro\Phoenix\tests\Phoenix\Service;
3 3
 
4 4
 use Symfony\Component\Form\Test\TypeTestCase;
5 5
 

+ 1
- 1
tests/Phoenix/Service/SetupDocumentTest.php View File

@@ -1,5 +1,5 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\tests\Service;
2
+namespace Logipro\Phoenix\tests\Phoenix\Service;
3 3
 
4 4
 use PHPUnit\Framework\TestCase;
5 5
 use Logipro\Phoenix\Service\AuthTokenGenerator;

+ 1
- 1
tests/Phoenix/Tools/Tree/TreeWalkerTest.php View File

@@ -1,5 +1,5 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\Tests\Tools\Tree;
2
+namespace Logipro\Phoenix\tests\Phoenix\Tools\Tree;
3 3
 
4 4
 use PHPUnit\Framework\TestCase;
5 5
 use Logipro\Phoenix\Tools\Tree\TreeNode;

+ 30
- 0
tests/PhxWebTestCase.php View File

@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+namespace Logipro\Phoenix\tests;
4
+
5
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
+
7
+class PhxWebTestCase extends WebTestCase
8
+{ 
9
+    /**
10
+     * retourne le chemin d'une route à partir de son nom
11
+     * @param string
12
+     * 
13
+     * @return string
14
+     */
15
+    protected function getRoutePath($name): string
16
+    {
17
+        self::bootKernel();
18
+
19
+        // returns the real and unchanged service container
20
+        $container = self::$kernel->getContainer();
21
+
22
+        $router = $container->get('router');
23
+
24
+        $route = $router->getRouteCollection()->get($name);
25
+        if (!$route) {
26
+            throw new RouteNotFoundException('Aucune route ne correspond à ' . $name);
27
+        }
28
+        return $route->getPath();
29
+    }
30
+}

Loading…
Cancel
Save