Issues (11)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

EmailTemplatesTest/Service/EmailServiceTest.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @author Antoine Hedgcock
4
 */
5
6
namespace EmailTemplatesTest\Service;
7
8
use PHPUnit_Framework_MockObject_MockObject;
9
use PHPUnit_Framework_TestCase;
10
use Roave\EmailTemplates\Options\EmailServiceOptions;
11
use Roave\EmailTemplates\Service\EmailService;
12
use Roave\EmailTemplates\Service\TemplateServiceInterface;
13
use Zend\Mail\Message;
14
use Zend\Mail\Transport\TransportInterface;
15
16
/**
17
 * Class EmailServiceTest
18
 *
19
 * @coversDefaultClass \Roave\EmailTemplates\Service\EmailService
20
 * @covers ::<!public>
21
 *
22
 * @group service
23
 */
24
class EmailServiceTest extends PHPUnit_Framework_TestCase
25
{
26
    /**
27
     * @var EmailServiceOptions
28
     */
29
    protected $options;
30
31
    /**
32
     * @var TemplateServiceInterface|PHPUnit_Framework_MockObject_MockObject
33
     */
34
    protected $templateService;
35
36
    /**
37
     * @var EmailService
38
     */
39
    protected $service;
40
41
    /**
42
     * @covers ::__construct
43
     */
44
    protected function setUp()
45
    {
46
        $this->options         = new EmailServiceOptions();
47
        $this->templateService = $this->createMock(TemplateServiceInterface::class);
48
49
        $this->service = new EmailService(
50
            $this->templateService,
51
            $this->options
52
        );
53
    }
54
55
    private function mockRender()
56
    {
57
        $this->templateService
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Roave\EmailTemplates\Ser...emplateServiceInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
58
            ->expects($this->any())
59
            ->method('render')
60
            ->willReturn(['subject', 'html', 'text']);
61
    }
62
63
    /**
64
     * @covers ::setTransport
65
     */
66
    public function testSetTransport()
67
    {
68
        $this->service->setTransport($this->createMock(TransportInterface::class));
69
    }
70
71
    /**
72
     * @covers ::getTransport
73
     */
74
    public function testGetTransport()
75
    {
76
        $transport = $this->service->getTransport();
77
78
        $this->assertInstanceOf($this->options->getDefaultTransport(), $transport);
79
80
        $transport = $this->createMock(TransportInterface::class);
81
        $this->service->setTransport($transport);
82
83
        $this->assertSame($transport, $this->service->getTransport());
84
    }
85
86
    /**
87
     * @covers ::send
88
     */
89
    public function testSend()
90
    {
91
        $email      = '[email protected]';
92
        $locale     = 'sv_SE';
93
        $templateId = 'roave:contact';
94
        $parameters = ['name' => 'Antoine'];
95
96
        $this->mockRender();
97
98
        $transport = $this->createMock(TransportInterface::class);
99
        $transport
100
            ->expects($this->once())
101
            ->method('send')
102
            ->with($this->isInstanceOf(Message::class));
103
104
        $this->service->setTransport($transport);
105
        $this->service->send($email, $templateId, $parameters, $locale);
106
    }
107
108
    /**
109
     * @covers ::send
110
     */
111
    public function testSendHasCorrectContentType()
112
    {
113
        $email      = '[email protected]';
114
        $locale     = 'sv_SE';
115
        $templateId = 'roave:contact';
116
        $parameters = ['name' => 'Hotas'];
117
118
        $this->mockRender();
119
120
        $transport = $this->createMock(TransportInterface::class);
121
        $transport
122
            ->expects($this->once())
123
            ->method('send')
124
            ->with($this->isInstanceOf(Message::class))
125
            ->will($this->returnCallback(function(Message $message) {
126
                $contentType = $message->getHeaders()->get('content-type');
127
                $this->assertContains('multipart/alternative', $contentType->getFieldValue());
128
            }));
129
130
        $this->service->setTransport($transport);
131
        $this->service->send($email, $templateId, $parameters, $locale);
132
    }
133
134
    /**
135
     * @covers ::send
136
     */
137
    public function testSendCanOverrideReplyToHeader()
138
    {
139
        $email      = '[email protected]';
140
        $locale     = 'sv_SE';
141
        $templateId = 'roave:contact';
142
        $parameters = ['name' => 'Hotas'];
143
        $replyTo    = '[email protected]';
144
145
        $this->mockRender();
146
147
        $transport = $this->createMock(TransportInterface::class);
148
        $transport
149
            ->expects($this->at(0))
150
            ->method('send')
151
            ->with($this->isInstanceOf(Message::class))
152
            ->will($this->returnCallback(function(Message $message) {
153
                $replyToField = $message->getHeaders()->get('Reply-To');
154
                $this->assertContains($this->options->getReplyTo(), $replyToField->getFieldValue());
0 ignored issues
show
The method getFieldValue does only exist in Zend\Mail\Header\HeaderInterface, but not in ArrayIterator.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
155
            }));
156
157
        $transport
158
            ->expects($this->at(1))
159
            ->method('send')
160
            ->with($this->isInstanceOf(Message::class))
161
            ->will($this->returnCallback(function(Message $message) use ($replyTo) {
162
                $replyToField = $message->getHeaders()->get('Reply-To');
163
                $this->assertContains($replyTo, $replyToField->getFieldValue());
0 ignored issues
show
The method getFieldValue does only exist in Zend\Mail\Header\HeaderInterface, but not in ArrayIterator.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
164
            }));
165
166
        $this->service->setTransport($transport);
167
        $this->service->send($email, $templateId, $parameters, $locale, null);
168
        $this->service->send($email, $templateId, $parameters, $locale, $replyTo);
169
    }
170
}
171