fix: check certificate file exist. (#209)
* fix: check certificate file exist. * fix: certificate key path error
This commit is contained in:
parent
908c2219b3
commit
04caa04899
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue