-
Notifications
You must be signed in to change notification settings - Fork 135
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 #167 from projectdiscovery/dev
v1.0.2
- Loading branch information
Showing
25 changed files
with
423 additions
and
86 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
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,20 @@ | ||
#!/bin/bash | ||
|
||
rm -f final-config.yaml temp.yaml | ||
( echo "cat <<EOF >final-config.yaml"; | ||
cat test-config.yaml; | ||
echo "EOF"; | ||
) >temp.yaml | ||
. temp.yaml | ||
rm integration-test notify 2>/dev/null | ||
|
||
go build ../notify | ||
go build | ||
|
||
DEBUG=true ./integration-test --provider-config final-config.yaml | ||
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,45 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/logrusorgru/aurora" | ||
"github.com/projectdiscovery/notify/internal/testutils" | ||
) | ||
|
||
var ( | ||
providerConfig = flag.String("provider-config", "", "provider config to use for testing") | ||
debug = os.Getenv("DEBUG") == "true" | ||
errored = false | ||
success = aurora.Green("[✓]").String() | ||
failed = aurora.Red("[✘]").String() | ||
testCases = map[string]testutils.TestCase{ | ||
"discord": &discord{}, | ||
"slack": &slack{}, | ||
"custom": &custom{}, | ||
// "telegram": &telegram{}, | ||
// "teams": &teams{}, | ||
// "smtp": &smtp{}, | ||
// "pushover": &pushover{}, | ||
} | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
for name, test := range testCases { | ||
fmt.Printf("Running test cases for \"%s\"\n", aurora.Blue(name)) | ||
err := test.Execute() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, name, err) | ||
errored = true | ||
} else { | ||
fmt.Printf("%s Test \"%s\" passed!\n", success, name) | ||
} | ||
} | ||
if errored { | ||
os.Exit(1) | ||
} | ||
} |
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,74 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/projectdiscovery/notify/internal/testutils" | ||
) | ||
|
||
func run(provider string) error { | ||
args := []string{"--provider", provider} | ||
if *providerConfig != "" { | ||
args = append(args, "--provider-config", *providerConfig) | ||
} | ||
results, err := testutils.RunNotifyAndGetResults(debug, args...) | ||
if err != nil { | ||
return err | ||
} | ||
if len(results) < 1 { | ||
return errIncorrectResultsCount(results) | ||
} | ||
for _, r := range results { | ||
if !strings.Contains(r, provider) { | ||
return fmt.Errorf("incorrect result %s", results[0]) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
type discord struct{} | ||
|
||
func (h *discord) Execute() error { | ||
return run("discord") | ||
} | ||
|
||
type custom struct{} | ||
|
||
func (h *custom) Execute() error { | ||
return run("custom") | ||
} | ||
|
||
type slack struct{} | ||
|
||
func (h *slack) Execute() error { | ||
return run("slack") | ||
} | ||
|
||
// type pushover struct{} | ||
// | ||
// func (h *pushover) Execute() error { | ||
// return run("pushover") | ||
// } | ||
// | ||
// type smtp struct{} | ||
// | ||
// func (h *smtp) Execute() error { | ||
// return run("smtp") | ||
// } | ||
// | ||
// type teams struct{} | ||
// | ||
// func (h *teams) Execute() error { | ||
// return run("teams") | ||
// } | ||
// | ||
// type telegram struct{} | ||
// | ||
// func (h *telegram) Execute() error { | ||
// return run("telegram") | ||
// } | ||
|
||
func errIncorrectResultsCount(results []string) error { | ||
return fmt.Errorf("incorrect number of results %s", strings.Join(results, "\n\t")) | ||
} |
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,14 @@ | ||
#!/bin/bash | ||
|
||
rm integration-test notify 2>/dev/null | ||
|
||
go build ../notify | ||
go build | ||
|
||
./integration-test | ||
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,42 @@ | ||
discord: | ||
- id: "disocord-integration-test" | ||
discord_webhook_url: "${DISCORD_WEBHOOK_URL}" | ||
discord_format: "{{data}}" | ||
slack: | ||
- id: "slack-integration-test" | ||
slack_channel: "random" | ||
slack_username: "test" | ||
slack_webhook_url: "${SLACK_WEBHOOK_URL}" | ||
slack_format: "{{data}}" | ||
telegram: | ||
- id: "telegram-integration-test" | ||
telegram_api_key: "${telegram_api_key}" | ||
telegram_chat_id: "${telegram_chat_id}" | ||
telegram_format: "{{data}}" | ||
custom: | ||
- id: "custom-integration-test" | ||
custom_webook_url: "${CUSTOM_WEBOOK_URL}" | ||
custom_method: POST | ||
custom_format: '{{data}}' | ||
custom_headers: | ||
Content-Type: application/json | ||
pushover: | ||
- id: "push" | ||
pushover_user_key: "${pushover_user_key}" | ||
pushover_api_token: "${pushover_api_token}" | ||
pushover_format: "{{data}}" | ||
pushover_devices: | ||
- "iphone" | ||
smtp: | ||
- id: email | ||
smtp_server: "${smtp_server}" | ||
smtp_username: "${smtp_username}" | ||
smtp_password: "${smtp_password}" | ||
from_address: "${smtp_from_address}" | ||
smtp_cc: | ||
- "${smtp_cc}" | ||
smtp_format: "{{data}}" | ||
teams: | ||
- id: teams-integration-test | ||
teams_webhook_url: "${teams_webhook_url}" | ||
teams_format: "{{data}}" |
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
Oops, something went wrong.