]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #746 from ArthurHoaro/hotfix/delete-button
authorArthurHoaro <arthur@hoa.ro>
Sun, 15 Jan 2017 13:01:47 +0000 (14:01 +0100)
committerGitHub <noreply@github.com>
Sun, 15 Jan 2017 13:01:47 +0000 (14:01 +0100)
Fix delete button in editlink

12 files changed:
.gitattributes
.github/mailmap [new file with mode: 0644]
AUTHORS [new file with mode: 0644]
COPYING
Makefile
application/HttpUtils.php
application/LinkUtils.php
application/Updater.php
application/api/ApiMiddleware.php
index.php
tests/api/ApiMiddlewareTest.php
tpl/default/includes.html

index d753b1db076ab9fce664b20d15c361a1b5ecefe6..059fbb182a4fb08de293f81daac3b1d4820ebe64 100644 (file)
@@ -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 (file)
index 0000000..41d91e4
--- /dev/null
@@ -0,0 +1,13 @@
+ArthurHoaro <arthur@hoa.ro>
+Florian Eula <eula.florian@gmail.com> feula
+Florian Eula <eula.florian@gmail.com> <mr.pikzen@gmail.com>
+Nicolas Danelon <hi@nicolasmd.com.ar> nicolasm
+Nicolas Danelon <hi@nicolasmd.com.ar> <nda@3818.com.ar>
+Nicolas Danelon <hi@nicolasmd.com.ar> <nicolasdanelon@gmail.com>
+Nicolas Danelon <hi@nicolasmd.com.ar> <nicolasdanelon@users.noreply.github.com>
+Sébastien Sauvage <sebsauvage@sebsauvage.net>
+Timo Van Neerden <fire@lehollandaisvolant.net>
+Timo Van Neerden <fire@lehollandaisvolant.net> lehollandaisvolant <levoltigeurhollandais@gmail.com>
+VirtualTam <virtualtam@flibidi.net> <tamisier.aurelien@gmail.com>
+VirtualTam <virtualtam@flibidi.net> <virtualtam+github@flibidi.net>
+VirtualTam <virtualtam@flibidi.net> <virtualtam@flibidi.org>
diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..aa041ae
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,40 @@
+   327 ArthurHoaro <arthur@hoa.ro>
+   188 VirtualTam <virtualtam@flibidi.net>
+   132 nodiscc <nodiscc@gmail.com>
+    56 Sébastien Sauvage <sebsauvage@sebsauvage.net>
+    15 Florian Eula <eula.florian@gmail.com>
+    13 Emilien Klein <emilien@klein.st>
+    12 Nicolas Danelon <hi@nicolasmd.com.ar>
+     7 Christophe HENRY <christophe.henry@sbgodin.fr>
+     4 Alexandre Alapetite <alexandre@alapetite.fr>
+     4 David Sferruzza <david.sferruzza@gmail.com>
+     3 Teromene <teromene@teromene.fr>
+     2 Chris Kuethe <chris.kuethe@gmail.com>
+     2 Knah Tsaeb <Knah-Tsaeb@knah-tsaeb.org>
+     2 Mathieu Chabanon <git@matchab.fr>
+     2 Miloš Jovanović <mjovanovic@gmail.com>
+     2 Qwerty <champlywood@free.fr>
+     2 Timo Van Neerden <fire@lehollandaisvolant.net>
+     2 julienCXX <software@chmodplusx.eu>
+     2 kalvn <kalvnthereal@gmail.com>
+     1 Adrien Oliva <adrien.oliva@yapbreak.fr>
+     1 Alexis J <alexis@effingo.be>
+     1 BoboTiG <bobotig@gmail.com>
+     1 Bronco <bronco@warriordudimanche.net>
+     1 D Low <daniellowtw@gmail.com>
+     1 Dimtion <zizou.xena@gmail.com>
+     1 Fanch <fanch-github@qth.fr>
+     1 Felix Bartels <felix@host-consultants.de>
+     1 Felix Kästner <github.com-fpunktk@fpunktk.de>
+     1 Florian Voigt <flvoigt@me.com>
+     1 Gary Marigliano <gmarigliano93@gmail.com>
+     1 Guillaume Virlet <github@virlet.org>
+     1 Jonathan Druart <jonathan.druart@gmail.com>
+     1 Julien Pivotto <roidelapluie@inuits.eu>
+     1 Kevin Canévet <kevin@streamroot.io>
+     1 Knah Tsaeb <knah-tsaeb@knah-tsaeb.org>
+     1 Lionel Martin <renarddesmers@gmail.com>
+     1 Marsup <marsup@gmail.com>
+     1 Sbgodin <Sbgodin@users.noreply.github.com>
+     1 TsT <tst2005@gmail.com>
+     1 dimtion <zizou.xena@gmail.com>
diff --git a/COPYING b/COPYING
index 547ea570d549cc87d720756b926bf46f43b8c273..4bbdf2b3c95bb18bf984bb0f6084793231bb40fb 100644 (file)
--- a/COPYING
+++ b/COPYING
@@ -1,33 +1,7 @@
 Files: *
 License: zlib/libpng
 Copyright: (c) 2011-2015 Sébastien SAUVAGE <sebsauvage@sebsauvage.net>
-           (c) 2011-2015 Alexandre Alapetite <alexandre@alapetite.fr>
-           (c) 2011-2015 David Sferruzza <david.sferruzza@gmail.com>
-           (c) 2011-2015 Christophe HENRY <christophe.henry@sbgodin.fr>
-           (c) 2011-2015 Mathieu Chabanon <git@matchab.fr>
-           (c) 2011-2015 BoboTiG <bobotig@gmail.com>
-           (c) 2011-2015 Bronco <bronco@warriordudimanche.net>
-           (c) 2011-2015 Emilien Klein <emilien@klein.st>
-           (c) 2011-2015 Knah Tsaeb <knah-tsaeb@knah-tsaeb.org>
-           (c) 2011-2015 Lionel Martin <renarddesmers@gmail.com>
-           (c) 2011-2015 lehollandaisvolant <levoltigeurhollandais@gmail.com>
-           (c) 2011-2015 timo van neerden <fire@lehollandaisvolant.net>
-           (c) 2011-2015 nodiscc <nodiscc@gmail.com>
-           (c) 2011-2015 Florian Eula <mr.pikzen@gmail.com>
-           (c) 2011-2015 Arthur Hoaro <arthur@hoa.ro>
-           (c) 2011-2015 Aurélien "VirtualTam" Tamisier <virtualtam@flibidi.net>
-           (c) 2011-2015 qwertygc <champlywood@free.fr>
-           (c) 2011-2015 idleman <idleman@idleman.fr>
-           (c) 2015 Alexis Ju <alexis@effingo.be>
-           (c) 2015 dimtion <zizou.xena@gmail.com>
-           (c) 2015 Fanch <fanch-github@qth.fr>
-           (c) 2015 Guillaume Virlet <github@virlet.org>
-           (c) 2015 Felix Bartels <felix@host-consultants.de>
-           (c) 2015 Marsup <marsup@gmail.com>
-           (c) 2015 Miloš Jovanović <mjovanovic@gmail.com>
-           (c) 2015 Nicolás Danelón <hola@nicolasdanelon.com.ar>
-           (c) 2015 TsT <tst2005@gmail.com>
-
+           (c) 2011-2017 The Shaarli Community, see AUTHORS
 
 Files: inc/reset.css
 License: BSD (http://opensource.org/licenses/BSD-3-Clause)
index 60aec9a08b6049328ee031dd7e19fbaeafc8664e..f3065b77ed2658856018372444844dc00e4575da 100644 (file)
--- 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
index e8fc1f5db45fc4ca11da2793068c373013339614..a81f90565fb3b79349981cadb049de3a2fe2d6aa 100644 (file)
@@ -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);
index cf58f8083355af37e0a9271cf1168823252708dc..976474de721ad14636b9b431f0cec06a8920e120 100644 (file)
@@ -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;
index 621c7238336a4e128187ca576b0d2784aaadcf86..eb03c6d3afe6cc6be66062fb2050ac6dfe3170b5 100644 (file)
@@ -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');
+    }
 }
 
 /**
index 162e88e0bc06ea50a43e6cc1cc289212962b1edf..522091cac39328222d790b441f29195e2d64fe78 100644 (file)
@@ -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'));
     }
 
     /**
index e553d1ddcfd3564f3a8abdeeb575a9f428ee248b..a54dfb1d06f89231a863cc44fa1e3d8894974569 100644 (file)
--- 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();
index 4d4dd9b979c8180b3ffd05c816ba4e6c1600287e..d9753b1d6bdafc6b92aa8771e3e748ae7e605d66 100644 (file)
@@ -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();
index c3b837f5de350bb683804f1f408767d4afafcf27..17b78b17ccda034cf074c4a175e07ce843b9b15a 100644 (file)
@@ -8,7 +8,7 @@
 <link href="images/favicon.ico#" rel="shortcut icon" type="image/x-icon" />
 <link type="text/css" rel="stylesheet" href="css/reset.css" />
 <link type="text/css" rel="stylesheet" href="css/shaarli.css" />
-{if="is_file('inc/user.css')"}<link type="text/css" rel="stylesheet" href="inc/user.css#" />{/if}
+{if="is_file('data/user.css')"}<link type="text/css" rel="stylesheet" href="data/user.css#" />{/if}
 {loop="$plugins_includes.css_files"}
 <link type="text/css" rel="stylesheet" href="{$value}#"/>
 {/loop}