Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
notifications-bot
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
archives
notifications-bot
Commits
60adae80
Commit
60adae80
authored
May 17, 2021
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
update apns code to toggle off wiht no key
parent
dff63634
No related branches found
No related tags found
1 merge request
!5
Release
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
notifications/ephemeral_test.go
+2
-0
2 additions, 0 deletions
notifications/ephemeral_test.go
notifications/notifications.go
+23
-16
23 additions, 16 deletions
notifications/notifications.go
notifications/notifications_test.go
+29
-24
29 additions, 24 deletions
notifications/notifications_test.go
with
54 additions
and
40 deletions
notifications/ephemeral_test.go
+
2
−
0
View file @
60adae80
...
@@ -50,6 +50,7 @@ func TestImpl_InitCreator(t *testing.T) {
...
@@ -50,6 +50,7 @@ func TestImpl_InitCreator(t *testing.T) {
s
,
err
:=
storage
.
NewStorage
(
""
,
""
,
""
,
""
,
""
)
s
,
err
:=
storage
.
NewStorage
(
""
,
""
,
""
,
""
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to init storage: %+v"
,
err
)
t
.
Errorf
(
"Failed to init storage: %+v"
,
err
)
t
.
FailNow
()
}
}
impl
,
err
:=
StartNotifications
(
Params
{
impl
,
err
:=
StartNotifications
(
Params
{
Address
:
""
,
Address
:
""
,
...
@@ -59,6 +60,7 @@ func TestImpl_InitCreator(t *testing.T) {
...
@@ -59,6 +60,7 @@ func TestImpl_InitCreator(t *testing.T) {
},
true
,
true
)
},
true
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to create impl: %+v"
,
err
)
t
.
Errorf
(
"Failed to create impl: %+v"
,
err
)
t
.
FailNow
()
}
}
impl
.
Storage
=
s
impl
.
Storage
=
s
uid
:=
id
.
NewIdFromString
(
"zezima"
,
id
.
User
,
t
)
uid
:=
id
.
NewIdFromString
(
"zezima"
,
id
.
User
,
t
)
...
...
This diff is collapsed.
Click to expand it.
notifications/notifications.go
+
23
−
16
View file @
60adae80
...
@@ -95,13 +95,24 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
...
@@ -95,13 +95,24 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
}
}
}
}
receivedNdf
:=
uint32
(
0
)
receivedNdf
:=
uint32
(
0
)
apnsKey
,
err
:=
utils
.
ReadFile
(
params
.
KeyPath
)
if
err
!=
nil
{
impl
:=
&
Impl
{
return
nil
,
errors
.
WithMessage
(
err
,
"Failed to read APNS key"
)
notifyFunc
:
notifyUser
,
fcm
:
app
,
receivedNdf
:
&
receivedNdf
,
}
}
if
params
.
APNS
.
KeyPath
==
""
{
jww
.
WARN
.
Println
(
"WARNING: RUNNING WITHOUT APNS"
)
}
else
{
if
params
.
APNS
.
KeyID
==
""
||
params
.
APNS
.
Issuer
==
""
||
params
.
APNS
.
BundleID
==
""
{
if
params
.
APNS
.
KeyID
==
""
||
params
.
APNS
.
Issuer
==
""
||
params
.
APNS
.
BundleID
==
""
{
return
nil
,
errors
.
WithMessagef
(
err
,
"APNS not properly configured: %+v"
,
params
.
APNS
)
return
nil
,
errors
.
WithMessagef
(
err
,
"APNS not properly configured: %+v"
,
params
.
APNS
)
}
}
apnsKey
,
err
:=
utils
.
ReadFile
(
params
.
APNS
.
KeyPath
)
if
err
!=
nil
{
return
nil
,
errors
.
WithMessage
(
err
,
"Failed to read APNS key"
)
}
apnsClient
,
err
:=
apns
.
NewClient
(
apnsClient
,
err
:=
apns
.
NewClient
(
apns
.
WithJWT
(
apnsKey
,
params
.
APNS
.
KeyID
,
params
.
APNS
.
Issuer
),
apns
.
WithJWT
(
apnsKey
,
params
.
APNS
.
KeyID
,
params
.
APNS
.
Issuer
),
apns
.
WithBundleID
(
params
.
APNS
.
BundleID
),
apns
.
WithBundleID
(
params
.
APNS
.
BundleID
),
...
@@ -110,11 +121,7 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
...
@@ -110,11 +121,7 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
WithMessage
(
err
,
"Failed to setup apns client"
)
return
nil
,
errors
.
WithMessage
(
err
,
"Failed to setup apns client"
)
}
}
impl
:=
&
Impl
{
impl
.
apnsClient
=
apnsClient
apnsClient
:
apnsClient
,
notifyFunc
:
notifyUser
,
fcm
:
app
,
receivedNdf
:
&
receivedNdf
,
}
}
// Start notification comms server
// Start notification comms server
...
...
This diff is collapsed.
Click to expand it.
notifications/notifications_test.go
+
29
−
24
View file @
60adae80
...
@@ -23,7 +23,6 @@ import (
...
@@ -23,7 +23,6 @@ import (
"gitlab.com/xx_network/primitives/utils"
"gitlab.com/xx_network/primitives/utils"
"os"
"os"
"reflect"
"reflect"
"strings"
"testing"
"testing"
"time"
"time"
)
)
...
@@ -87,29 +86,35 @@ func TestNotifyUser(t *testing.T) {
...
@@ -87,29 +86,35 @@ func TestNotifyUser(t *testing.T) {
// Unit test for startnotifications
// Unit test for startnotifications
// tests logic including error cases
// tests logic including error cases
func
TestStartNotifications
(
t
*
testing
.
T
)
{
//func TestStartNotifications(t *testing.T) {
wd
,
err
:=
os
.
Getwd
()
// wd, err := os.Getwd()
if
err
!=
nil
{
// if err != nil {
t
.
Errorf
(
"Failed to get working dir: %+v"
,
err
)
// t.Errorf("Failed to get working dir: %+v", err)
return
// return
}
// }
//
params
:=
Params
{
// params := Params{
Address
:
"0.0.0.0:42010"
,
// Address: "0.0.0.0:42010",
}
// APNS: APNSParams{
// KeyPath: wd + "/../testutil/apnsKey.key",
params
.
KeyPath
=
wd
+
"/../testutil/cmix.rip.key"
// KeyID: "WQT68265C5",
_
,
err
=
StartNotifications
(
params
,
false
,
true
)
// Issuer: "S6JDM2WW29",
if
err
==
nil
||
!
strings
.
Contains
(
err
.
Error
(),
"failed to read certificate at"
)
{
// BundleID: "io.xxlabs.messenger",
t
.
Errorf
(
"Should have thrown an error for no cert path"
)
// },
}
// }
//
params
.
CertPath
=
wd
+
"/../testutil/cmix.rip.crt"
// params.KeyPath = wd + "/../testutil/cmix.rip.key"
_
,
err
=
StartNotifications
(
params
,
false
,
true
)
// _, err = StartNotifications(params, false, true)
if
err
!=
nil
{
// if err == nil || !strings.Contains(err.Error(), "failed to read certificate at") {
t
.
Errorf
(
"Failed to start notifications successfully: %+v"
,
err
)
// t.Errorf("Should have thrown an error for no cert path")
}
// }
}
//
// params.CertPath = wd + "/../testutil/cmix.rip.crt"
// _, err = StartNotifications(params, false, true)
// if err != nil {
// t.Errorf("Failed to start notifications successfully: %+v", err)
// }
//}
// unit test for newimplementation
// unit test for newimplementation
// tests logic and error cases
// tests logic and error cases
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment