Skip to content

Commit

Permalink
Merge pull request #86 from projectdiscovery/dev
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
ehsandeep authored Oct 24, 2022
2 parents b0993e2 + 1275b21 commit dfb65f6
Show file tree
Hide file tree
Showing 15 changed files with 443 additions and 118 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ jobs:
- name: Test
run: go test ./...
working-directory: .

# - name: Integration Tests
# env:
# GH_ACTION: true
# run: bash run.sh
# working-directory: integration_tests/
#

- name: Race Condition Tests
run: go build -race .
working-directory: cmd/uncover/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3.2.0
uses: golangci/golangci-lint-action@v3.3.0
with:
version: latest
args: --timeout 5m
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/provider-integration.yml
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/


25 changes: 13 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,38 @@ go 1.17
require (
github.com/hashicorp/golang-lru v0.5.4
github.com/julienschmidt/httprouter v1.3.0
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/pkg/errors v0.9.1
github.com/projectdiscovery/fdmax v0.0.3
github.com/projectdiscovery/fileutil v0.0.0-20220609150212-453ac591c36c
github.com/projectdiscovery/fileutil v0.0.1
github.com/projectdiscovery/folderutil v0.0.0-20220212074351-38f1c1d2fdd4
github.com/projectdiscovery/goflags v0.0.9
github.com/projectdiscovery/goflags v0.1.1
github.com/projectdiscovery/gologger v1.1.4
github.com/projectdiscovery/iputil v0.0.0-20220613112553-9b6873b2c619
github.com/projectdiscovery/mapcidr v1.0.1
github.com/projectdiscovery/iputil v0.0.0-20220712175312-b9406f31cdd8
github.com/projectdiscovery/mapcidr v1.0.3
github.com/projectdiscovery/ratelimit v0.0.1
github.com/projectdiscovery/retryablehttp-go v1.0.2
github.com/projectdiscovery/stringsutil v0.0.0-20220612082425-0037ce9f89f3
github.com/projectdiscovery/stringsutil v0.0.1
github.com/stretchr/testify v1.8.0
go.uber.org/ratelimit v0.2.0
)

require (
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/microcosm-cc/bluemonday v1.0.19 // indirect
github.com/microcosm-cc/bluemonday v1.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/projectdiscovery/blackrock v0.0.0-20210903102120-5a9d2412d21d // indirect
github.com/projectdiscovery/blackrock v0.0.0-20220628111055-35616c71b2dc // indirect
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
93 changes: 75 additions & 18 deletions go.sum

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions integration-tests/integration-test.go
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
}
19 changes: 19 additions & 0 deletions integration-tests/run.sh
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
110 changes: 110 additions & 0 deletions integration-tests/source-test.go
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)
}
4 changes: 2 additions & 2 deletions runner/banners.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const banner = `
__ ______ _________ _ _____ _____
/ / / / __ \/ ___/ __ \ | / / _ \/ ___/
/ /_/ / / / / /__/ /_/ / |/ / __/ /
\__,_/_/ /_/\___/\____/|___/\___/_/ v0.0.8
\__,_/_/ /_/\___/\____/|___/\___/_/ v0.0.9
`

// Version is the current version of uncover
const Version = `v0.0.8`
const Version = `v0.0.9`

// showBanner is used to show the banner to the user
func showBanner() {
Expand Down
Loading

0 comments on commit dfb65f6

Please sign in to comment.