feat(BRIDGE-37): Remote notification support

This commit is contained in:
Atanas Janeshliev
2024-08-29 13:31:37 +02:00
parent ed1b65731a
commit f04350c046
43 changed files with 2350 additions and 1168 deletions

View File

@ -0,0 +1,17 @@
Feature: Bridge send remote notification observability metrics
Background:
Given there exists an account with username "[user:user1]" and password "password"
And there exists an account with username "[user:user2]" and password "password"
Then it succeeds
When bridge starts
Then it succeeds
Scenario: Send notification 'received' and 'processed' observability metric
When the user logs in with username "[user:user1]" and password "password"
And the user with username "[user:user1]" sends the following remote notification observability metric "received"
Then it succeeds
And the user with username "[user:user1]" sends the following remote notification observability metric "processed"
Then it succeeds

View File

@ -216,4 +216,8 @@ func (s *scenario) steps(ctx *godog.ScenarioContext) {
ctx.Step(`^the contact "([^"]*)" of user "([^"]*)" has encryption "([^"]*)"$`, s.contactOfUserHasEncryption)
ctx.Step(`^the contact "([^"]*)" of user "([^"]*)" has public key:$`, s.contactOfUserHasPubKey)
ctx.Step(`^the contact "([^"]*)" of user "([^"]*)" has public key from file "([^"]*)"$`, s.contactOfUserHasPubKeyFromFile)
// ==== OBSERVABILITY METRICS ====
ctx.Step(`^the user with username "([^"]*)" sends the following remote notification observability metric "([^"]*)"`,
s.userRemoteNotificationMetricTest)
}

View File

@ -23,11 +23,13 @@ import (
"fmt"
"net/mail"
"strings"
"time"
"github.com/ProtonMail/gluon/rfc822"
"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/gopenpgp/v2/crypto"
"github.com/ProtonMail/proton-bridge/v3/internal/bridge"
"github.com/ProtonMail/proton-bridge/v3/internal/services/notifications"
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
"github.com/ProtonMail/proton-bridge/v3/pkg/algo"
"github.com/bradenaw/juniper/iterator"
@ -690,3 +692,24 @@ func matchSettings(have proton.MailSettings, want MailSettings) error {
return nil
}
func (s *scenario) userRemoteNotificationMetricTest(username string, metricName string) error {
var metricToTest proton.ObservabilityMetric
switch strings.ToLower(metricName) {
case "processed":
metricToTest = notifications.GenerateProcessedMetric(1)
case "received":
metricToTest = notifications.GenerateReceivedMetric(1)
default:
return fmt.Errorf("invalid metric name specified")
}
// Account for endpoint throttle
time.Sleep(time.Second * 5)
return s.t.withClientPass(context.Background(), username, s.t.getUserByName(username).userPass, func(ctx context.Context, c *proton.Client) error {
batch := proton.ObservabilityBatch{Metrics: []proton.ObservabilityMetric{metricToTest}}
err := c.SendObservabilityBatch(ctx, batch)
return err
})
}