From f200d254a070a6cb18ebf21cad0a264c03047fc5 Mon Sep 17 00:00:00 2001
From: xdrm-brackets
Date: Sat, 13 Feb 2016 17:28:28 +0100
Subject: [PATCH] - [x] [phpunit/sessionManager] test unitaires du manager de
session php
---
manager/ManagerError.php | 23 +-
manager/module/userDefault.php | 37 ++-
phpunit/coverage/Database.php.html | 124 ++++-----
phpunit/coverage/ManagerError.php.html | 177 +++++++------
phpunit/coverage/ResourceDispatcher.php.html | 84 +++----
phpunit/coverage/autoloader.php.html | 14 +-
phpunit/coverage/index.dashboard.html | 12 +-
phpunit/coverage/index.html | 86 +++----
phpunit/coverage/sessionManager.php.html | 178 ++++++-------
phpunit/phpunit.xml | 10 +-
phpunit/tests/Database_check.php | 4 +-
phpunit/tests/Database_construct.php | 4 +-
phpunit/tests/Database_delNumeric.php | 4 +-
phpunit/tests/ManagerError.php | 107 ++++++++
phpunit/tests/sessionManager.php | 251 +++++++++++++++++++
todo.md | 1 +
16 files changed, 769 insertions(+), 347 deletions(-)
create mode 100644 phpunit/tests/ManagerError.php
create mode 100644 phpunit/tests/sessionManager.php
diff --git a/manager/ManagerError.php b/manager/ManagerError.php
index 1988718..c85d962 100755
--- a/manager/ManagerError.php
+++ b/manager/ManagerError.php
@@ -41,18 +41,24 @@
// Erreur de parametre(s)
const ParamError = 9;
+ // Erreur dans le traitement
+ const ModuleError = 10;
+
/* Repo */
// Verification de la coherence du chemin (existe dans la conf)
- const WrongPathRepo = 10;
+ const WrongPathRepo = 11;
// Module non specifie dans la conf
- const UnknownRepo = 11;
+ const UnknownRepo = 12;
+
+ // Erreur dans le traitement
+ const RepoError = 13;
/* Database */
// Erreur lors de la creation d'un objet PDO (connection)
- const PDOConnection = 12;
+ const PDOConnection = 14;
/* EXPLICITE UN CODE D'ERREUR
@@ -65,7 +71,9 @@
public static function explicit($error){
switch($error){
case self::Success: return "Tout s'est bien deroule"; break;
+
case self::ParsingFailed: return "La lecture du fichier JSON a echoue"; break;
+
case self::InvalidFlags: return "Les specifications (drapeaux) sont incorrects"; break;
case self::UnreachableResource: return "La ressource n'existe pas (404)"; break;
case self::MissingPath: return "Le chemin de delegation n'a pas ete renseigne"; break;
@@ -75,13 +83,18 @@
case self::UnknownRepo: return "Le repo n'existe pas"; break;
case self::UnknownMethod: return "Le methode n'existe pas"; break;
case self::UncallableMethod: return "Le methode n'est pas amorcable"; break;
+
case self::ParamError: return "Un ou plusieurs parametres sont manquants ou incorrects"; break;
+ case self::ModuleError: return "Erreur lors du traitement du module"; break;
+ case self::RepoError: return "Erreur lors du traitement du repo"; break;
+
case self::PDOConnection: return "La connexion avec la base de donnees a echoue"; break;
- default: return "Erreur inconnue..."; break;
+ // default: return "Erreur inconnue..."; break;
}
- return 'Aucune erreur trouvee';
+ // Erreur inconnue
+ return null;
}
}
diff --git a/manager/module/userDefault.php b/manager/module/userDefault.php
index a59e21a..db5885d 100755
--- a/manager/module/userDefault.php
+++ b/manager/module/userDefault.php
@@ -52,10 +52,41 @@
return array('ModuleError' => \manager\ManagerError::ParamError);
- // $request = new \manager\Repo('user/create', array($code, $username, $firstname, $lastname, $mail, $password, $status) );
+ /* [2] Creation de l'utilisateur
+ =========================================================*/
+ $create_user = new \manager\Repo('user/create', array($code, $username, $firstname, $lastname, $mail, $password_hash, $status) );
+ $id_user = $create_user->answer();
- // return $request->answer();
- return array('ModuleError' => \manager\ManagerError::Success);
+ // Si une erreur est retournee, on retourne une erreur
+ if( $id_user === false )
+ return array('ModuleError' => \manager\ManagerError::ModuleError);
+
+
+ /* [3] Creation du groupe de meme nom que l'username
+ =========================================================*/
+ $create_group = new \manager\Repo('group/create', array($username) );
+ $id_group = $create_group->answer();
+
+ // Si une erreur est retournee, on retourne une erreur
+ if( $id_group === false )
+ return array('ModuleError' => \manager\ManagerError::ModuleError);
+
+
+ /* [4] Association au groupe
+ =========================================================*/
+ $assoc_goup = new \manager\Repo('group/associate', array($id_user, $id_group));
+ $id_assoc = $assoc_goup->answer();
+
+ // Si une erreur est retournee, on retourne une erreur
+ if( $id_assoc === false )
+ return array('ModuleError' => \manager\ManagerError::ModuleError);
+
+ /* [5] Gestion du retour
+ =========================================================*/
+ return array(
+ 'ModuleError' => \manager\ManagerError::Success,
+ 'id_user' => $id_user
+ );
}
diff --git a/phpunit/coverage/Database.php.html b/phpunit/coverage/Database.php.html
index 7adfff1..c33edbe 100755
--- a/phpunit/coverage/Database.php.html
+++ b/phpunit/coverage/Database.php.html
@@ -220,47 +220,47 @@
| |
| |
| public function __construct($host, $dbname, $username, $password){ |
- | $this->host = $host; |
- | $this->dbname = $dbname; |
- | $this->username = $username; |
- | $this->password = $password; |
+ | $this->host = $host; |
+ | $this->dbname = $dbname; |
+ | $this->username = $username; |
+ | $this->password = $password; |
| |
| try{ |
- | self::$pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->dbname, $this->username, $this->password); |
+ | self::$pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->dbname, $this->username, $this->password); |
| |
| // On signale que tout s'est bien passe |
- | self::$error = \manager\ManagerError::Success; |
+ | self::$error = \manager\ManagerError::Success; |
| |
- | }catch(Exception $e){ |
+ | }catch(Exception $e){ |
| // On signale qu'il y a une erreur |
| self::$error = \manager\ManagerError::PDOConnection; |
| } |
- | } |
+ | } |
| |
| |
| /* retourne une instance de la classe */ |
| public static function getInstance(){ |
- | if( self::$instance == null || self::$error != \manager\ManagerError::Success ){ // Si aucune instance existante OU erreur de connection |
+ | if( self::$instance == null || self::$error != \manager\ManagerError::Success ){ // Si aucune instance existante OU erreur de connection |
| |
| // chargement de la configuration du server SQL |
- | if( !isset($_SERVER['HTTP_HOST']) || isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'stefproject' ) |
- | $conf = json_decode( ResourceDispatcher::getResource(self::$config_path['local']), true ); |
+ | if( !isset($_SERVER['HTTP_HOST']) || isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'stefproject' ) |
+ | $conf = json_decode( ResourceDispatcher::getResource(self::$config_path['local']), true ); |
| else |
| $conf = json_decode( ResourceDispatcher::getResource(self::$config_path['remote']), true ); |
| |
| // creation de l'instance en fonction des parametres |
- | self::$instance = new DataBase($conf['host'], $conf['dbname'], $conf['user'], $conf['password']); |
+ | self::$instance = new DataBase($conf['host'], $conf['dbname'], $conf['user'], $conf['password']); |
| |
- | } |
+ | } |
| |
- | return self::$instance; |
+ | return self::$instance; |
| } |
| |
| /* retourne la connection statique */ |
| public static function getPDO(){ |
- | $instance = self::getInstance(); |
+ | $instance = self::getInstance(); |
| |
- | return self::$pdo; |
+ | return self::$pdo; |
| } |
| |
| |
@@ -273,9 +273,9 @@
| |
| public function getConfig(){ |
| return array( |
- | 'host' => $this->host, |
- | 'username' => $this->username |
- | ); |
+ | 'host' => $this->host, |
+ | 'username' => $this->username |
+ | ); |
| } |
| |
| |
@@ -303,54 +303,54 @@
| * |
| */ |
| public static function delNumeric($fetchData, $oneDimension=false){ |
- | $nextEquivalent = false; // Vaut VRAI si le prochain est peut-etre un equivalent numerique |
+ | $nextEquivalent = false; // Vaut VRAI si le prochain est peut-etre un equivalent numerique |
| |
| /* [1] 2 dimensions |
| ===============================================*/ |
- | if( !$oneDimension && is_array($fetchData[0]) ){ |
+ | if( !$oneDimension && is_array($fetchData[0]) ){ |
| |
| // on supprime les doublons des entrées (indice numérique) |
- | for( $i = 0 ; $i < count($fetchData) ; $i++ ) // pour tout les utilisateurs |
- | foreach($fetchData[$i] as $col => $val){ // pour toutes les entrées |
+ | for( $i = 0 ; $i < count($fetchData) ; $i++ ) // pour tout les utilisateurs |
+ | foreach($fetchData[$i] as $col => $val){ // pour toutes les entrées |
| |
- | if( !mb_detect_encoding($val, 'UTF-8') ) |
- | $fetchData[$i][$col] = utf8_encode($val); |
+ | if( !mb_detect_encoding($val, 'UTF-8') ) |
+ | $fetchData[$i][$col] = utf8_encode($val); |
| |
- | if( is_int($col) ){ // Si indice numerique |
+ | if( is_int($col) ){ // Si indice numerique |
| if( $nextEquivalent ) // Si suit un indice textuel |
- | unset( $fetchData[$i][$col] ); // on supprime l'indice |
+ | unset( $fetchData[$i][$col] ); // on supprime l'indice |
| |
- | $nextEquivalent = false; // Dans tous les cas, on dit que le prochain ne pourra pas etre supprime si numerique |
+ | $nextEquivalent = false; // Dans tous les cas, on dit que le prochain ne pourra pas etre supprime si numerique |
| |
- | }else // Si l'indice n'est pas un entier |
- | $nextEquivalent = true; // On signale qu'il y aura peut etre un indice numerique suivant |
+ | }else // Si l'indice n'est pas un entier |
+ | $nextEquivalent = true; // On signale qu'il y aura peut etre un indice numerique suivant |
| |
- | } |
+ | } |
| |
| /* [2] 1 dimensions |
| ===============================================*/ |
- | }else{ |
+ | }else{ |
| |
| // on supprime les doublons des entrées (indice numérique) |
- | foreach($fetchData as $i=>$val){ // pour toutes les entrées |
+ | foreach($fetchData as $i=>$val){ // pour toutes les entrées |
| |
- | if( !mb_detect_encoding($val, 'UTF-8') ) |
- | $fetchData[$i] = utf8_encode($val); |
+ | if( !mb_detect_encoding($val, 'UTF-8') ) |
+ | $fetchData[$i] = utf8_encode($val); |
| |
- | if( is_int($i) ){ // Si indice numerique |
+ | if( is_int($i) ){ // Si indice numerique |
| if( $nextEquivalent ) // Si suit un indice textuel |
- | unset( $fetchData[$i] ); // on supprime l'indice |
+ | unset( $fetchData[$i] ); // on supprime l'indice |
| |
- | $nextEquivalent = false; // Dans tous les cas, on dit que le prochain ne pourra pas etre supprime si numerique |
+ | $nextEquivalent = false; // Dans tous les cas, on dit que le prochain ne pourra pas etre supprime si numerique |
| |
- | }else // Si l'indice n'est pas un entier |
- | $nextEquivalent = true; // On signale qu'il y aura peut etre un indice numerique suivant |
+ | }else // Si l'indice n'est pas un entier |
+ | $nextEquivalent = true; // On signale qu'il y aura peut etre un indice numerique suivant |
| |
- | } |
+ | } |
| |
| } |
| |
- | return $fetchData; |
+ | return $fetchData; |
| } |
| |
| |
@@ -374,41 +374,41 @@
| * |
| */ |
| public static function check($type, $value){ |
- | $checker = !is_null($value); |
+ | $checker = !is_null($value); |
| |
| switch($type){ |
| /* (1) Global */ |
- | case 'auto_increment_id': |
- | return $checker && is_numeric($value) && $value <= 2147483647 && $value >= -2147483647; |
+ | case 'auto_increment_id': |
+ | return $checker && is_numeric($value) && $value <= 2147483647 && $value >= -2147483647; |
| break; |
| |
| /* (2) Utilisateur */ |
- | case 'user.code': |
- | case 'machine.code': |
- | return $checker && is_string($value) && preg_match('/^[\dA-F]{2}(\-[\dA-F]{2}){3,5}$/i', $value); |
+ | case 'user.code': |
+ | case 'machine.code': |
+ | return $checker && is_string($value) && preg_match('/^[\dA-F]{2}(\-[\dA-F]{2}){3,5}$/i', $value); |
| break; |
| |
- | case 'user.username': |
- | case 'machine.name': |
- | case 'group.name': |
- | return $checker && is_string($value) && preg_match('/^[\w-]{1,30}$/i', $value); |
+ | case 'user.username': |
+ | case 'machine.name': |
+ | case 'group.name': |
+ | return $checker && is_string($value) && preg_match('/^[\w-]{1,30}$/i', $value); |
| break; |
| |
- | case 'user.firstname': |
- | case 'user.lastname': |
- | return $checker && is_string($value) && preg_match('/^[a-z -]{3,30}$/i', $value); |
+ | case 'user.firstname': |
+ | case 'user.lastname': |
+ | return $checker && is_string($value) && preg_match('/^[a-z -]{3,30}$/i', $value); |
| break; |
| |
- | case 'user.mail': |
- | return $checker && is_string($value) && strlen($value) <= 50 && preg_match('/^[\w\.-]+@[\w\.-]+\.[a-z]{2,4}$/i', $value); |
+ | case 'user.mail': |
+ | return $checker && is_string($value) && strlen($value) <= 50 && preg_match('/^[\w\.-]+@[\w\.-]+\.[a-z]{2,4}$/i', $value); |
| break; |
| |
- | case 'user.password': |
- | return $checker && is_string($value) && preg_match('/^[\da-f]{40}$/i', $value); |
+ | case 'user.password': |
+ | return $checker && is_string($value) && preg_match('/^[\da-f]{40}$/i', $value); |
| break; |
| |
- | case 'user.status': |
- | return $checker && is_numeric($value) && floor($value) == $value && $value >= 0 && $value <= 100; |
+ | case 'user.status': |
+ | return $checker && is_numeric($value) && floor($value) == $value && $value >= 0 && $value <= 100; |
| break; |
| |
| } |
@@ -431,7 +431,7 @@
Dead Code
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016.
diff --git a/phpunit/coverage/ManagerError.php.html b/phpunit/coverage/ManagerError.php.html
index dc2e9fe..6c9d4f8 100644
--- a/phpunit/coverage/ManagerError.php.html
+++ b/phpunit/coverage/ManagerError.php.html
@@ -41,66 +41,66 @@
- Total |
-
-
+ Total |
+
|
- 0.00% |
- 0 / 1 |
-
-
+ 100.00% |
+ 1 / 1 |
+
|
- 0.00% |
- 0 / 1 |
- CRAP |
-
-
+ 100.00% |
+ 1 / 1 |
+ CRAP |
+
|
- 0.00% |
- 0 / 14 |
+ 100.00% |
+ 16 / 16 |
| | |
- ManagerError |
-
-
+ ManagerError |
+
|
- 0.00% |
- 0 / 1 |
-
-
+ 100.00% |
+ 1 / 1 |
+
|
- 0.00% |
- 0 / 1 |
- 182 |
-
-
+ 100.00% |
+ 1 / 1 |
+ 16 |
+
|
- 0.00% |
- 0 / 14 |
+ 100.00% |
+ 16 / 16 |
| | |
- explicit($error) |
-
-
+ explicit($error) |
+
|
- 0.00% |
- 0 / 1 |
- 182 |
-
-
+ 100.00% |
+ 1 / 1 |
+ 16 |
+
|
- 0.00% |
- 0 / 14 |
+ 100.00% |
+ 16 / 16 |
| |
@@ -148,50 +148,67 @@
| // Methode inamorcable |
| const UncallableMethod = 8; |
| |
- | /* Repo */ |
- | |
- | // Verification de la coherence du chemin (existe dans la conf) |
- | const WrongPathRepo = 9; |
- | |
- | // Module non specifie dans la conf |
- | const UnknownRepo = 10; |
+ | // Erreur de parametre(s) |
+ | const ParamError = 9; |
+ | |
+ | // Erreur dans le traitement |
+ | const ModuleError = 10; |
+ | |
+ | /* Repo */ |
| |
- | /* Database */ |
- | |
- | // Erreur lors de la creation d'un objet PDO (connection) |
- | const PDOConnection = 11; |
- | |
+ | // Verification de la coherence du chemin (existe dans la conf) |
+ | const WrongPathRepo = 11; |
+ | |
+ | // Module non specifie dans la conf |
+ | const UnknownRepo = 12; |
| |
- | /* EXPLICITE UN CODE D'ERREUR |
- | * |
- | * @error<Integer> Code d'erreur |
- | * |
- | * @return explicit<String> Description explicite du code d'erreur |
- | * |
- | */ |
- | public static function explicit($error){ |
- | switch($error){ |
- | case self::Success: return "Tout s'est bien deroule"; break; |
- | case self::ParsingFailed: return "La lecture du fichier JSON a echoue"; break; |
- | case self::InvalidFlags: return "Les specifications (drapeaux) sont incorrects"; break; |
- | case self::UnreachableResource: return "La ressource n'existe pas (404)"; break; |
- | case self::MissingPath: return "Le chemin de delegation n'a pas ete renseigne"; break; |
- | case self::WrongPathModule: return "Le chemin de delegation est incorrect ('nomModule/nomMethode')"; break; |
- | case self::WrongPathRepo: return "Le chemin de delegation est incorrect ('nomRepo/nomMethode')"; break; |
- | case self::UnknownModule: return "Le module n'existe pas"; break; |
- | case self::UnknownRepo: return "Le repo n'existe pas"; break; |
- | case self::UnknownMethod: return "Le methode n'existe pas"; break; |
- | case self::UncallableMethod: return "Le methode n'est pas amorcable"; break; |
- | case self::PDOConnection: return "La connexion avec la base de donnees a echoue"; break; |
+ | // Erreur dans le traitement |
+ | const RepoError = 13; |
+ | |
+ | /* Database */ |
+ | |
+ | // Erreur lors de la creation d'un objet PDO (connection) |
+ | const PDOConnection = 14; |
+ | |
+ | |
+ | /* EXPLICITE UN CODE D'ERREUR |
+ | * |
+ | * @error<Integer> Code d'erreur |
+ | * |
+ | * @return explicit<String> Description explicite du code d'erreur |
+ | * |
+ | */ |
+ | public static function explicit($error){ |
+ | switch($error){ |
+ | case self::Success: return "Tout s'est bien deroule"; break; |
+ | |
+ | case self::ParsingFailed: return "La lecture du fichier JSON a echoue"; break; |
| |
- | default: return "Erreur inconnue..."; break; |
- | } |
- | |
- | return 'Aucune erreur trouvee'; |
- | } |
- | |
- | } |
- | |
+ | case self::InvalidFlags: return "Les specifications (drapeaux) sont incorrects"; break; |
+ | case self::UnreachableResource: return "La ressource n'existe pas (404)"; break; |
+ | case self::MissingPath: return "Le chemin de delegation n'a pas ete renseigne"; break; |
+ | case self::WrongPathModule: return "Le chemin de delegation est incorrect ('nomModule/nomMethode')"; break; |
+ | case self::WrongPathRepo: return "Le chemin de delegation est incorrect ('nomRepo/nomMethode')"; break; |
+ | case self::UnknownModule: return "Le module n'existe pas"; break; |
+ | case self::UnknownRepo: return "Le repo n'existe pas"; break; |
+ | case self::UnknownMethod: return "Le methode n'existe pas"; break; |
+ | case self::UncallableMethod: return "Le methode n'est pas amorcable"; break; |
+ | |
+ | case self::ParamError: return "Un ou plusieurs parametres sont manquants ou incorrects"; break; |
+ | case self::ModuleError: return "Erreur lors du traitement du module"; break; |
+ | case self::RepoError: return "Erreur lors du traitement du repo"; break; |
+ | |
+ | case self::PDOConnection: return "La connexion avec la base de donnees a echoue"; break; |
+ | |
+ | // default: return "Erreur inconnue..."; break; |
+ | } |
+ | |
+ | // Erreur inconnue |
+ | return null; |
+ | } |
+ | |
+ | } |
+ | |
@@ -203,7 +220,7 @@
Dead Code
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016.
diff --git a/phpunit/coverage/ResourceDispatcher.php.html b/phpunit/coverage/ResourceDispatcher.php.html
index 7367242..3272a19 100644
--- a/phpunit/coverage/ResourceDispatcher.php.html
+++ b/phpunit/coverage/ResourceDispatcher.php.html
@@ -223,42 +223,42 @@
| * |
| */ |
| public function __construct($url, $view=false){ |
- | $this->error = ManagerError::Success; |
+ | $this->error = ManagerError::Success; |
| |
| |
| /* [0] On met a jour la configuration |
| =====================================================*/ |
| // Extensions supportees |
- | $extensions_conf = json_decode( file_get_contents(__ROOT__.self::$extension_config_path), true ); |
+ | $extensions_conf = json_decode( file_get_contents(__ROOT__.self::$extension_config_path), true ); |
| |
| // Gestion de l'erreur de parsage |
- | if( $extensions_conf == null ){ |
+ | if( $extensions_conf == null ){ |
| $this->error = ManagerError::ParsingFailed; |
| return false; |
| } |
| |
- | self::$supported_extensions = $extensions_conf; |
+ | self::$supported_extensions = $extensions_conf; |
| |
| // Dossiers supportes |
- | $parents_conf = json_decode( file_get_contents(__ROOT__.self::$parents_config_path), true ); |
+ | $parents_conf = json_decode( file_get_contents(__ROOT__.self::$parents_config_path), true ); |
| |
| // Gestion de l'erreur de parsage |
- | if( $parents_conf == null ){ |
+ | if( $parents_conf == null ){ |
| $this->error = ManagerError::ParsingFailed; |
| return false; |
| } |
| |
- | self::$supported_parents = $parents_conf; |
+ | self::$supported_parents = $parents_conf; |
| |
| |
| |
| /* [1] On recupere les donnees de l'URL |
| ==================================================*/ |
- | $serialFlags = array_slice( explode('/',$url), 1 ); |
+ | $serialFlags = array_slice( explode('/',$url), 1 ); |
| |
| /* [2] On check/cree les drapeaux avec ces donnees |
| ==================================================*/ |
- | if( !$this->createFlags($serialFlags) ){ // Creation des drapeaux |
+ | if( !$this->createFlags($serialFlags) ){ // Creation des drapeaux |
| $this->error = ManagerError::InvalidFlags; |
| return false; |
| } |
@@ -266,7 +266,7 @@
| |
| /* [3] On construit le chemin a partir des tags |
| ==================================================*/ |
- | if( !$this->buildPath() ){ // Construction du chemin |
+ | if( !$this->buildPath() ){ // Construction du chemin |
| $this->error = ManagerError::UnreachableResource; |
| return false; |
| } |
@@ -274,10 +274,10 @@
| /* [4] On gere l'affichage pour l'appel externe/interne |
| ==================================================*/ |
| if( $view ) // Appel externe |
- | $this->view(); |
+ | $this->view(); |
| |
| |
- | return true; |
+ | return true; |
| |
| } |
| |
@@ -290,8 +290,8 @@
| * |
| */ |
| public static function getResource($route){ |
- | $instance = new ResourceDispatcher($route); |
- | return $instance->getContent(); |
+ | $instance = new ResourceDispatcher($route); |
+ | return $instance->getContent(); |
| } |
| |
| |
@@ -307,46 +307,46 @@
| /* [1] Verification des flags (version serialisee) |
| ======================================================*/ |
| |
- | $correct = true; |
+ | $correct = true; |
| |
| // Verification du nombre de drapeaux () au moins 3 |
- | $correct = $correct && count($serialFlags) >= 3; |
+ | $correct = $correct && count($serialFlags) >= 3; |
| |
| // Verification que l'extension est correcte |
- | $correct = $correct && array_key_exists($serialFlags[0], self::$supported_extensions); |
+ | $correct = $correct && array_key_exists($serialFlags[0], self::$supported_extensions); |
| |
| // Verification du filename |
- | $correct = $correct && preg_match('#^[\w_-]+$#i', $serialFlags[1]); |
+ | $correct = $correct && preg_match('#^[\w_-]+$#i', $serialFlags[1]); |
| |
| // Verification du parent |
- | $correct = $correct && array_key_exists($serialFlags[2], self::$supported_parents); |
+ | $correct = $correct && array_key_exists($serialFlags[2], self::$supported_parents); |
| |
| // Verification du sous-parent (optionnel) |
- | $opt_subParent = count($serialFlags) >= 4; |
+ | $opt_subParent = count($serialFlags) >= 4; |
| |
| if( $opt_subParent ) |
- | $correct = $correct && preg_match('#^[\w_-]+$#i', $serialFlags[3]); |
+ | $correct = $correct && preg_match('#^[\w_-]+$#i', $serialFlags[3]); |
| |
| |
- | if( !$correct ) |
- | return false; |
+ | if( !$correct ) |
+ | return false; |
| |
| |
| |
| /* [2] Creation (non serialisee) des flags |
| ======================================================*/ |
| // Si tout se deroule bien, on cree les flags |
- | $this->flags = array( |
- | 'extension' => $serialFlags[0], |
- | 'filename' => $serialFlags[1], |
- | 'parent' => $serialFlags[2] |
- | ); |
+ | $this->flags = array( |
+ | 'extension' => $serialFlags[0], |
+ | 'filename' => $serialFlags[1], |
+ | 'parent' => $serialFlags[2] |
+ | ); |
| |
| // Ajout du sous-parent optionnel |
| if( $opt_subParent ) |
- | $this->flags['subparent'] = $serialFlags[3]; |
+ | $this->flags['subparent'] = $serialFlags[3]; |
| |
- | return true; |
+ | return true; |
| |
| |
| } |
@@ -365,10 +365,10 @@
| /* [1] On recupere le HEADER associe a l'extension |
| ==========================================================*/ |
| // Si aucun header pour cet cle, on retourne une erreur |
- | if( !isset(self::$supported_extensions[$this->flags['extension']]) ) return false; |
+ | if( !isset(self::$supported_extensions[$this->flags['extension']]) ) return false; |
| |
| // On recupere le header associe |
- | $header = self::$supported_extensions[$this->flags['extension']]; |
+ | $header = self::$supported_extensions[$this->flags['extension']]; |
| |
| |
| |
@@ -377,28 +377,28 @@
| /* [2] On recupere le chemin associe au parent |
| ==========================================================*/ |
| // Si aucun dossier pour cet indice, on retourne une erreur |
- | if( !isset(self::$supported_parents[$this->flags['parent']]) ) return false; |
+ | if( !isset(self::$supported_parents[$this->flags['parent']]) ) return false; |
| |
| // On recupere le dossier associe |
- | $parent = self::$supported_parents[$this->flags['parent']]; |
+ | $parent = self::$supported_parents[$this->flags['parent']]; |
| |
| |
| /* [3] Gestion du sous-parent optionnel |
| ==========================================================*/ |
- | $opt_subParent = (isset($this->flags['subparent'])) ? $this->flags['subparent'].'/' : ''; |
+ | $opt_subParent = (isset($this->flags['subparent'])) ? $this->flags['subparent'].'/' : ''; |
| |
| |
| /* [4] On definit le header |
| ==========================================================*/ |
- | $this->header = $header; |
+ | $this->header = $header; |
| |
| /* [5] On construit le chemin |
| ==========================================================*/ |
- | $this->path = __ROOT__.$parent.'/'.$opt_subParent.$this->flags['filename'].'.'.$this->flags['extension']; |
+ | $this->path = __ROOT__.$parent.'/'.$opt_subParent.$this->flags['filename'].'.'.$this->flags['extension']; |
| |
| /* [6] On retourne si le fichier existe ou non |
| ==========================================================*/ |
- | return @file_get_contents( $this->path ) != false; |
+ | return @file_get_contents( $this->path ) != false; |
| |
| } |
| |
@@ -427,12 +427,12 @@
| */ |
| public function getContent(){ |
| // S'il y a eu une erreur en amont |
- | if( $this->error != ManagerError::Success ) |
- | return false; // on retourne faux |
+ | if( $this->error != ManagerError::Success ) |
+ | return false; // on retourne faux |
| |
| |
| // On inclut le contenu |
- | return file_get_contents($this->path); |
+ | return file_get_contents($this->path); |
| } |
| |
| |
@@ -450,7 +450,7 @@
Dead Code
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016.
diff --git a/phpunit/coverage/autoloader.php.html b/phpunit/coverage/autoloader.php.html
index 1cc001c..e37027e 100755
--- a/phpunit/coverage/autoloader.php.html
+++ b/phpunit/coverage/autoloader.php.html
@@ -120,18 +120,18 @@
| * |
| */ |
| function autoloader($className){ |
- | $path = ''; |
+ | $path = ''; |
| |
| /* [1] On utilise le namespace pour localiser |
| ===============================================*/ |
| // On remplace les '\' par des '/' |
- | $path = str_replace('\\', '/', $className) . '.php'; |
- | $path = __ROOT__.'/'.$path; |
+ | $path = str_replace('\\', '/', $className) . '.php'; |
+ | $path = __ROOT__.'/'.$path; |
| |
| // Si le fichier existe, on l'inclut |
- | if( file_exists($path) ) |
- | require_once $path; |
- | } |
+ | if( file_exists($path) ) |
+ | require_once $path; |
+ | } |
| |
| // On definit l'autoloader comme autoloader (obvious) |
| spl_autoload_register('autoloader', false, true); |
@@ -153,7 +153,7 @@
Dead Code
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016.
diff --git a/phpunit/coverage/index.dashboard.html b/phpunit/coverage/index.dashboard.html
index 4123f08..a522a3d 100755
--- a/phpunit/coverage/index.dashboard.html
+++ b/phpunit/coverage/index.dashboard.html
@@ -40,8 +40,6 @@
@@ -96,7 +90,7 @@ $(document).ready(function() {
min: 0
},
series: [{
- data: [1,1,0,0,0,0,0,0,1,0,1,0]
+ data: [0,0,0,0,0,0,0,0,1,0,1,2]
}],
});
@@ -124,7 +118,7 @@ $(document).ready(function() {
}
},
series: [{
- data: [[95.3125,52,"DataBase<\/a>"],[0,13,"ManagerError<\/a>"],[75.925925925926,24,"ResourceDispatcher<\/a>"],[3.3333333333333,11,"sessionManager<\/a>"]],
+ data: [[95.3125,52,"DataBase<\/a>"],[100,16,"ManagerError<\/a>"],[75.925925925926,24,"ResourceDispatcher<\/a>"],[100,11,"sessionManager<\/a>"]],
marker: {
symbol: 'diamond'
}
diff --git a/phpunit/coverage/index.html b/phpunit/coverage/index.html
index 45d9ca9..ce19264 100755
--- a/phpunit/coverage/index.html
+++ b/phpunit/coverage/index.html
@@ -41,25 +41,25 @@
- Total |
+ Total |
+
+ |
+ 88.51% |
+ 154 / 174 |
+
+ |
+ 70.59% |
+ 12 / 17 |
|
- 63.37% |
- 109 / 172 |
-
- |
- 47.06% |
- 8 / 17 |
-
- |
- 0.00% |
- 0 / 4 |
+ 50.00% |
+ 2 / 4 |
@@ -85,25 +85,25 @@
- ManagerError.php |
-
-
+ ManagerError.php |
+
|
- 0.00% |
- 0 / 14 |
-
-
+ 100.00% |
+ 16 / 16 |
+
|
- 0.00% |
- 0 / 1 |
-
-
+ 100.00% |
+ 1 / 1 |
+
|
- 0.00% |
- 0 / 1 |
+ 100.00% |
+ 1 / 1 |
| | |
@@ -145,25 +145,25 @@
- sessionManager.php |
-
-
+ sessionManager.php |
+
|
- 3.33% |
- 1 / 30 |
-
-
+ 100.00% |
+ 30 / 30 |
+
|
- 25.00% |
- 1 / 4 |
-
-
+ 100.00% |
+ 4 / 4 |
+
|
- 0.00% |
- 0 / 1 |
+ 100.00% |
+ 1 / 1 |
| | |
@@ -177,7 +177,7 @@
High: 70% to 100%
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016.
diff --git a/phpunit/coverage/sessionManager.php.html b/phpunit/coverage/sessionManager.php.html
index eef0b6d..cb2a80b 100644
--- a/phpunit/coverage/sessionManager.php.html
+++ b/phpunit/coverage/sessionManager.php.html
@@ -41,49 +41,49 @@
- Total |
-
-
+ Total |
+
|
- 0.00% |
- 0 / 1 |
-
-
+ 100.00% |
+ 1 / 1 |
+
|
- 25.00% |
- 1 / 4 |
- CRAP |
-
-
+ 100.00% |
+ 4 / 4 |
+ CRAP |
+
|
- 3.33% |
- 1 / 30 |
+ 100.00% |
+ 30 / 30 |
| | |
- sessionManager |
-
-
+ sessionManager |
+
|
- 0.00% |
- 0 / 1 |
-
-
+ 100.00% |
+ 1 / 1 |
+
|
- 25.00% |
- 1 / 4 |
- 120.30 |
-
-
+ 100.00% |
+ 4 / 4 |
+ 11 |
+
|
- 3.33% |
- 1 / 30 |
+ 100.00% |
+ 30 / 30 |
| | |
@@ -104,54 +104,54 @@
- reset_session($session_id=null) |
- |
- update_token() |
-
-
+ update_token() |
+
|
- 0.00% |
- 0 / 1 |
- 2 |
-
-
+ 100.00% |
+ 1 / 1 |
+ 1 |
+
|
- 0.00% |
- 0 / 5 |
+ 100.00% |
+ 5 / 5 |
| |
- session_start() |
-
-
+ session_start() |
+
|
- 0.00% |
- 0 / 1 |
- 56 |
-
-
+ 100.00% |
+ 1 / 1 |
+ 7 |
+
|
- 0.00% |
- 0 / 16 |
+ 100.00% |
+ 16 / 16 |
| |
@@ -173,7 +173,7 @@
| /* SECURE SHA1 ALGORITHM */ |
| /*************************/ |
| public static function secure_sha1($data){ |
- | return sha1( '">\[..|{@#))'.sha1($data.'_)Q@#((%*_$%(@#') ); |
+ | return sha1( '">\[..|{@#))'.sha1($data.'_)Q@#((%*_$%(@#') ); |
| } |
| |
| |
@@ -182,38 +182,38 @@
| /*****************************/ |
| private static function reset_session($session_id=null){ |
| // On ferme la session |
- | session_destroy(); |
+ | session_destroy(); |
| |
| // On definit l'id session si donne en argument |
- | if( $session_id != null ) |
- | session_id( $session_id ); |
+ | if( $session_id != null ) |
+ | session_id( $session_id ); |
| |
| // Precaution: on met a jour le cookie |
- | setcookie('PHPSESSID', session_id(), time()+60*30 ); |
+ | setcookie('PHPSESSID', session_id(), time()+60*30 ); |
| |
| // On redemarre la session avec le bon id session |
- | \session_start(); |
+ | \session_start(); |
| |
| // On met a jour le token |
- | self::update_token(); |
+ | self::update_token(); |
| |
| |
- | header('Refresh: 0'); |
- | } |
+ | header('Refresh: 0'); |
+ | } |
| |
| /*******************/ |
| /* GENERE UN TOKEN */ |
| /*******************/ |
| private static function update_token(){ |
- | $token = self::$prefix.self::secure_sha1(uniqid()); |
+ | $token = self::$prefix.self::secure_sha1(uniqid()); |
| |
| // On definit le token en session |
- | $_SESSION['session_token'] = $token; |
+ | $_SESSION['session_token'] = $token; |
| |
| // On definit le token en cookie |
- | $_COOKIE['session_token'] = $_SESSION['session_token']; |
- | setcookie('session_token', $_COOKIE['session_token'], time()+60*30 ); |
- | } |
+ | $_COOKIE['session_token'] = $_SESSION['session_token']; |
+ | setcookie('session_token', $_COOKIE['session_token'], time()+60*30 ); |
+ | } |
| |
| /************/ |
| /* AMORCEUR */ |
@@ -222,29 +222,29 @@
| /* [1] Génération et Gestion des donnees a utiliser |
| ==============================================================*/ |
| // On genere le hash a partir des donnees personnelles |
- | self::$prefix = self::secure_sha1( $_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT'] ); |
+ | self::$prefix = self::secure_sha1( $_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT'] ); |
| |
| // On cree un id session associe a ces donnees personnelles |
- | $sessid = substr(self::$prefix,0,5) . substr(self::secure_sha1(uniqid()),0,24); |
+ | $sessid = substr(self::$prefix,0,5) . substr(self::secure_sha1(uniqid()),0,24); |
| |
| // On genere un token pour l'execution suivante |
- | $token = self::$prefix.self::secure_sha1(uniqid()); |
+ | $token = self::$prefix.self::secure_sha1(uniqid()); |
| |
| // On definit/recupere le token |
- | $session_token = (isset($_COOKIE['session_token'])) ? $_COOKIE['session_token'] : null; |
+ | $session_token = (isset($_COOKIE['session_token'])) ? $_COOKIE['session_token'] : null; |
| |
| |
| |
| /* [2] Verification de l'id session |
| ==============================================================*/ |
- | \session_start(); |
+ | \session_start(); |
| |
| // On verifie l'id session (5 premiers chars du hash des donnees perso) |
- | $valid_sessid = strpos( session_id(), substr(self::$prefix,0,5) ) === 0; |
+ | $valid_sessid = strpos( session_id(), substr(self::$prefix,0,5) ) === 0; |
| |
| // Si id session incorrect ou pas de token |
- | if( !$valid_sessid ) |
- | self::reset_session( $sessid ); // On initialise la session (bon id session) |
+ | if( !$valid_sessid ) |
+ | self::reset_session( $sessid ); // On initialise la session (bon id session) |
| |
| |
| // si id session invalide |
@@ -253,20 +253,20 @@
| /* [3] Verification du token |
| ==============================================================*/ |
| // On verifie que le token est valide |
- | $valid_token = $session_token != null; // verification de l'existence du cookie |
- | $valid_token = $valid_token && strpos($session_token, self::$prefix) === 0; // verification des donnes personnelles |
- | $valid_token = $valid_token && isset($_SESSION['session_token']); // verification que la variable session associee existe |
- | $valid_token = $valid_token && $_SESSION['session_token'] == $_COOKIE['session_token']; // verification que la session est coherente |
+ | $valid_token = $session_token != null; // verification de l'existence du cookie |
+ | $valid_token = $valid_token && strpos($session_token, self::$prefix) === 0; // verification des donnes personnelles |
+ | $valid_token = $valid_token && isset($_SESSION['session_token']); // verification que la variable session associee existe |
+ | $valid_token = $valid_token && $_SESSION['session_token'] == $_COOKIE['session_token']; // verification que la session est coherente |
| |
| /* [4] Si token inexistant |
| ==============================================================*/ |
- | if( !$valid_token ) |
- | self::reset_session($sessid); // On initialise la session |
+ | if( !$valid_token ) |
+ | self::reset_session($sessid); // On initialise la session |
| else |
- | self::update_token(); // Dans tous les cas, on cree un nouveau token |
+ | self::update_token(); // Dans tous les cas, on cree un nouveau token |
| |
| |
- | } |
+ | } |
| |
| |
| } |
@@ -284,7 +284,7 @@
Dead Code
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:40:08 CET 2016.
+ Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016.
diff --git a/phpunit/phpunit.xml b/phpunit/phpunit.xml
index bbe09a6..2c2d7f8 100755
--- a/phpunit/phpunit.xml
+++ b/phpunit/phpunit.xml
@@ -2,9 +2,17 @@
-
+
./tests/
+
+
+ ./tests/ManagerError.php
+
+
+
+ ./tests/sessionManager.php
+
diff --git a/phpunit/tests/Database_check.php b/phpunit/tests/Database_check.php
index 39292ee..635b39f 100755
--- a/phpunit/tests/Database_check.php
+++ b/phpunit/tests/Database_check.php
@@ -1,6 +1,6 @@
-assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorParsingFailed(){
+ $error = \manager\ManagerError::ParsingFailed;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorInvalidFlags(){
+ $error = \manager\ManagerError::InvalidFlags;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorUnreachableResource(){
+ $error = \manager\ManagerError::UnreachableResource;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorMissingPath(){
+ $error = \manager\ManagerError::MissingPath;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorWrongPathModule(){
+ $error = \manager\ManagerError::WrongPathModule;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorUnknownModule(){
+ $error = \manager\ManagerError::UnknownModule;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorUnknownMethod(){
+ $error = \manager\ManagerError::UnknownMethod;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorUncallableMethod(){
+ $error = \manager\ManagerError::UncallableMethod;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorParamError(){
+ $error = \manager\ManagerError::ParamError;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorModuleError(){
+ $error = \manager\ManagerError::ModuleError;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorWrongPathRepo(){
+ $error = \manager\ManagerError::WrongPathRepo;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorUnknownRepo(){
+ $error = \manager\ManagerError::UnknownRepo;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorRepoError(){
+ $error = \manager\ManagerError::RepoError;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+ public function testErrorPDOConnection(){
+ $error = \manager\ManagerError::PDOConnection;
+
+ $this->assertNotNull( \manager\ManagerError::explicit($error) );
+ }
+
+
+ public function testErrorNotKnown(){
+ $error = 1239;
+
+ $this->assertNull( \manager\ManagerError::explicit($error) );
+ }
+
+ }
+
+
+?>
\ No newline at end of file
diff --git a/phpunit/tests/sessionManager.php b/phpunit/tests/sessionManager.php
new file mode 100644
index 0000000..c5cec2c
--- /dev/null
+++ b/phpunit/tests/sessionManager.php
@@ -0,0 +1,251 @@
+assertEquals(40, strlen($hash) );
+ $this->assertNotContains( $plain, $hash );
+ }
+
+ /* [2] Test de l'unicite et du prefix
+ =========================================================*/
+ public function testIdSessionUniq(){
+ // Premiere session
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $id_first = session_id();
+
+ // Seconde session
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $id_second = session_id();
+
+ $this->assertNotEquals( $id_first, $id_second );
+ }
+
+
+ public function testIdenticalPrefix(){
+ // Premiere session
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $first_prefix = substr(session_id(), 0, 5);
+
+ // Seconde session
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $second_prefix = substr(session_id(), 0, 5);
+
+ $this->assertEquals( $first_prefix, $second_prefix );
+ }
+
+
+ public function testCookieUniq(){
+ // Premiere session
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $token_first = $_COOKIE['session_token'];
+
+ // Seconde session
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $token_second = $_COOKIE['session_token'];
+
+ $this->assertNotEquals( $token_first, $token_second );
+ }
+
+ /* [3] REMOTE_ADDR different
+ =========================================================*/
+ public function testSessionIdTheftWithWrongIp(){
+ $default_remote_addr = $_SERVER['REMOTE_ADDR'];
+
+ // Hote n.1
+ $_SERVER['REMOTE_ADDR'] = 'a';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $first_prefix = substr(session_id(), 0, 5);
+
+ // Hote n.2
+ $_SERVER['REMOTE_ADDR'] = 'b';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $second_prefix = substr(session_id(), 0, 5);
+
+
+ $this->assertNotEquals( $first_prefix, $second_prefix );
+
+ $_SERVER['REMOTE_ADDR'] = $default_remote_addr;
+ }
+
+ public function testSessionTokenTheftWithWrongIp(){
+ $default_remote_addr = $_SERVER['REMOTE_ADDR'];
+
+ // Hote n.1
+ $_SERVER['REMOTE_ADDR'] = 'a';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $first_prefix = substr($_COOKIE['session_token'], 0, 5);
+
+ // Hote n.2
+ $_SERVER['REMOTE_ADDR'] = 'b';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $second_prefix = substr($_COOKIE['session_token'], 0, 5);
+
+
+ $this->assertNotEquals( $first_prefix, $second_prefix );
+
+ $_SERVER['REMOTE_ADDR'] = $default_remote_addr;
+ }
+
+
+
+ public function testSessionTokenTheftWithWrongIpThenWell(){
+ $default_remote_addr = $_SERVER['REMOTE_ADDR'];
+
+ // Hote n.1
+ $_SERVER['REMOTE_ADDR'] = 'a';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $first_prefix = substr($_COOKIE['session_token'], 0, 40);
+
+ // Hote n.2
+ $_SERVER['REMOTE_ADDR'] = 'b';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $second_prefix = substr($_COOKIE['session_token'], 0, 40);
+
+ // Hote n.1
+ $_SERVER['REMOTE_ADDR'] = 'a';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $third_prefix = substr($_COOKIE['session_token'], 0, 40);
+
+
+ $this->assertEquals( $first_prefix, $third_prefix );
+ $this->assertNotEquals( $first_prefix, $second_prefix );
+
+ $_SERVER['REMOTE_ADDR'] = $default_remote_addr;
+ }
+
+ /* [4] HTTP_USER_AGENT different
+ =========================================================*/
+ public function testSessionIdTheftWithWrongUserAgent(){
+ $default_http_user_agent = $_SERVER['HTTP_USER_AGENT'];
+
+ // Hote n.1
+ $_SERVER['HTTP_USER_AGENT'] = 'a';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $first_prefix = substr(session_id(), 0, 5);
+
+ // Hote n.2
+ $_SERVER['HTTP_USER_AGENT'] = 'b';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $second_prefix = substr(session_id(), 0, 5);
+
+
+ $this->assertNotEquals( $first_prefix, $second_prefix );
+
+ $_SERVER['HTTP_USER_AGENT'] = $default_http_user_agent;
+ }
+
+ public function testSessionTokenTheftWithWrongUserAgent(){
+ $default_http_user_agent = $_SERVER['HTTP_USER_AGENT'];
+
+ // Hote n.1
+ $_SERVER['HTTP_USER_AGENT'] = 'a';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $first_prefix = substr($_COOKIE['session_token'], 0, 40);
+
+ // Hote n.2
+ $_SERVER['HTTP_USER_AGENT'] = 'b';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $second_prefix = substr($_COOKIE['session_token'], 0, 40);
+
+
+ $this->assertNotEquals( $first_prefix, $second_prefix );
+
+ $_SERVER['HTTP_USER_AGENT'] = $default_http_user_agent;
+ }
+
+
+
+ public function testSessionTokenTheftWithWrongUserAgentThenWell(){
+ $default_http_user_agent = $_SERVER['HTTP_USER_AGENT'];
+
+ // Hote n.1
+ $_SERVER['HTTP_USER_AGENT'] = 'a';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $first_prefix = substr($_COOKIE['session_token'], 0, 40);
+
+ // Hote n.2
+ $_SERVER['HTTP_USER_AGENT'] = 'b';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $second_prefix = substr($_COOKIE['session_token'], 0, 40);
+
+ // Hote n.1
+ $_SERVER['HTTP_USER_AGENT'] = 'a';
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $third_prefix = substr($_COOKIE['session_token'], 0, 40);
+
+
+ $this->assertEquals( $first_prefix, $third_prefix );
+ $this->assertNotEquals( $first_prefix, $second_prefix );
+
+ $_SERVER['HTTP_USER_AGENT'] = $default_http_user_agent;
+ }
+
+
+
+ /* [5] Regeneration du cookie 'session_token'
+ =========================================================*/
+ public function testRegeneratedToken(){
+
+ // Connection 1
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $first_token = $_COOKIE['session_token'];
+
+ // Connection 2
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $second_token = $_COOKIE['session_token'];
+
+
+ $this->assertNotEquals( $first_token, $second_token );
+ }
+
+ public function testSamePrefixToken(){
+
+ // Connection 1
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $first_token_prefix = substr($_COOKIE['session_token'], 0, 40);
+
+ // Connection 2
+ session_destroy();
+ @\manager\sessionManager::session_start();
+ $second_token_prefix = substr($_COOKIE['session_token'], 0, 40);
+
+ $this->assertEquals( $first_token_prefix, $second_token_prefix );
+ }
+
+
+
+ }
+
+
+?>
\ No newline at end of file
diff --git a/todo.md b/todo.md
index 6961a1f..835a672 100755
--- a/todo.md
+++ b/todo.md
@@ -39,6 +39,7 @@
########
# FAIT #
########
+- [x] [phpunit/sessionManager] test unitaires du manager de session php
- [x] [ModuleAnswer] Gestion des erreurs au niveau interne des Modules
- [x] [autoloader][phpunit/bootstrap.php] Correction des bugs de $_SERVER avec PHPUnit -> autoloader + bootstrap personnalise
- [x] [sessionManager] Import de sessionManager