Passed
Push — master ( 5c87ed...e4bb53 )
by Stefan
04:05
created

MockProfileSilverbullet   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A generateCertificate() 0 2 1
A isGeneratedCertificate() 0 2 2
A delete() 0 3 1
A revokeCertificate() 0 5 2
1
<?php
2
/* 
3
 *******************************************************************************
4
 * Copyright 2011-2017 DANTE Ltd. and GÉANT on behalf of the GN3, GN3+, GN4-1 
5
 * and GN4-2 consortia
6
 *
7
 * License: see the web/copyright.php file in the file structure
8
 *******************************************************************************
9
 */
10
11
/**
12
 * 
13
 * @author Zilvinas Vaira
14
 *
15
 */
16
class MockProfileSilverbullet extends \core\ProfileSilverbullet{
17
    
18
    /**
19
     * 
20
     * @var int
21
     */
22
    private $instId;
23
    
24
    /**
25
     * 
26
     * @var array
27
     */
28
    private $generatedCertificates = array();
29
    
30
    /**
31
     * 
32
     * @param \core\DBConnection $databaseHandle
33
     */
34
    public function __construct(\core\DBConnection $databaseHandle){
35
        $this->databaseHandle = $databaseHandle;
36
        if($this->databaseHandle->exec("INSERT INTO institution (country) VALUES('LT')")){
37
            $this->instId = $this->databaseHandle->lastID();
38
        }
39
        if($this->databaseHandle->exec("INSERT INTO profile (inst_id, realm) VALUES($this->instId, 'test.realm.tst')")){
40
            $this->identifier = $this->databaseHandle->lastID();
41
        }
42
        $this->attributes = array(array('name' => 'hiddenprofile:tou_accepted'));
43
    }
44
    
45
    /**
46
     * 
47
     */
48
    public function delete(){
49
        $this->databaseHandle->exec("DELETE FROM `institution` WHERE `inst_id`='" . $this->instId . "'");
50
        $this->databaseHandle->exec("DELETE FROM `profile` WHERE `profile_id`='" . $this->identifier . "'");
51
    }
52
    
53
    /**
54
     * 
55
     * {@inheritDoc}
56
     * @see \core\ProfileSilverbullet::generateCertificate()
57
     */
58
    public function generateCertificate($serial, $cn){
59
        $this->generatedCertificates[$serial] = $cn;
60
    }
61
    
62
    /**
63
     * 
64
     * {@inheritDoc}
65
     * @see \core\ProfileSilverbullet::revokeCertificate()
66
     */
67
    public function revokeCertificate($serial){
68
        if(isset($this->generatedCertificates[$serial])){
69
            unset($this->generatedCertificates[$serial]);
70
            $nowSql = (new \DateTime())->format("Y-m-d H:i:s");
71
            $this->databaseHandle->exec("UPDATE silverbullet_certificate SET revocation_status = 'REVOKED', revocation_time = ? WHERE serial_number = ?", "si", $nowSql, $serial);
72
        }
73
    }
74
    
75
    /**
76
     * 
77
     * @param string $serial
78
     * @param string $cn
79
     * @return boolean
80
     */
81
    public function isGeneratedCertificate($serial, $cn){
82
        return isset($this->generatedCertificates[$serial]) && $this->generatedCertificates[$serial]==$cn;
83
    }
84
}
85