From: ArthurHoaro Date: Sun, 15 Jan 2017 13:01:47 +0000 (+0100) Subject: Merge pull request #746 from ArthurHoaro/hotfix/delete-button X-Git-Tag: v0.9.0~68 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=5fbab3edb300ad770d88f40ba1cc50d5b93a5bb8;hp=066333c03ca6f484b8e1505e7626d2d01f252bf5;p=github%2Fshaarli%2FShaarli.git Merge pull request #746 from ArthurHoaro/hotfix/delete-button Fix delete button in editlink --- diff --git a/.gitattributes b/.gitattributes index d753b1db..059fbb18 100644 --- a/.gitattributes +++ b/.gitattributes @@ -19,6 +19,7 @@ Dockerfile text # Exclude from Git archives .gitattributes export-ignore +.github export-ignore .gitignore export-ignore .travis.yml export-ignore doc/**/*.json export-ignore diff --git a/.github/mailmap b/.github/mailmap new file mode 100644 index 00000000..41d91e47 --- /dev/null +++ b/.github/mailmap @@ -0,0 +1,13 @@ +ArthurHoaro +Florian Eula feula +Florian Eula +Nicolas Danelon nicolasm +Nicolas Danelon +Nicolas Danelon +Nicolas Danelon +Sébastien Sauvage +Timo Van Neerden +Timo Van Neerden lehollandaisvolant +VirtualTam +VirtualTam +VirtualTam diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 00000000..aa041ae9 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,40 @@ + 327 ArthurHoaro + 188 VirtualTam + 132 nodiscc + 56 Sébastien Sauvage + 15 Florian Eula + 13 Emilien Klein + 12 Nicolas Danelon + 7 Christophe HENRY + 4 Alexandre Alapetite + 4 David Sferruzza + 3 Teromene + 2 Chris Kuethe + 2 Knah Tsaeb + 2 Mathieu Chabanon + 2 Miloš Jovanović + 2 Qwerty + 2 Timo Van Neerden + 2 julienCXX + 2 kalvn + 1 Adrien Oliva + 1 Alexis J + 1 BoboTiG + 1 Bronco + 1 D Low + 1 Dimtion + 1 Fanch + 1 Felix Bartels + 1 Felix Kästner + 1 Florian Voigt + 1 Gary Marigliano + 1 Guillaume Virlet + 1 Jonathan Druart + 1 Julien Pivotto + 1 Kevin Canévet + 1 Knah Tsaeb + 1 Lionel Martin + 1 Marsup + 1 Sbgodin + 1 TsT + 1 dimtion diff --git a/COPYING b/COPYING index 547ea570..4bbdf2b3 100644 --- a/COPYING +++ b/COPYING @@ -1,33 +1,7 @@ Files: * License: zlib/libpng Copyright: (c) 2011-2015 Sébastien SAUVAGE - (c) 2011-2015 Alexandre Alapetite - (c) 2011-2015 David Sferruzza - (c) 2011-2015 Christophe HENRY - (c) 2011-2015 Mathieu Chabanon - (c) 2011-2015 BoboTiG - (c) 2011-2015 Bronco - (c) 2011-2015 Emilien Klein - (c) 2011-2015 Knah Tsaeb - (c) 2011-2015 Lionel Martin - (c) 2011-2015 lehollandaisvolant - (c) 2011-2015 timo van neerden - (c) 2011-2015 nodiscc - (c) 2011-2015 Florian Eula - (c) 2011-2015 Arthur Hoaro - (c) 2011-2015 Aurélien "VirtualTam" Tamisier - (c) 2011-2015 qwertygc - (c) 2011-2015 idleman - (c) 2015 Alexis Ju - (c) 2015 dimtion - (c) 2015 Fanch - (c) 2015 Guillaume Virlet - (c) 2015 Felix Bartels - (c) 2015 Marsup - (c) 2015 Miloš Jovanović - (c) 2015 Nicolás Danelón - (c) 2015 TsT - + (c) 2011-2017 The Shaarli Community, see AUTHORS Files: inc/reset.css License: BSD (http://opensource.org/licenses/BSD-3-Clause) diff --git a/Makefile b/Makefile index 60aec9a0..f3065b77 100644 --- a/Makefile +++ b/Makefile @@ -169,6 +169,12 @@ clean: @git clean -df @rm -rf sandbox +### generate the AUTHORS file from Git commit information +authors: + @cp .github/mailmap .mailmap + @git shortlog -sne > AUTHORS + @rm .mailmap + ### generate Doxygen documentation doxygen: clean @rm -rf doxygen @@ -214,4 +220,4 @@ htmlpages: -o doc/$$base.html $$file; \ done; -htmldoc: doc htmlsidebar htmlpages +htmldoc: authors doc htmlsidebar htmlpages diff --git a/application/HttpUtils.php b/application/HttpUtils.php index e8fc1f5d..a81f9056 100644 --- a/application/HttpUtils.php +++ b/application/HttpUtils.php @@ -122,7 +122,7 @@ function get_http_response($url, $timeout = 30, $maxBytes = 4194304) $content = substr($response, $headSize); $headers = array(); foreach (preg_split('~[\r\n]+~', $rawHeadersLastRedir) as $line) { - if (empty($line) or ctype_space($line)) { + if (empty($line) || ctype_space($line)) { continue; } $splitLine = explode(': ', $line, 2); diff --git a/application/LinkUtils.php b/application/LinkUtils.php index cf58f808..976474de 100644 --- a/application/LinkUtils.php +++ b/application/LinkUtils.php @@ -89,7 +89,9 @@ function count_private($links) { $cpt = 0; foreach ($links as $link) { - $cpt = $link['private'] == true ? $cpt + 1 : $cpt; + if ($link['private']) { + $cpt += 1; + } } return $cpt; diff --git a/application/Updater.php b/application/Updater.php index 621c7238..eb03c6d3 100644 --- a/application/Updater.php +++ b/application/Updater.php @@ -69,7 +69,7 @@ class Updater return $updatesRan; } - if ($this->methods == null) { + if ($this->methods === null) { throw new UpdaterException('Couldn\'t retrieve Updater class methods.'); } @@ -308,6 +308,22 @@ class Updater return true; } + + /** + * Move the file to inc/user.css to data/user.css. + * + * Note: Due to hardcoded paths, it's not unit testable. But one line of code should be fine. + * + * @return bool true if the update is successful, false otherwise. + */ + public function updateMethodMoveUserCss() + { + if (! is_file('inc/user.css')) { + return true; + } + + return rename('inc/user.css', 'data/user.css'); + } } /** diff --git a/application/api/ApiMiddleware.php b/application/api/ApiMiddleware.php index 162e88e0..522091ca 100644 --- a/application/api/ApiMiddleware.php +++ b/application/api/ApiMiddleware.php @@ -98,8 +98,7 @@ class ApiMiddleware * @throws ApiAuthorizationException The token couldn't be validated. */ protected function checkToken($request) { - $jwt = $request->getHeaderLine('jwt'); - if (empty($jwt)) { + if (! $request->hasHeader('Authorization')) { throw new ApiAuthorizationException('JWT token not provided'); } @@ -107,7 +106,13 @@ class ApiMiddleware throw new ApiAuthorizationException('Token secret must be set in Shaarli\'s administration'); } - ApiUtils::validateJwtToken($jwt, $this->conf->get('api.secret')); + $authorization = $request->getHeaderLine('Authorization'); + + if (! preg_match('/^Bearer (.*)/i', $authorization, $matches)) { + throw new ApiAuthorizationException('Invalid JWT header'); + } + + ApiUtils::validateJwtToken($matches[1], $this->conf->get('api.secret')); } /** diff --git a/index.php b/index.php index e553d1dd..a54dfb1d 100644 --- a/index.php +++ b/index.php @@ -204,7 +204,7 @@ function setup_login_state($conf) } // If session does not exist on server side, or IP address has changed, or session has expired, logout. if (empty($_SESSION['uid']) - || ($conf->get('security.session_protection_disabled') == false && $_SESSION['ip'] != allIPs()) + || ($conf->get('security.session_protection_disabled') === false && $_SESSION['ip'] != allIPs()) || time() >= $_SESSION['expires_on']) { logout(); diff --git a/tests/api/ApiMiddlewareTest.php b/tests/api/ApiMiddlewareTest.php index 4d4dd9b9..d9753b1d 100644 --- a/tests/api/ApiMiddlewareTest.php +++ b/tests/api/ApiMiddlewareTest.php @@ -143,7 +143,7 @@ class ApiMiddlewareTest extends \PHPUnit_Framework_TestCase $env = Environment::mock([ 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/echo', - 'HTTP_JWT'=> 'jwt', + 'HTTP_AUTHORIZATION'=> 'Bearer jwt', ]); $request = Request::createFromEnvironment($env); $response = new Response(); @@ -157,7 +157,30 @@ class ApiMiddlewareTest extends \PHPUnit_Framework_TestCase } /** - * Invoke the middleware without an invalid JWT token (debug): + * Invoke the middleware with an invalid JWT token header + */ + public function testInvalidJwtAuthHeaderDebug() + { + $this->conf->set('dev.debug', true); + $mw = new ApiMiddleware($this->container); + $env = Environment::mock([ + 'REQUEST_METHOD' => 'GET', + 'REQUEST_URI' => '/echo', + 'HTTP_AUTHORIZATION'=> 'PolarBearer jwt', + ]); + $request = Request::createFromEnvironment($env); + $response = new Response(); + /** @var Response $response */ + $response = $mw($request, $response, null); + + $this->assertEquals(401, $response->getStatusCode()); + $body = json_decode((string) $response->getBody()); + $this->assertEquals('Not authorized: Invalid JWT header', $body->message); + $this->assertContains('ApiAuthorizationException', $body->stacktrace); + } + + /** + * Invoke the middleware with an invalid JWT token (debug): * should return a 401 error Unauthorized - with a specific message and a stacktrace. * * Note: specific JWT errors tests are handled in ApiUtilsTest. @@ -169,7 +192,7 @@ class ApiMiddlewareTest extends \PHPUnit_Framework_TestCase $env = Environment::mock([ 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/echo', - 'HTTP_JWT'=> 'bad jwt', + 'HTTP_AUTHORIZATION'=> 'Bearer jwt', ]); $request = Request::createFromEnvironment($env); $response = new Response(); diff --git a/tpl/default/includes.html b/tpl/default/includes.html index c3b837f5..17b78b17 100644 --- a/tpl/default/includes.html +++ b/tpl/default/includes.html @@ -8,7 +8,7 @@ -{if="is_file('inc/user.css')"}{/if} +{if="is_file('data/user.css')"}{/if} {loop="$plugins_includes.css_files"} {/loop}