forked from joernio/joern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[php] allow custom file extensions in frontend
* add option in frontend to associate custom file extensions to PHP * add tests
- Loading branch information
Showing
3 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...-cli/frontends/php2cpg/src/test/scala/io/joern/php2cpg/passes/PhpFileExtensionsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package io.joern.php2cpg.passes | ||
|
||
import io.joern.php2cpg.Config | ||
import io.joern.php2cpg.parser.Domain.PhpOperators | ||
import io.joern.php2cpg.testfixtures.PhpCode2CpgFixture | ||
import io.shiftleft.semanticcpg.language.* | ||
|
||
class PhpFileExtensionsTest extends PhpCode2CpgFixture() { | ||
|
||
"two files with two new extensions associated with PHP" should { | ||
|
||
val cpg = code( | ||
""" | ||
|require 'vendor/autoload.php'; | ||
| | ||
|$s3 = new S3Client([ | ||
| 'version' => 'latest', | ||
| 'region' => 'us-east-1', | ||
| 'credentials' => [ | ||
| 'key' => 'YOUR_AWS_ACCESS_KEY_ID', | ||
| 'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY', | ||
| ] | ||
|]); | ||
|""".stripMargin, | ||
"sample.php" | ||
) | ||
.moreCode( | ||
"""<?php | ||
|require 'vendor/autoload.php'; | ||
| | ||
|$s3 = new S3Client([ | ||
| 'version' => 'latest', | ||
| 'region' => 'us-east-1', | ||
| 'credentials' => [ | ||
| 'key' => 'YOUR_AWS_ACCESS_KEY_ID', | ||
| 'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY', | ||
| ] | ||
|]); | ||
| | ||
|""".stripMargin, | ||
"something.cls" | ||
) | ||
.withConfig(Config().withExtensions(Set(".php", ".cls"))) | ||
|
||
"be scanned and present in cpg" in { | ||
cpg.file.name.l shouldBe List("sample.php", "something.cls", "<unknown>") | ||
cpg.file.name.l.size shouldBe 3 | ||
} | ||
|
||
} | ||
|
||
"two files with only default (.php) extension associated with PHP" should { | ||
|
||
val cpg = code( | ||
""" | ||
|require 'vendor/autoload.php'; | ||
| | ||
|$s3 = new S3Client([ | ||
| 'version' => 'latest', | ||
| 'region' => 'us-east-1', | ||
| 'credentials' => [ | ||
| 'key' => 'YOUR_AWS_ACCESS_KEY_ID', | ||
| 'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY', | ||
| ] | ||
|]); | ||
|""".stripMargin, | ||
"sample.php" | ||
) | ||
.moreCode( | ||
"""<?php | ||
|require 'vendor/autoload.php'; | ||
| | ||
|$s3 = new S3Client([ | ||
| 'version' => 'latest', | ||
| 'region' => 'us-east-1', | ||
| 'credentials' => [ | ||
| 'key' => 'YOUR_AWS_ACCESS_KEY_ID', | ||
| 'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY', | ||
| ] | ||
|]); | ||
| | ||
|""".stripMargin, | ||
"something.cls" | ||
) | ||
|
||
"be scanned and one default extension present in cpg" in { | ||
cpg.file.name.l shouldBe List("sample.php", "<unknown>") | ||
cpg.file.name.l.size shouldBe 2 | ||
} | ||
} | ||
|
||
} |