test(GODT-2746): Integration tests for reporting a problem

- Add function for checking header in form-data request

Bug reports are sent with multipart/form-data, and the function parses this,
then compares the needed field with the wanted
Also, added the step definition.

- Add functions for reporting a bug with changes

Be able to report a bug by changing the value of a single field, or multiple fields through a JSON format

- Add integration tests for reporting a problem
This commit is contained in:
Gjorgji Slamkov
2023-08-30 13:42:48 +02:00
parent 44e103edd5
commit c57b52ef23
4 changed files with 138 additions and 0 deletions

View File

@ -19,6 +19,7 @@ package tests
import (
"context"
"encoding/json"
"errors"
"fmt"
"net"
@ -29,6 +30,7 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/ProtonMail/proton-bridge/v3/internal/events"
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
"github.com/cucumber/godog"
"github.com/golang/mock/gomock"
)
@ -155,6 +157,54 @@ func (s *scenario) theUserReportsABug() error {
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", "description", "username", "email", "client", false)
}
func (s *scenario) theUserReportsABugWithSingleHeaderChange(key, value string) error {
switch keyValue := key; keyValue {
case "osType":
return s.t.bridge.ReportBug(context.Background(), value, "osVersion", "title", "description", "username", "email", "client", false)
case "osVersion":
return s.t.bridge.ReportBug(context.Background(), "osType", value, "title", "description", "username", "email", "client", false)
case "Title":
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", value, "description", "username", "email", "client", false)
case "Description":
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", value, "username", "email", "client", false)
case "Username":
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", "description", value, "email", "client", false)
case "Email":
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", "description", "username", value, "client", false)
case "Client":
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", "description", "username", "email", value, false)
case "Attachment":
att, _ := strconv.ParseBool(value)
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", "description", "username", "email", "client", att)
default:
return fmt.Errorf("Wrong header (\"%s\") is being checked", key)
}
}
func (s *scenario) theUserReportsABugWithDetails(value *godog.DocString) error {
type BugReportTest struct {
OSType string `json:"OS"`
OSVersion string `json:"OSVersion"`
Title string `json:"Title"`
Description string `json:"Description"`
Username string `json:"Username"`
Email string `json:"Email"`
Client string `json:"Client"`
Attachment bool `json:"Attachment"`
}
bugReport := BugReportTest{OSType: "osType", OSVersion: "osVersion", Title: "title", Description: "description", Username: "username", Email: "email", Client: "client", Attachment: false}
jsonString := value
err := json.Unmarshal([]byte(jsonString.Content), &bugReport)
if err != nil {
fmt.Println(err)
}
return s.t.bridge.ReportBug(context.Background(), bugReport.OSType, bugReport.OSVersion, bugReport.Title, bugReport.Description, bugReport.Username, bugReport.Email, bugReport.Client, bugReport.Attachment)
}
func (s *scenario) bridgeSendsAConnectionUpEvent() error {
if event := s.t.events.await(events.ConnStatusUp{}, 30*time.Second); event == nil {
return errors.New("expected connection up event, got none")

View File

@ -18,8 +18,11 @@
package tests
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/cucumber/godog"
@ -87,6 +90,47 @@ func (s *scenario) theHeaderInTheRequestToHasSetTo(method, path, key, value stri
return nil
}
func (s *scenario) theHeaderInTheMultipartRequestToHasSetTo(method, path, key, value string) error {
// We have to exclude HTTP-Overrides to avoid race condition with the creating and sending of the draft message.
call, err := s.t.getLastCallExcludingHTTPOverride(method, path)
if err != nil {
return err
}
buf := new(bytes.Buffer)
if _, err := buf.WriteString(fmt.Sprintf("%s %s HTTP/1.1\r\n", call.Method, call.URL.Path)); err != nil {
return fmt.Errorf("failed to write request line: %w", err)
}
if err := call.RequestHeader.Write(buf); err != nil {
return fmt.Errorf("failed to write header: %w", err)
}
if _, err := buf.WriteString("\r\n"); err != nil {
return fmt.Errorf("failed to write header: %w", err)
}
if _, err := buf.Write(call.RequestBody); err != nil {
return fmt.Errorf("failed to write body: %w", err)
}
req, err := http.ReadRequest(bufio.NewReader(buf))
if err != nil {
return fmt.Errorf("failed to read request: %w", err)
}
if err := req.ParseMultipartForm(1 << 10); err != nil {
return fmt.Errorf("failed to parse multipart form: %w", err)
}
if haveKey := req.FormValue(key); haveKey != value {
return fmt.Errorf("have header %q, want %q", haveKey, value)
}
return nil
}
func (s *scenario) theBodyInTheRequestToIs(method, path string, value *godog.DocString) error {
// We have to exclude HTTP-Overrides to avoid race condition with the creating and sending of the draft message.
call, err := s.t.getLastCallExcludingHTTPOverride(method, path)

View File

@ -0,0 +1,41 @@
Feature: The user reports a problem
Background:
Given there exists an account with username "[user:user]" and password "password"
Then it succeeds
When bridge starts
And the user logs in with username "[user:user]" and password "password"
And user "[user:user]" finishes syncing
Then it succeeds
Scenario: User sends a problem report without logs attached
When the user reports a bug
Then the header in the "POST" multipart request to "/core/v4/reports/bug" has "Title" set to "[Bridge] Bug - title"
And the header in the "POST" multipart request to "/core/v4/reports/bug" has "Description" set to "description"
And the header in the "POST" multipart request to "/core/v4/reports/bug" has "Username" set to "[user:user]"
Scenario: User sends a problem report with changed Title
When the user reports a bug with field "Title" set to "Testing title"
Then the header in the "POST" multipart request to "/core/v4/reports/bug" has "Title" set to "[Bridge] Bug - Testing title"
Scenario: User sends a problem report with changed Description
When the user reports a bug with field "Description" set to "There's an issue with my testing, please fix!"
Then the header in the "POST" multipart request to "/core/v4/reports/bug" has "Description" set to "There's an issue with my testing, please fix!"
Scenario: User sends a problem report with multiple details changed
When the user reports a bug with details:
"""
{
"Title": "Testing Title",
"Description": "Testing Description",
"Username": "[user:user]",
"Email": "[user:user]@[domain]",
"Client": "Apple Mail"
}
"""
Then the header in the "POST" multipart request to "/core/v4/reports/bug" has "Title" set to "[Bridge] Bug - Testing Title"
And the header in the "POST" multipart request to "/core/v4/reports/bug" has "OS" set to "osType"
And the header in the "POST" multipart request to "/core/v4/reports/bug" has "OSVersion" set to "osVersion"
And the header in the "POST" multipart request to "/core/v4/reports/bug" has "Description" set to "Testing Description"
And the header in the "POST" multipart request to "/core/v4/reports/bug" has "Username" set to "[user:user]"
And the header in the "POST" multipart request to "/core/v4/reports/bug" has "Email" set to "[user:user]@[domain]"
And the header in the "POST" multipart request to "/core/v4/reports/bug" has "Client" set to "Apple Mail"

View File

@ -28,6 +28,7 @@ func (s *scenario) steps(ctx *godog.ScenarioContext) {
ctx.Step(`^the internet is turned on$`, s.internetIsTurnedOn)
ctx.Step(`^the user agent is "([^"]*)"$`, s.theUserAgentIs)
ctx.Step(`^the header in the "([^"]*)" request to "([^"]*)" has "([^"]*)" set to "([^"]*)"$`, s.theHeaderInTheRequestToHasSetTo)
ctx.Step(`^the header in the "([^"]*)" multipart request to "([^"]*)" has "([^"]*)" set to "([^"]*)"$`, s.theHeaderInTheMultipartRequestToHasSetTo)
ctx.Step(`^the body in the "([^"]*)" request to "([^"]*)" is:$`, s.theBodyInTheRequestToIs)
ctx.Step(`^the body in the "([^"]*)" response to "([^"]*)" is:$`, s.theBodyInTheResponseToIs)
ctx.Step(`^the API requires bridge version at least "([^"]*)"$`, s.theAPIRequiresBridgeVersion)
@ -71,6 +72,8 @@ func (s *scenario) steps(ctx *godog.ScenarioContext) {
ctx.Step(`^the user deletes the gluon files$`, s.theUserDeletesTheGluonFiles)
ctx.Step(`^the user deletes the gluon cache$`, s.theUserDeletesTheGluonCache)
ctx.Step(`^the user reports a bug$`, s.theUserReportsABug)
ctx.Step(`^the user reports a bug with field "([^"]*)" set to "([^"]*)"$`, s.theUserReportsABugWithSingleHeaderChange)
ctx.Step(`^the user reports a bug with details:$`, s.theUserReportsABugWithDetails)
ctx.Step(`^the user hides All Mail$`, s.theUserHidesAllMail)
ctx.Step(`^the user shows All Mail$`, s.theUserShowsAllMail)
ctx.Step(`^the user disables telemetry in bridge settings$`, s.theUserDisablesTelemetryInBridgeSettings)