forked from Silverfish/proton-bridge
chore: (BRIDGE-253) removing unused telemetry (activation and troubleshooting)
This commit is contained in:
@ -1,187 +0,0 @@
|
||||
// Copyright (c) 2024 Proton AG
|
||||
//
|
||||
// This file is part of Proton Mail Bridge.
|
||||
//
|
||||
// Proton Mail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Proton Mail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package tests
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/go-proton-api/server"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/configstatus"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (s *scenario) configStatusFileExistForUser(username string) error {
|
||||
configStatusFile, err := getConfigStatusFile(s.t, username)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := os.Stat(configStatusFile); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *scenario) configStatusIsPendingForUser(username string) error {
|
||||
data, err := loadConfigStatusFile(s.t, username)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if data.DataV1.PendingSince.IsZero() {
|
||||
return fmt.Errorf("expected ConfigStatus pending but got success instead")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *scenario) configStatusIsPendingWithFailureForUser(username string) error {
|
||||
data, err := loadConfigStatusFile(s.t, username)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if data.DataV1.PendingSince.IsZero() {
|
||||
return fmt.Errorf("expected ConfigStatus pending but got success instead")
|
||||
}
|
||||
if data.DataV1.FailureDetails == "" {
|
||||
return fmt.Errorf("expected ConfigStatus pending with failure but got no failure instead")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *scenario) configStatusSucceedForUser(username string) error {
|
||||
data, err := loadConfigStatusFile(s.t, username)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !data.DataV1.PendingSince.IsZero() {
|
||||
return fmt.Errorf("expected ConfigStatus success but got pending since %s", data.DataV1.PendingSince)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *scenario) configStatusEventIsEventuallySendXTime(event string, number int) error {
|
||||
return eventually(func() error {
|
||||
err := s.checkEventSentForUser(event, number)
|
||||
logrus.WithError(err).Trace("Matching eventually")
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (s *scenario) configStatusEventIsNotSendMoreThanXTime(event string, number int) error {
|
||||
if err := eventually(func() error {
|
||||
err := s.checkEventSentForUser(event, number+1)
|
||||
logrus.WithError(err).Trace("Matching eventually")
|
||||
return err
|
||||
}); err == nil {
|
||||
return fmt.Errorf("expected %s to be sent %d but catch %d", event, number, number+1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *scenario) forceConfigStatusProgressToBeSentForUser(username string) error {
|
||||
configStatusFile, err := getConfigStatusFile(s.t, username)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data, err := loadConfigStatusFile(s.t, username)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data.DataV1.PendingSince = time.Now().AddDate(0, 0, -2)
|
||||
data.DataV1.LastProgress = time.Now().AddDate(0, 0, -1)
|
||||
|
||||
f, err := os.Create(configStatusFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
return json.NewEncoder(f).Encode(data)
|
||||
}
|
||||
|
||||
func (s *scenario) checkEventSentForUser(event string, number int) error {
|
||||
calls, err := getLastTelemetryEventSent(s.t, event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(calls) != number {
|
||||
return fmt.Errorf("expected %s to be sent %d but catch %d", event, number, len(calls))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getConfigStatusFile(t *testCtx, username string) (string, error) {
|
||||
userID := t.getUserByName(username).getUserID()
|
||||
statsDir, err := t.locator.ProvideStatsPath()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get Statistics directory: %w", err)
|
||||
}
|
||||
return filepath.Join(statsDir, userID+".json"), nil
|
||||
}
|
||||
|
||||
func loadConfigStatusFile(t *testCtx, username string) (configstatus.ConfigurationStatusData, error) {
|
||||
data := configstatus.ConfigurationStatusData{}
|
||||
|
||||
configStatusFile, err := getConfigStatusFile(t, username)
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(configStatusFile); err != nil {
|
||||
return data, err
|
||||
}
|
||||
|
||||
f, err := os.Open(configStatusFile)
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
err = json.NewDecoder(f).Decode(&data)
|
||||
return data, err
|
||||
}
|
||||
|
||||
func getLastTelemetryEventSent(t *testCtx, event string) ([]server.Call, error) {
|
||||
var matches []server.Call
|
||||
|
||||
calls, err := t.getAllCalls("POST", "/data/v1/stats")
|
||||
if err != nil {
|
||||
return matches, err
|
||||
}
|
||||
|
||||
for _, call := range calls {
|
||||
var req proton.SendStatsReq
|
||||
if err := json.Unmarshal(call.RequestBody, &req); err != nil {
|
||||
continue
|
||||
}
|
||||
if req.Event == event {
|
||||
matches = append(matches, call)
|
||||
}
|
||||
}
|
||||
return matches, err
|
||||
}
|
||||
@ -1,79 +0,0 @@
|
||||
Feature: Configuration Status Telemetry
|
||||
Background:
|
||||
Given there exists an account with username "[user:user]" and password "password"
|
||||
Then it succeeds
|
||||
When bridge starts
|
||||
Then it succeeds
|
||||
|
||||
|
||||
Scenario: Init config status on user addition
|
||||
Then bridge telemetry feature is enabled
|
||||
When the user logs in with username "[user:user]" and password "password"
|
||||
Then config status file exist for user "[user:user]"
|
||||
And config status is pending for user "[user:user]"
|
||||
|
||||
|
||||
Scenario: Config Status Success on IMAP
|
||||
Then bridge telemetry feature is enabled
|
||||
When the user logs in with username "[user:user]" and password "password"
|
||||
Then config status file exist for user "[user:user]"
|
||||
And config status is pending for user "[user:user]"
|
||||
When user "[user:user]" connects and authenticates IMAP client "1"
|
||||
Then config status succeed for user "[user:user]"
|
||||
And config status event "bridge_config_success" is eventually send 1 time
|
||||
|
||||
|
||||
Scenario: Config Status Success on SMTP
|
||||
Then bridge telemetry feature is enabled
|
||||
When the user logs in with username "[user:user]" and password "password"
|
||||
Then config status file exist for user "[user:user]"
|
||||
And config status is pending for user "[user:user]"
|
||||
When user "[user:user]" connects and authenticates SMTP client "1"
|
||||
Then config status succeed for user "[user:user]"
|
||||
And config status event "bridge_config_success" is eventually send 1 time
|
||||
|
||||
|
||||
Scenario: Config Status Success send only once
|
||||
Then bridge telemetry feature is enabled
|
||||
When the user logs in with username "[user:user]" and password "password"
|
||||
Then config status file exist for user "[user:user]"
|
||||
And config status is pending for user "[user:user]"
|
||||
When user "[user:user]" connects and authenticates IMAP client "1"
|
||||
Then config status succeed for user "[user:user]"
|
||||
And config status event "bridge_config_success" is eventually send 1 time
|
||||
When user "[user:user]" connects and authenticates IMAP client "2"
|
||||
Then config status event "bridge_config_success" is not send more than 1 time
|
||||
|
||||
|
||||
Scenario: Config Status Abort
|
||||
Then bridge telemetry feature is enabled
|
||||
When the user logs in with username "[user:user]" and password "password"
|
||||
And user "[user:user]" finishes syncing
|
||||
Then config status file exist for user "[user:user]"
|
||||
And config status is pending for user "[user:user]"
|
||||
When user "[user:user]" is deleted
|
||||
Then config status event "bridge_config_abort" is eventually send 1 time
|
||||
|
||||
|
||||
Scenario: Config Status Recovery from deauth
|
||||
Then bridge telemetry feature is enabled
|
||||
When the user logs in with username "[user:user]" and password "password"
|
||||
And user "[user:user]" connects and authenticates IMAP client "1"
|
||||
Then config status succeed for user "[user:user]"
|
||||
When the auth of user "[user:user]" is revoked
|
||||
Then bridge sends a deauth event for user "[user:user]"
|
||||
Then config status is pending with failure for user "[user:user]"
|
||||
When the user logs in with username "[user:user]" and password "password"
|
||||
And user "[user:user]" connects and authenticates IMAP client "1"
|
||||
Then config status succeed for user "[user:user]"
|
||||
And config status event "bridge_config_recovery" is eventually send 1 time
|
||||
|
||||
|
||||
Scenario: Config Status Progress
|
||||
Then bridge telemetry feature is enabled
|
||||
When the user logs in with username "[user:user]" and password "password"
|
||||
And config status is pending for user "[user:user]"
|
||||
And bridge stops
|
||||
And force config status progress to be sent for user"[user:user]"
|
||||
And bridge starts
|
||||
Then config status event "bridge_config_progress" is eventually send 1 time
|
||||
@ -203,13 +203,6 @@ func (s *scenario) steps(ctx *godog.ScenarioContext) {
|
||||
ctx.Step(`^bridge needs to send heartbeat`, s.bridgeNeedsToSendHeartbeat)
|
||||
ctx.Step(`^bridge do not need to send heartbeat`, s.bridgeDoNotNeedToSendHeartbeat)
|
||||
ctx.Step(`^heartbeat is not whitelisted`, s.heartbeatIsNotwhitelisted)
|
||||
ctx.Step(`^config status file exist for user "([^"]*)"$`, s.configStatusFileExistForUser)
|
||||
ctx.Step(`^config status is pending for user "([^"]*)"$`, s.configStatusIsPendingForUser)
|
||||
ctx.Step(`^config status is pending with failure for user "([^"]*)"$`, s.configStatusIsPendingWithFailureForUser)
|
||||
ctx.Step(`^config status succeed for user "([^"]*)"$`, s.configStatusSucceedForUser)
|
||||
ctx.Step(`^config status event "([^"]*)" is eventually send (\d+) time`, s.configStatusEventIsEventuallySendXTime)
|
||||
ctx.Step(`^config status event "([^"]*)" is not send more than (\d+) time`, s.configStatusEventIsNotSendMoreThanXTime)
|
||||
ctx.Step(`^force config status progress to be sent for user"([^"]*)"$`, s.forceConfigStatusProgressToBeSentForUser)
|
||||
|
||||
// ==== CONTACT ====
|
||||
ctx.Step(`^user "([^"]*)" has contact "([^"]*)" with name "([^"]*)"$`, s.userHasContactWithName)
|
||||
|
||||
Reference in New Issue
Block a user