mirror of https://github.com/statping/statping
twilio notifier fix, enabled more testing
parent
b0aaf228a1
commit
3fa5269af6
|
@ -220,18 +220,8 @@ jobs:
|
|||
make xz-utils cpio wget zip unzip p7zip git mercurial bzr texinfo help2man cmake --no-install-recommends
|
||||
sudo ln -s /usr/include/asm-generic/ /usr/include/asm
|
||||
|
||||
- name: Install MacOSX compiler
|
||||
run: |
|
||||
cd /
|
||||
git clone https://github.com/tpoechtrager/osxcross.git
|
||||
cd osxcross && git checkout 88cb6e8d0d7675cae7c8a2d66c11f58237101df0 && cd ../
|
||||
wget https://s3.dockerproject.org/darwin/v2/MacOSX10.11.sdk.tar.xz
|
||||
mv MacOSX10.11.sdk.tar.xz /osxcross/tarballs/
|
||||
OSX_VERSION_MIN=10.10 UNATTENDED=1 LD_LIBRARY_PATH=/osxcross/target/lib /osxcross/build.sh
|
||||
|
||||
- name: Setting ENV's
|
||||
run: |
|
||||
echo "::add-path::/osxcross/target/bin"
|
||||
echo "::add-path::$(go env GOPATH)/bin"
|
||||
echo "::add-path::/opt/hostedtoolcache/node/10.20.1/x64/bin"
|
||||
echo ::set-env name=VERSION::$(cat version.txt)
|
||||
|
|
1
Makefile
1
Makefile
|
@ -163,7 +163,6 @@ build-win:
|
|||
|
||||
build-darwin:
|
||||
GO111MODULE="on" GOOS=darwin GOARCH=amd64 go build -a -ldflags "-s -w -X main.VERSION=${VERSION}" -o releases/statping-darwin-amd64/statping --tags "darwin" ./cmd
|
||||
GO111MODULE="on" GOOS=darwin GOARCH=386 go build -a -ldflags "-s -w -X main.VERSION=${VERSION}" -o releases/statping-darwin-386/statping --tags "darwin" ./cmd
|
||||
|
||||
build-linux:
|
||||
CGO_ENABLED=1 GO111MODULE="on" GOOS=linux GOARCH=amd64 \
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
</div>
|
||||
|
||||
<div class="row lower_canvas full-col-12 text-white" :class="{'bg-success': service.online, 'bg-danger': !service.online}">
|
||||
<div class="col-md-8 col-6">
|
||||
<div class="col-md-10 col-6">
|
||||
<div class="dropup" :class="{show: dropDownMenu}">
|
||||
<button style="font-size: 10pt;" @click.prevent="openMenu('timeframe')" type="button" class="col-4 float-left btn btn-sm float-right btn-block text-white dropdown-toggle service_scale pr-2">
|
||||
{{timeframepick.text}}
|
||||
|
@ -58,7 +58,7 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div class="col-md-4 col-6 float-right">
|
||||
<div class="col-md-2 col-6 float-right">
|
||||
<button v-if="!expanded" @click="setService" class="btn btn-sm float-right dyn-dark text-white" :class="{'bg-success': service.online, 'bg-danger': !service.online}">
|
||||
View Service
|
||||
</button>
|
||||
|
|
|
@ -235,6 +235,7 @@ func TestMainApiRoutes(t *testing.T) {
|
|||
URL: "/metrics",
|
||||
Method: "GET",
|
||||
BeforeTest: SetTestENV,
|
||||
AfterTest: UnsetTestENV,
|
||||
ExpectedStatus: 200,
|
||||
ExpectedContains: []string{
|
||||
`Statping Totals`,
|
||||
|
@ -242,6 +243,21 @@ func TestMainApiRoutes(t *testing.T) {
|
|||
`Golang Metrics`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Test API Key Authentication",
|
||||
URL: "/metrics?api=" + core.App.ApiSecret,
|
||||
Method: "GET",
|
||||
BeforeTest: UnsetTestENV,
|
||||
ExpectedStatus: 200,
|
||||
},
|
||||
{
|
||||
Name: "Test API Header Authentication",
|
||||
URL: "/metrics",
|
||||
Method: "GET",
|
||||
HttpHeaders: []string{"Authorization=" + core.App.ApiSecret},
|
||||
BeforeTest: UnsetTestENV,
|
||||
ExpectedStatus: 200,
|
||||
},
|
||||
}
|
||||
|
||||
for _, v := range tests {
|
||||
|
|
|
@ -132,29 +132,6 @@ func logsLineHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
//func exportHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// var notifiers []*notifier.Notification
|
||||
// for _, v := range core.CoreApp.Notifications {
|
||||
// notifier := v.(notifier.Notifier)
|
||||
// notifiers = append(notifiers, notifier.Select())
|
||||
// }
|
||||
//
|
||||
// export, _ := core.ExportSettings()
|
||||
//
|
||||
// mime := http.DetectContentType(export)
|
||||
// fileSize := len(string(export))
|
||||
//
|
||||
// w.Header().Set("Content-Type", mime)
|
||||
// w.Header().Set("Content-Disposition", "attachment; filename=export.json")
|
||||
// w.Header().Set("Expires", "0")
|
||||
// w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
// w.Header().Set("Content-Length", strconv.Itoa(fileSize))
|
||||
// w.Header().Set("Content-Control", "private, no-transform, no-store, must-revalidate")
|
||||
//
|
||||
// http.ServeContent(w, r, "export.json", utils.Now(), bytes.NewReader(export))
|
||||
//
|
||||
//}
|
||||
|
||||
type JwtClaim struct {
|
||||
Username string `json:"username"`
|
||||
Admin bool `json:"admin"`
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/statping/statping/types/core"
|
||||
"github.com/statping/statping/types/groups"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -113,6 +114,21 @@ func TestGroupAPIRoutes(t *testing.T) {
|
|||
ExpectedStatus: 200,
|
||||
BeforeTest: SetTestENV,
|
||||
},
|
||||
{
|
||||
Name: "Statping View Private Group with API Key",
|
||||
URL: "/api/groups/2?api=" + core.App.ApiSecret,
|
||||
Method: "GET",
|
||||
ExpectedStatus: 200,
|
||||
BeforeTest: UnsetTestENV,
|
||||
},
|
||||
{
|
||||
Name: "Statping View Private Group with API Header",
|
||||
URL: "/api/groups/2",
|
||||
Method: "GET",
|
||||
HttpHeaders: []string{"Authorization=" + core.App.ApiSecret},
|
||||
ExpectedStatus: 200,
|
||||
BeforeTest: UnsetTestENV,
|
||||
},
|
||||
{
|
||||
Name: "Statping Reorder Groups",
|
||||
URL: "/api/reorder/groups",
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/statping/statping/types"
|
||||
"github.com/statping/statping/types/core"
|
||||
"github.com/statping/statping/types/services"
|
||||
"github.com/statping/statping/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -108,6 +109,21 @@ func TestApiServiceRoutes(t *testing.T) {
|
|||
ExpectedStatus: 200,
|
||||
BeforeTest: SetTestENV,
|
||||
},
|
||||
{
|
||||
Name: "Statping Private Service with API Key",
|
||||
URL: "/api/services/6?api=" + core.App.ApiSecret,
|
||||
Method: "GET",
|
||||
ExpectedStatus: 200,
|
||||
BeforeTest: UnsetTestENV,
|
||||
},
|
||||
{
|
||||
Name: "Statping Private Service with API Header",
|
||||
URL: "/api/services/6?api=" + core.App.ApiSecret,
|
||||
Method: "GET",
|
||||
HttpHeaders: []string{"Authorization=" + core.App.ApiSecret},
|
||||
ExpectedStatus: 200,
|
||||
BeforeTest: UnsetTestENV,
|
||||
},
|
||||
{
|
||||
Name: "Statping Service 1 with Private responses",
|
||||
URL: "/api/services/1",
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
)
|
||||
|
||||
func TestCommandNotifier(t *testing.T) {
|
||||
t.SkipNow()
|
||||
db, err := database.OpenTester()
|
||||
require.Nil(t, err)
|
||||
db.AutoMigrate(¬ifications.Notification{})
|
||||
|
|
|
@ -16,7 +16,6 @@ var (
|
|||
)
|
||||
|
||||
func TestPushoverNotifier(t *testing.T) {
|
||||
t.SkipNow()
|
||||
db, err := database.OpenTester()
|
||||
require.Nil(t, err)
|
||||
db.AutoMigrate(¬ifications.Notification{})
|
||||
|
|
|
@ -25,7 +25,6 @@ func init() {
|
|||
}
|
||||
|
||||
func TestTelegramNotifier(t *testing.T) {
|
||||
t.SkipNow()
|
||||
db, err := database.OpenTester()
|
||||
require.Nil(t, err)
|
||||
db.AutoMigrate(¬ifications.Notification{})
|
||||
|
|
|
@ -62,15 +62,17 @@ var Twilio = &twilio{¬ifications.Notification{
|
|||
|
||||
// Send will send a HTTP Post to the Twilio SMS API. It accepts type: string
|
||||
func (t *twilio) sendMessage(message string) (string, error) {
|
||||
twilioUrl := fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%v/Messages.json", t.GetValue("api_key"))
|
||||
twilioUrl := fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%v/Messages.json", t.ApiKey)
|
||||
|
||||
v := url.Values{}
|
||||
v.Set("To", "+"+t.Var1)
|
||||
v.Set("From", "+"+t.Var2)
|
||||
v.Set("Body", message)
|
||||
rb := *strings.NewReader(v.Encode())
|
||||
rb := strings.NewReader(v.Encode())
|
||||
|
||||
contents, _, err := utils.HttpRequest(twilioUrl, "POST", "application/x-www-form-urlencoded", nil, &rb, time.Duration(10*time.Second), true)
|
||||
authHeader := utils.Base64(fmt.Sprintf("%s:%s", t.ApiKey, t.ApiSecret))
|
||||
|
||||
contents, _, err := utils.HttpRequest(twilioUrl, "POST", "application/x-www-form-urlencoded", []string{"Authorization=Basic " + authHeader}, rb, 10*time.Second, true)
|
||||
success, _ := twilioSuccess(contents)
|
||||
if !success {
|
||||
errorOut := twilioError(contents)
|
||||
|
|
|
@ -21,29 +21,25 @@ var (
|
|||
func init() {
|
||||
TWILIO_SID = os.Getenv("TWILIO_SID")
|
||||
TWILIO_SECRET = os.Getenv("TWILIO_SECRET")
|
||||
TWILIO_FROM = os.Getenv("TWILIO_FROM")
|
||||
TWILIO_TO = os.Getenv("TWILIO_TO")
|
||||
}
|
||||
|
||||
func TestTwilioNotifier(t *testing.T) {
|
||||
t.SkipNow()
|
||||
|
||||
db, err := database.OpenTester()
|
||||
require.Nil(t, err)
|
||||
db.AutoMigrate(¬ifications.Notification{})
|
||||
notifications.SetDB(db)
|
||||
|
||||
if TWILIO_SID == "" || TWILIO_SECRET == "" || TWILIO_FROM == "" {
|
||||
t.Log("twilio notifier testing skipped, missing TWILIO_SID environment variable")
|
||||
if TWILIO_SID == "" || TWILIO_SECRET == "" {
|
||||
t.Log("twilio notifier testing skipped, missing TWILIO_SID and TWILIO_SECRET environment variable")
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
t.Run("Load Twilio", func(t *testing.T) {
|
||||
Twilio.ApiKey = TWILIO_SID
|
||||
Twilio.ApiSecret = TWILIO_SECRET
|
||||
Twilio.Var1 = TWILIO_TO
|
||||
Twilio.Var2 = TWILIO_FROM
|
||||
Twilio.Delay = time.Duration(100 * time.Millisecond)
|
||||
Twilio.Var1 = "15005550006"
|
||||
Twilio.Var2 = "15005550006"
|
||||
Twilio.Delay = 100 * time.Millisecond
|
||||
Twilio.Enabled = null.NewNullBool(true)
|
||||
|
||||
Add(Twilio)
|
||||
|
|
|
@ -2,6 +2,7 @@ package utils
|
|||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"math/rand"
|
||||
|
@ -22,6 +23,10 @@ func NewSHA256Hash() string {
|
|||
return fmt.Sprintf("%x", sha256.Sum256(d))
|
||||
}
|
||||
|
||||
func Base64(s string) string {
|
||||
return base64.StdEncoding.EncodeToString([]byte(s))
|
||||
}
|
||||
|
||||
var characterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
|
||||
// RandomString generates a random string of n length
|
||||
|
|
Loading…
Reference in New Issue