GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 932629...d7a7a8 )
by François
03:12
created

TotpTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
/**
3
 *  Copyright (C) 2016 SURFnet.
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as
7
 *  published by the Free Software Foundation, either version 3 of the
8
 *  License, or (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace SURFnet\VPN\Server\Tests;
20
21
use DateTime;
22
use PDO;
23
use PHPUnit_Framework_TestCase;
24
use SURFnet\VPN\Server\Exception\TotpException;
25
use SURFnet\VPN\Server\Storage;
26
use SURFnet\VPN\Server\Totp;
27
28
class TotpTest extends PHPUnit_Framework_TestCase
29
{
30
    /** @var Totp */
31
    private $totp;
32
33
    public function setUp()
0 ignored issues
show
Coding Style introduced by
setUp uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
34
    {
35
        $storage = new Storage(
36
            new PDO(
37
                $GLOBALS['DB_DSN'],
38
                $GLOBALS['DB_USER'],
39
                $GLOBALS['DB_PASSWD']
40
            ),
41
            new DateTime()
42
        );
43
        $storage->init();
44
        $storage->setTotpSecret('foo', 'CN2XAL23SIFTDFXZ');
45
46
        $this->totp = new Totp($storage);
47
    }
48
49
    /**
50
     * @expectedException \SURFnet\VPN\Server\Exception\TotpException
51
     * @expectedExceptionMessage too many attempts at TOTP
52
     */
53
    public function testTooManyReplays()
54
    {
55
        for ($i = 0; $i < 10; ++$i) {
56
            try {
57
                $this->totp->verify('foo', (string) 123456 + $i);
58
            } catch (TotpException $e) {
59
                $this->assertSame('invalid TOTP key', $e->getMessage());
60
            }
61
        }
62
        $this->totp->verify('foo', '555555');
63
    }
64
}
65