Created
February 19, 2021 02:06
-
-
Save sminnee/e36f4094c2a5a303b5ab83577da5bfb4 to your computer and use it in GitHub Desktop.
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
diff --git a/app/tests/Service/Advisories/SecurityAdvisoriesTest.php b/app/tests/Service/Advisories/SecurityAdvisoriesTest.php | |
new file mode 100644 | |
index 0000000..ff18429 | |
--- /dev/null | |
+++ b/app/tests/Service/Advisories/SecurityAdvisoriesTest.php | |
@@ -0,0 +1,108 @@ | |
+<?php | |
+ | |
+use SilverStripe\Dev\SapphireTest; | |
+ | |
+class SecurityAdvisoriesTest extends SapphireTest | |
+{ | |
+ | |
+ /** | |
+ * @dataProvider expandVersionsTestData | |
+ */ | |
+ public function testExpandVersions($input, $versionList, $output) | |
+ { | |
+ | |
+ $reader = new SecurityAdvisories(); | |
+ $method = new ReflectionMethod('SecurityAdvisories', 'expandVersions'); | |
+ $method->setAccessible(true); | |
+ $result = $method->invoke($reader, $input, $versionList); | |
+ | |
+ $this->assertEquals($output, iterator_to_array($result, false)); | |
+ } | |
+ | |
+ public function expandVersionsTestData() | |
+ { | |
+ $versionList = [ | |
+ [ 'package' => 'silverstripe/framework', 'version' => '3.7.0' ], | |
+ [ 'package' => 'silverstripe/framework', 'version' => '3.8.0' ], | |
+ [ 'package' => 'silverstripe/framework', 'version' => '4.1.0' ], | |
+ [ 'package' => 'silverstripe/framework', 'version' => '4.1.x-dev' ], | |
+ [ 'package' => 'silverstripe/framework', 'version' => '4.1.1' ], | |
+ [ 'package' => 'silverstripe/framework', 'version' => '4.1.2', ], | |
+ [ 'package' => 'silverstripe/framework', 'version' => '4.1.3' ], | |
+ [ 'package' => 'silverstripe/framework', 'version' => '4.2.0' ], | |
+ [ 'package' => 'silverstripe/framework', 'version' => '4.2.2' ], | |
+ [ 'package' => 'silverstripe/framework', 'version' => 'dev-master' ], | |
+ [ 'package' => 'package/other', 'version' => '4.1.x-dev' ], | |
+ ]; | |
+ | |
+ return [ | |
+ 'Basic test' => [ | |
+ 'input' => [ | |
+ [ | |
+ 'vuln_id' => 'A', | |
+ 'package'=> 'silverstripe/framework', | |
+ 'title' => 'Vuln A', | |
+ 'branches' => [ | |
+ [ 'versions' => '>=4.1.0,<4.1.2' ], | |
+ [ 'versions' => '^4.2,<4.2.2' ], | |
+ ], | |
+ ], | |
+ [ | |
+ 'vuln_id' => 'B', | |
+ 'title' => 'Vuln B', | |
+ 'package'=> 'silverstripe/framework', | |
+ 'branches' => [ | |
+ [ 'versions' => '^3,<3.8.0' ], | |
+ ], | |
+ ], | |
+ [ | |
+ 'vuln_id' => 'C', | |
+ 'title' => 'Vuln C', | |
+ 'package'=> 'package/other', | |
+ 'branches' => [ | |
+ [ 'versions' => '^4' ], | |
+ ], | |
+ ], | |
+ ], | |
+ 'versionList' => $versionList, | |
+ 'output' => [ | |
+ [ | |
+ 'package' => 'silverstripe/framework', | |
+ 'version' => '3.7.0', | |
+ 'vulns' => [ | |
+ [ 'vuln_id' => 'B', 'title' => 'Vuln B', ], | |
+ ] | |
+ ], | |
+ [ | |
+ 'package' => 'silverstripe/framework', | |
+ 'version' => '4.1.0', | |
+ 'vulns' => [ | |
+ [ 'vuln_id' => 'A', 'title' => 'Vuln A', ], | |
+ ] | |
+ ], | |
+ [ | |
+ 'package' => 'silverstripe/framework', | |
+ 'version' => '4.1.1', | |
+ 'vulns' => [ | |
+ [ 'vuln_id' => 'A', 'title' => 'Vuln A', ], | |
+ ] | |
+ ], | |
+ [ | |
+ 'package' => 'silverstripe/framework', | |
+ 'version' => '4.2.0', | |
+ 'vulns' => [ | |
+ [ 'vuln_id' => 'A', 'title' => 'Vuln A', ], | |
+ ] | |
+ ], | |
+ [ | |
+ 'package' => 'package/other', | |
+ 'version' => '4.1.x-dev', | |
+ 'vulns' => [ | |
+ [ 'vuln_id' => 'C', 'title' => 'Vuln C', ], | |
+ ] | |
+ ], | |
+ ], | |
+ ], | |
+ ]; | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment