-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from projectdiscovery/dev
Bugfix
- Loading branch information
Showing
15 changed files
with
443 additions
and
118 deletions.
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
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,30 @@ | ||
name: 🔨 Provider Test | ||
on: | ||
schedule: | ||
- cron: '00 12 * * 1' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Test Builds | ||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.17 | ||
|
||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Integration Tests | ||
env: | ||
GH_ACTION: true | ||
CENSYS_API_KEY: ${{secrets.CENSYS_API_SECRET}} | ||
FOFA_API_KEY: ${{secrets.FOFA_KEY}} | ||
SHODAN_API_KEY: ${{secrets.SHODAN_API_KEY}} | ||
ZOOMEYE_API_KEY: ${{secrets.ZOOMEYE_API_KEY}} | ||
QUAKE_API_KEY: ${{secrets.QUAKE_TOKEN}} | ||
run: bash run.sh | ||
working-directory: integration-tests/ | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/logrusorgru/aurora" | ||
|
||
"github.com/projectdiscovery/uncover/testutils" | ||
) | ||
|
||
var ( | ||
debug = os.Getenv("DEBUG") == "true" | ||
githubAction = os.Getenv("GH_ACTION") == "true" | ||
customTests = os.Getenv("TESTS") | ||
|
||
success = aurora.Green("[✓]").String() | ||
failed = aurora.Red("[✘]").String() | ||
|
||
sourceTests = map[string]testutils.TestCase{ | ||
"censys": censysTestcases{}, | ||
"shodan": shodanTestcases{}, | ||
"zoomeye": zoomeyeTestcases{}, | ||
"fofa": fofaTestcases{}, | ||
//"hunter": hunterTestcases{}, | ||
"quake": quakeTestcases{}, | ||
} | ||
) | ||
|
||
func main() { | ||
failedTestCases := runTests(toMap(toSlice(customTests))) | ||
|
||
if len(failedTestCases) > 0 { | ||
if githubAction { | ||
debug = true | ||
fmt.Println("::group::Failed integration tests in debug mode") | ||
_ = runTests(failedTestCases) | ||
fmt.Println("::endgroup::") | ||
} | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func runTests(customTestCases map[string]struct{}) map[string]struct{} { | ||
failedTestCases := map[string]struct{}{} | ||
|
||
for source, testCase := range sourceTests { | ||
if len(customTestCases) == 0 { | ||
fmt.Printf("Running test cases for %q source\n", aurora.Blue(source)) | ||
} | ||
if err, failedTemplatePath := execute(source, testCase); err != nil { | ||
failedTestCases[failedTemplatePath] = struct{}{} | ||
} | ||
} | ||
return failedTestCases | ||
} | ||
|
||
func execute(source string, testCase testutils.TestCase) (error, string) { | ||
if err := testCase.Execute(); err != nil { | ||
_, _ = fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, source, err) | ||
return err, source | ||
} | ||
|
||
fmt.Printf("%s Test \"%s\" passed!\n", success, source) | ||
return nil, "" | ||
} | ||
|
||
func expectResultsGreaterThanCount(results []string, expectedNumber int) error { | ||
if len(results) > expectedNumber { | ||
return nil | ||
} | ||
return fmt.Errorf("incorrect number of results: expected a result greater than %d,but got %d", expectedNumber, len(results)) | ||
} | ||
func toSlice(value string) []string { | ||
if strings.TrimSpace(value) == "" { | ||
return []string{} | ||
} | ||
|
||
return strings.Split(value, ",") | ||
} | ||
|
||
func toMap(slice []string) map[string]struct{} { | ||
result := make(map[string]struct{}, len(slice)) | ||
for _, value := range slice { | ||
if _, ok := result[value]; !ok { | ||
result[value] = struct{}{} | ||
} | ||
} | ||
return result | ||
} |
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,19 @@ | ||
#!/bin/bash | ||
|
||
echo "::task~> Clean up & Build binaries files" | ||
rm integration-test uncover 2>/dev/null | ||
cd ../cmd/uncover | ||
go build | ||
mv uncover ../../integration-tests/uncover | ||
cd ../../integration-tests | ||
go build | ||
echo "::done::" | ||
echo "::task~> Run integration test" | ||
./integration-tests | ||
echo "::done::" | ||
if [ $? -eq 0 ] | ||
then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi |
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,110 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/projectdiscovery/folderutil" | ||
"github.com/projectdiscovery/uncover/testutils" | ||
) | ||
|
||
var ( | ||
ConfigFile = filepath.Join(folderutil.HomeDirOrDefault("."), ".config/uncover/provider-config.yaml") | ||
) | ||
|
||
type censysTestcases struct{} | ||
|
||
func (h censysTestcases) Execute() error { | ||
token := os.Getenv("CENSYS_API_KEY") | ||
if token == "" { | ||
return errors.New("missing censys api key") | ||
} | ||
censysToken := fmt.Sprintf(`censys: [%s]`, token) | ||
_ = os.WriteFile(ConfigFile, []byte(censysToken), 0644) | ||
defer os.RemoveAll(ConfigFile) | ||
results, err := testutils.RunUncoverAndGetResults(debug, "-censys", "'services.software.vendor=Grafana'") | ||
if err != nil { | ||
return err | ||
} | ||
return expectResultsGreaterThanCount(results, 0) | ||
} | ||
|
||
type shodanTestcases struct{} | ||
|
||
func (h shodanTestcases) Execute() error { | ||
token := os.Getenv("SHODAN_API_KEY") | ||
if token == "" { | ||
return errors.New("missing shodan api key") | ||
} | ||
shodanToken := fmt.Sprintf(`shodan: [%s]`, token) | ||
_ = os.WriteFile(ConfigFile, []byte(shodanToken), 0644) | ||
defer os.RemoveAll(ConfigFile) | ||
results, err := testutils.RunUncoverAndGetResults(debug, "-shodan", "'title:\"Grafana\"'") | ||
if err != nil { | ||
return err | ||
} | ||
return expectResultsGreaterThanCount(results, 0) | ||
} | ||
|
||
type zoomeyeTestcases struct{} | ||
|
||
func (h zoomeyeTestcases) Execute() error { | ||
token := os.Getenv("ZOOMEYE_API_KEY") | ||
if token == "" { | ||
return errors.New("missing zoomeye api key") | ||
} | ||
zoomeyeToken := fmt.Sprintf(`zoomeye: [%s]`, token) | ||
_ = os.WriteFile(ConfigFile, []byte(zoomeyeToken), 0644) | ||
defer os.RemoveAll(ConfigFile) | ||
results, err := testutils.RunUncoverAndGetResults(debug, "-zoomeye", "'app:\"Atlassian JIRA\"'") | ||
if err != nil { | ||
return err | ||
} | ||
return expectResultsGreaterThanCount(results, 0) | ||
} | ||
|
||
type fofaTestcases struct{} | ||
|
||
func (h fofaTestcases) Execute() error { | ||
token := os.Getenv("FOFA_API_KEY") | ||
if token == "" { | ||
return errors.New("missing fofa api key") | ||
} | ||
fofaToken := fmt.Sprintf(`fofa: [%s]`, token) | ||
_ = os.WriteFile(ConfigFile, []byte(fofaToken), 0644) | ||
defer os.RemoveAll(ConfigFile) | ||
results, err := testutils.RunUncoverAndGetResults(debug, "-fofa", "'app=Grafana'") | ||
if err != nil { | ||
return err | ||
} | ||
return expectResultsGreaterThanCount(results, 0) | ||
} | ||
|
||
// type hunterTestcases struct{} | ||
|
||
// func (h hunterTestcases) Execute() error { | ||
// results, err := testutils.RunUncoverAndGetResults(debug, "-hunter", "'Grafana'") | ||
// if err != nil { | ||
// return err | ||
// } | ||
// return expectResultsGreaterOrEqualToCount(results, 0) | ||
// } | ||
|
||
type quakeTestcases struct{} | ||
|
||
func (h quakeTestcases) Execute() error { | ||
token := os.Getenv("QUAKE_API_KEY") | ||
if token == "" { | ||
return errors.New("missing quake api key") | ||
} | ||
quakeToken := fmt.Sprintf(`quake: [%s]`, token) | ||
_ = os.WriteFile(ConfigFile, []byte(quakeToken), 0644) | ||
defer os.RemoveAll(ConfigFile) | ||
results, err := testutils.RunUncoverAndGetResults(debug, "-quake", "'Grafana'") | ||
if err != nil { | ||
return err | ||
} | ||
return expectResultsGreaterThanCount(results, 0) | ||
} |
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
Oops, something went wrong.