Issues (24)

Security Analysis    not enabled

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.

src/Providers/ModuleTestingServiceProvider.php (1 issue)

Labels
Severity

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
4
namespace SmartWeb\ModuleTesting\Providers;
5
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\Facades\File;
8
use Illuminate\Support\ServiceProvider;
9
use SmartWeb\ModuleTesting\BaseAcceptanceCest;
10
use SmartWeb\ModuleTesting\BaseGraphQLCest;
11
use SmartWeb\ModuleTesting\BaseIntegrationCest;
12
use SmartWeb\ModuleTesting\BaseUnitTest;
13
use SmartWeb\ModuleTesting\Console\Command\GenerateCest;
14
use SmartWeb\ModuleTesting\Console\Command\GenerateSetup;
15
use SmartWeb\ModuleTesting\Console\Command\GenerateTest;
16
use SmartWeb\ModuleTesting\Generator\Test\BaseClassResolver;
17
use SmartWeb\ModuleTesting\Generator\Test\CodeceptionTestType;
18
use SmartWeb\ModuleTesting\Template\TemplateFactory;
19
use SmartWeb\ModuleTesting\Util\FileUtil;
20
use const DIRECTORY_SEPARATOR;
21
use function glob;
22
use function implode;
23
24
/**
25
 * Class ModuleTestingServiceProvider
26
 *
27
 * @package SmartWeb\ModuleTesting\Providers
28
 */
29
class ModuleTestingServiceProvider extends ServiceProvider
30
{
31
    
32
    /**
33
     * Indicates if loading of the provider is deferred.
34
     *
35
     * @var bool
36
     */
37
    protected $defer = false;
38
    
39
    /**
40
     * Boot the application events.
41
     */
42
    public function boot()
43
    {
44
        if ($this->app->environment() !== 'production') {
45
            $this->includeCodeceptionShim();
46
            
47
            $this->registerConfig();
48
            $this->registerHelpers();
49
            $this->registerMacros();
50
            
51
            $this->registerBaseTestClasses();
52
            $this->registerTemplates();
53
            
54
            $this->registerProviders();
55
        }
56
    }
57
    
58
    private function includeCodeceptionShim()
59
    {
60
        $vendorDir = FileUtil::findParentDir(__DIR__, 'vendor');
61
        require_once $vendorDir . '/codeception/codeception/shim.php';
62
    }
63
    
64
    /**
65
     * Register config.
66
     *
67
     * @return void
68
     */
69
    protected function registerConfig()
70
    {
71
        $this->publishes([
72
            __DIR__ . '/../Config/config.php' => config_path('testing.php'),
73
        ], 'config');
74
        $this->mergeConfigFrom(
75
            __DIR__ . '/../Config/config.php', 'testing'
76
        );
77
    }
78
    
79
    protected function registerHelpers()
80
    {
81
        foreach (glob($this->path('Helpers/*.php')) as $file) {
82
            File::requireOnce($file);
83
        }
84
    }
85
    
86
    protected function registerMacros()
87
    {
88
        Collection::macro('mapIntoWithValues', function (string $class) {
89
            /**
90
             * @var Collection $this
91
             */
92
            return $this->map(function ($value) use ($class) {
0 ignored issues
show
The method map() does not seem to exist on object<SmartWeb\ModuleTe...TestingServiceProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
93
                return new $class($value);
94
            });
95
        });
96
    }
97
    
98
    protected function registerBaseTestClasses()
99
    {
100
        $baseClasses = [
101
            'test' => [
102
                'Unit' => BaseUnitTest::class,
103
            ],
104
            'cest' => [
105
                'Integration' => BaseIntegrationCest::class,
106
                'GraphQL'     => BaseGraphQLCest::class,
107
                'Acceptance'  => BaseAcceptanceCest::class,
108
            ],
109
            'cept' => [],
110
        ];
111
        
112
        foreach ($baseClasses as $type => $classesForType) {
113
            /**
114
             * @var CodeceptionTestType $type
115
             * @var string[]            $classesForType
116
             */
117
            $type = CodeceptionTestType::memberByKey($type);
118
            
119
            foreach ($classesForType as $suite => $baseClass) {
120
                BaseClassResolver::registerBaseClassForModule($type, $suite, BaseClassResolver::DEFAULT_MODULE, $baseClass);
121
            }
122
        }
123
    }
124
    
125
    protected function registerTemplates()
126
    {
127
        TemplateFactory::registerTemplate(
128
            CodeceptionTestType::test(),
129
            'Unit',
130
            $this->templatePath('test.unit.tpl')
131
        );
132
        
133
        TemplateFactory::registerTemplate(
134
            CodeceptionTestType::cest(),
135
            'Integration',
136
            $this->templatePath('cest.integration.tpl')
137
        );
138
        
139
        TemplateFactory::registerTemplate(
140
            CodeceptionTestType::cest(),
141
            'GraphQL',
142
            $this->templatePath('cest.graphql.tpl')
143
        );
144
    }
145
    
146
    protected function registerProviders()
147
    {
148
        $this->app->register(ExpressionLanguageServiceProvider::class);
149
    }
150
    
151
    /**
152
     * @param string $template
153
     *
154
     * @return string
155
     */
156
    protected function templatePath(string $template) : string
157
    {
158
        return TemplateFactory::DEFAULT_TEMPLATE_DIR . DIRECTORY_SEPARATOR . $template;
159
    }
160
    
161
    /**
162
     * Register the service provider.
163
     *
164
     * @return void
165
     */
166
    public function register()
167
    {
168
        $this->registerCommands();
169
    }
170
    
171
    /**
172
     * Get the services provided by the provider.
173
     *
174
     * @return array
175
     */
176
    public function provides()
177
    {
178
        return [];
179
    }
180
    
181
    protected function registerCommands()
182
    {
183
        $this->app->singleton(
184
            'command.smartweb.testing.generate-setup',
185
            GenerateSetup::class
186
        );
187
        
188
        $this->app->singleton(
189
            'command.smartweb.testing.generate-test',
190
            GenerateTest::class
191
        );
192
        
193
        $this->app->singleton(
194
            'command.smartweb.testing.generate-cest',
195
            GenerateCest::class
196
        );
197
        
198
        $this->commands(
199
            'command.smartweb.testing.generate-setup',
200
            'command.smartweb.testing.generate-test',
201
            'command.smartweb.testing.generate-cest');
202
    }
203
    
204
    /**
205
     * @param string[] ...$parts
206
     *
207
     * @return string
208
     */
209
    protected function path(...$parts) : string
210
    {
211
        return __DIR__ . '/../' . implode(DIRECTORY_SEPARATOR, $parts);
212
    }
213
}
214