Skip to content

Commit

Permalink
fix: check certificate file exist. (#209)
Browse files Browse the repository at this point in the history
* fix: check certificate file exist.

* fix: certificate key path error
  • Loading branch information
appleboy authored Apr 6, 2017
1 parent 908c221 commit 04caa04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions gorush/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"path/filepath"
"time"

Expand Down Expand Up @@ -142,6 +143,11 @@ func CheckPushConf() error {
if PushConf.Ios.KeyPath == "" {
return errors.New("Missing iOS certificate path")
}

// check certificate file exist
if _, err := os.Stat(PushConf.Ios.KeyPath); os.IsNotExist(err) {
return errors.New("certificate file does not exist")
}
}

if PushConf.Android.Enabled {
Expand Down
10 changes: 8 additions & 2 deletions gorush/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ func TestMissingIOSCertificate(t *testing.T) {

PushConf.Ios.Enabled = true
PushConf.Ios.KeyPath = ""

err := CheckPushConf()

assert.Error(t, err)
assert.Equal(t, "Missing iOS certificate path", err.Error())

PushConf.Ios.KeyPath = "test.pem"
err = CheckPushConf()

assert.Error(t, err)
assert.Equal(t, "certificate file does not exist", err.Error())

}

func TestMissingAndroidAPIKey(t *testing.T) {
Expand All @@ -54,7 +60,7 @@ func TestCorrectConf(t *testing.T) {
PushConf.Android.APIKey = "xxxxx"

PushConf.Ios.Enabled = true
PushConf.Ios.KeyPath = "xxxxx"
PushConf.Ios.KeyPath = "../certificate/certificate-valid.pem"

err := CheckPushConf()

Expand Down

0 comments on commit 04caa04

Please sign in to comment.