@@ -138,16 +138,24 @@ discard block |
||
| 138 | 138 | // Match Auth Routes. |
| 139 | 139 | // The below algorithm is similar to the one Code Igniter uses in its |
| 140 | 140 | // Routing Class. |
| 141 | - if ($uri_auths == null || !is_array($uri_auths)) return; |
|
| 141 | + if ($uri_auths == null || !is_array($uri_auths)) { |
|
| 142 | + return; |
|
| 143 | + } |
|
| 142 | 144 | $auths = null; |
| 143 | 145 | foreach ($uri_auths as $uri => $auth_array) { |
| 144 | 146 | // Convert wildcards to RegEx. |
| 145 | 147 | $uri = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $uri); |
| 146 | - if (preg_match('#^'.$uri.'$#', uri_string())) $auths = $auth_array; // Assign Authentication Steps. |
|
| 148 | + if (preg_match('#^'.$uri.'$#', uri_string())) { |
|
| 149 | + $auths = $auth_array; |
|
| 150 | + } |
|
| 151 | + // Assign Authentication Steps. |
|
| 147 | 152 | break; |
| 148 | 153 | } |
| 149 | 154 | //$auths = $this->ci->config->item('rest')['uri_auth'][uri_string()] ?? null; |
| 150 | - if ($auths == null) return; // No authentication(s) to acrry out. |
|
| 155 | + if ($auths == null) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + // No authentication(s) to acrry out. |
|
| 151 | 159 | // $this->process_auth() terminates the script if authentication fails |
| 152 | 160 | // It will call the callable in the rest.php config file under |
| 153 | 161 | // response_callbacks which matches the necesarry RESTResponse constant |
@@ -157,7 +165,9 @@ discard block |
||
| 157 | 165 | $this->process_auth($auths); |
| 158 | 166 | return; |
| 159 | 167 | } |
| 160 | - foreach ($auths as $auth) $this->process_auth($auth); |
|
| 168 | + foreach ($auths as $auth) { |
|
| 169 | + $this->process_auth($auth); |
|
| 170 | + } |
|
| 161 | 171 | } |
| 162 | 172 | /** |
| 163 | 173 | * [process_auth description] |
@@ -202,8 +212,14 @@ discard block |
||
| 202 | 212 | private function basic_auth():void { |
| 203 | 213 | $username = $_SERVER['PHP_AUTH_USER'] ?? null; |
| 204 | 214 | $password = $_SERVER['PHP_AUTH_PW'] ?? null; |
| 205 | - if (!$username || !$password) $this->handle_response(RESTResponse::BAD_REQUEST, RESTAuth::BASIC); // Exits. |
|
| 206 | - if (!$this->rest_model->basicAuth($this, $username, $password)) $this->handle_response(RESTResponse::UN_AUTHORIZED, RESTAuth::BASIC); // Exits. |
|
| 215 | + if (!$username || !$password) { |
|
| 216 | + $this->handle_response(RESTResponse::BAD_REQUEST, RESTAuth::BASIC); |
|
| 217 | + } |
|
| 218 | + // Exits. |
|
| 219 | + if (!$this->rest_model->basicAuth($this, $username, $password)) { |
|
| 220 | + $this->handle_response(RESTResponse::UN_AUTHORIZED, RESTAuth::BASIC); |
|
| 221 | + } |
|
| 222 | + // Exits. |
|
| 207 | 223 | } |
| 208 | 224 | /** |
| 209 | 225 | * [api_key_auth description] |
@@ -263,7 +279,9 @@ discard block |
||
| 263 | 279 | // Trunctate Rate Limit Data. |
| 264 | 280 | $this->rest_model->truncateRatelimitData(); |
| 265 | 281 | // Check Whitelist. |
| 266 | - if (in_array($this->ci->input->ip_address(), $this->whitelist)) return; |
|
| 282 | + if (in_array($this->ci->input->ip_address(), $this->whitelist)) { |
|
| 283 | + return; |
|
| 284 | + } |
|
| 267 | 285 | // Should we acyually Limit? |
| 268 | 286 | if ($this->ip_per_hour > 0) { |
| 269 | 287 | $client = hash('md5', $this->ci->input->ip_address()); |
@@ -339,7 +357,9 @@ discard block |
||
| 339 | 357 | if (isset($this->ci->config->item('rest')['response_callbacks'][$code])) { |
| 340 | 358 | $this->ci->config->item('rest')['response_callbacks'][$code]($auth); |
| 341 | 359 | } |
| 342 | - if (ENVIRONMENT != 'testing') exit($code); |
|
| 360 | + if (ENVIRONMENT != 'testing') { |
|
| 361 | + exit($code); |
|
| 362 | + } |
|
| 343 | 363 | throw new Exception("Error $code in $auth", $code); |
| 344 | 364 | } |
| 345 | 365 | } |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | * @covers JWT::__construct |
| 23 | 23 | */ |
| 24 | 24 | public static function setUpBeforeClass(): void { |
| 25 | - self::$ci =& get_instance(); |
|
| 25 | + self::$ci = & get_instance(); |
|
| 26 | 26 | self::$ci->load->database('mysqli://root@localhost/test_db'); |
| 27 | 27 | self::$ci->load->helper("url"); |
| 28 | - $queries = explode("#@@@", file_get_contents(FCPATH . 'application/splints/' . self::PACKAGE . '/phpunit/database.sql')); |
|
| 28 | + $queries = explode("#@@@", file_get_contents(FCPATH.'application/splints/'.self::PACKAGE.'/phpunit/database.sql')); |
|
| 29 | 29 | self::assertTrue(count($queries) > 0); |
| 30 | 30 | self::$ci->load->database(); |
| 31 | 31 | foreach ($queries as $query) { |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | // However, for the purpose of this test, we are going to Hack Code CodeIgniter |
| 42 | 42 | // with a Splint Config variable to allow us load config files from where |
| 43 | 43 | // ever we want. This happens below. |
| 44 | - self::$ci->load->add_package_path(APPPATH . 'splints/' . self::PACKAGE . "/phpunit/"); |
|
| 44 | + self::$ci->load->add_package_path(APPPATH.'splints/'.self::PACKAGE."/phpunit/"); |
|
| 45 | 45 | //self::$ci->config->set_item('st_config_path_prefix', '../splints/' . self::PACKAGE . "/phpunit/config/"); |
| 46 | 46 | } |
| 47 | 47 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $_SERVER['PHP_AUTH_PW'] = "012345678901234567890"; |
| 59 | 59 | self::$ci->config->set_item('expected_uri', 'basic/auth'); |
| 60 | 60 | self::$ci->config->set_item('expected_auth', RESTAuth::BASIC); |
| 61 | - $this->expectExceptionMessage('Error ' . RESTResponse::UN_AUTHORIZED . ' in ' . RESTAuth::BASIC); |
|
| 61 | + $this->expectExceptionMessage('Error '.RESTResponse::UN_AUTHORIZED.' in '.RESTAuth::BASIC); |
|
| 62 | 62 | self::$ci->load->splint(self::PACKAGE, '+REST', null, 'basic_rest_2'); |
| 63 | 63 | } |
| 64 | 64 | /** |
@@ -22,10 +22,10 @@ |
||
| 22 | 22 | * @covers JWT::__construct |
| 23 | 23 | */ |
| 24 | 24 | public static function setUpBeforeClass(): void { |
| 25 | - self::$ci =& get_instance(); |
|
| 25 | + self::$ci = & get_instance(); |
|
| 26 | 26 | self::$ci->load->database('mysqli://root@localhost/test_db'); |
| 27 | 27 | self::$ci->load->helper("url"); |
| 28 | - $queries = explode("#@@@", file_get_contents(FCPATH . 'application/splints/' . self::PACKAGE . '/phpunit/database.sql')); |
|
| 28 | + $queries = explode("#@@@", file_get_contents(FCPATH.'application/splints/'.self::PACKAGE.'/phpunit/database.sql')); |
|
| 29 | 29 | self::assertTrue(count($queries) > 0); |
| 30 | 30 | self::$ci->load->database(); |
| 31 | 31 | foreach ($queries as $query) { |
@@ -11,19 +11,19 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | $config['auth_callbacks'] = [ |
| 13 | 13 | |
| 14 | - RESTAuth::CUSTOM('X-APP-ID') => function (&$context, $value):bool { |
|
| 14 | + RESTAuth::CUSTOM('X-APP-ID') => function(&$context, $value):bool { |
|
| 15 | 15 | return true; |
| 16 | 16 | }, |
| 17 | 17 | |
| 18 | - RESTAuth::CUSTOM('X-DEVICE-ID') => function (&$context, $value):bool { |
|
| 18 | + RESTAuth::CUSTOM('X-DEVICE-ID') => function(&$context, $value):bool { |
|
| 19 | 19 | return true; |
| 20 | 20 | }, |
| 21 | 21 | |
| 22 | - RESTAuth::BEARER => function (&$context, $token):bool { |
|
| 22 | + RESTAuth::BEARER => function(&$context, $token):bool { |
|
| 23 | 23 | return true; |
| 24 | 24 | }, |
| 25 | 25 | |
| 26 | - RESTAuth::OAUTH2 => function (&$context, $token):bool { |
|
| 26 | + RESTAuth::OAUTH2 => function(&$context, $token):bool { |
|
| 27 | 27 | return true; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | }, |
| 39 | 39 | |
| 40 | 40 | RESTResponse::UN_AUTHORIZED => function(&$auth):void { |
| 41 | - $ci =& get_instance(); |
|
| 42 | - Assert::assertTrue(uri_string() == $ci->config->item('expected_uri')&& $auth == $ci->config->item('expected_auth')); |
|
| 41 | + $ci = & get_instance(); |
|
| 42 | + Assert::assertTrue(uri_string() == $ci->config->item('expected_uri') && $auth == $ci->config->item('expected_auth')); |
|
| 43 | 43 | }, |
| 44 | 44 | |
| 45 | 45 | RESTResponse::NOT_ACCEPTABLE => function(&$auth):void { |