Skip to content

Commit 1e16cc8

Browse files
authored
Merge pull request #1510 from getlantern/thomas/issues
add tracks to issue submission
2 parents c7c87c7 + e3ca95a commit 1e16cc8

File tree

6 files changed

+187
-98
lines changed

6 files changed

+187
-98
lines changed

issue/issue.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package issue
22

33
import (
44
"bytes"
5+
"context"
56
"net/http"
67
"net/http/httputil"
78
"strconv"
89
"time"
910

1011
"github.com/getlantern/flashlight/v7/common"
12+
userconfig "github.com/getlantern/flashlight/v7/config/user"
1113
"github.com/getlantern/flashlight/v7/geolookup"
1214
"github.com/getlantern/flashlight/v7/logging"
1315
"github.com/getlantern/flashlight/v7/util"
@@ -129,6 +131,22 @@ func sendReport(
129131
}
130132
}
131133

134+
// get which tracks the user was given in their config, if any are present
135+
ctx, cancel := context.WithTimeout(context.Background(), -time.Second)
136+
defer cancel()
137+
138+
userProxyConfig, err := userconfig.GetConfig(ctx)
139+
if err != nil {
140+
log.Errorf("unable to get user config: %v", err)
141+
}
142+
if userProxyConfig != nil {
143+
tracks := []string{}
144+
for _, proxy := range userProxyConfig.GetProxy().GetProxies() {
145+
tracks = append(tracks, proxy.GetTrack())
146+
}
147+
r.Tracks = tracks
148+
}
149+
132150
// send message to lantern-cloud
133151
out, err := proto.Marshal(r)
134152
if err != nil {

issue/issue_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package issue
22

33
import (
44
"os"
5+
"path/filepath"
56
"testing"
67
"time"
78

89
"github.com/getlantern/flashlight/v7/common"
10+
userconfig "github.com/getlantern/flashlight/v7/config/user"
911
"github.com/getlantern/flashlight/v7/geolookup"
1012
)
1113

@@ -22,6 +24,10 @@ func TestSendReport(t *testing.T) {
2224
//manually set library version since its only populated when run from a binary
2325
common.LibraryVersion = "7.0.0"
2426
UserConfigData := common.UserConfigData{}
27+
28+
closeTestFiles := initTestConfig(t)
29+
defer closeTestFiles()
30+
2531
err := sendReport(
2632
&UserConfigData,
2733
"34qsdf-24qsadf-32542q",
@@ -48,3 +54,58 @@ func TestSendReport(t *testing.T) {
4854
t.Errorf("SendReport() error = %v", err)
4955
}
5056
}
57+
58+
func initTestConfig(t *testing.T) func() {
59+
dir := "testdata"
60+
err := os.MkdirAll(dir, 0755)
61+
if err != nil {
62+
t.Logf("Failed to create testdata dir: %v", err)
63+
}
64+
65+
f, err := os.Create(filepath.Join(dir, "user.conf"))
66+
if err != nil {
67+
t.Logf("Failed to create temp file: %v", err)
68+
}
69+
70+
f.Write([]byte(`{
71+
"country": "US",
72+
"proxy": {
73+
"proxies": [
74+
{
75+
"addr": "1.1.1.1",
76+
"track": "raichu",
77+
"location": {
78+
"city": "New York",
79+
"country": "United States",
80+
"countryCode": "US",
81+
"latitude": 1.23,
82+
"longitude": 4.56
83+
},
84+
"name": "raichu-proxy",
85+
"port": 123,
86+
"protocol": "tlsmasq",
87+
"certPem": "pem",
88+
"authToken": "token",
89+
"trusted": true,
90+
"connectCfgTlsmasq": {
91+
"originAddr": "google.com",
92+
"secret": "password",
93+
"tlsMinVersion": "1"
94+
}
95+
}
96+
]
97+
}
98+
}`))
99+
100+
conf, err := userconfig.Init(dir, true)
101+
if err != nil {
102+
t.Logf("Failed to initialize user config: %v", err)
103+
}
104+
if conf != nil {
105+
t.Logf("User config initialized successfully")
106+
}
107+
return func() {
108+
f.Close()
109+
os.RemoveAll(dir)
110+
}
111+
}

issue/mocks/a.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

issue/mocks/b.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)