Skip to content

Commit

Permalink
Merge branch 'master' into riseup_tests_improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Oct 11, 2023
2 parents 1fca652 + 4828c58 commit 1ff4081
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
15 changes: 7 additions & 8 deletions internal/experiment/riseupvpn/riseupvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const (
tcpConnect = "tcpconnect://"
)

// EipServiceV3 is the main JSON object of eip-service.json.
type EipServiceV3 struct {
// EIPServiceV3 is the main JSON object returned by eip-service.json.
type EIPServiceV3 struct {
Gateways []GatewayV3
}

Expand All @@ -38,7 +38,6 @@ type GatewayV3 struct {
Capabilities CapabilitiesV3
Host string
IPAddress string `json:"ip_address"`
Location string `json:"location"`
}

// TransportV3 describes a transport.
Expand Down Expand Up @@ -204,7 +203,6 @@ func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
NoTLSVerify: !testkeys.CACertStatus,
}},
}

for entry := range multi.CollectOverall(ctx, inputs, 1, 20, "riseupvpn", callbacks) {
testkeys.UpdateProviderAPITestKeys(entry)
}
Expand Down Expand Up @@ -238,6 +236,7 @@ func (m Measurer) Run(ctx context.Context, args *model.ExperimentArgs) error {
// TODO(bassosimone): when urlgetter is able to do obfs4 handshakes, here
// can possibly also test for the obfs4 handshake.
// See https://github.com/ooni/probe/issues/1463.
startCount += len(openvpnEndpoints)
for entry := range multi.CollectOverall(
ctx, obfs4Endpoints, startCount, overallCount, "riseupvpn", callbacks) {
testkeys.AddGatewayConnectTestKeys(entry, "obfs4")
Expand Down Expand Up @@ -282,7 +281,7 @@ func parseGateways(testKeys *TestKeys) []GatewayV3 {
// TODO(bassosimone,cyberta): is it reasonable that we discard
// the error when the JSON we fetched cannot be parsed?
// See https://github.com/ooni/probe/issues/1432
eipService, err := DecodeEIP3(string(requestEntry.Response.Body))
eipService, err := DecodeEIPServiceV3(string(requestEntry.Response.Body))
if err == nil {
return eipService.Gateways
}
Expand Down Expand Up @@ -363,9 +362,9 @@ func (geoService *GeoService) isHealthyGateway(gateway GatewayV3) bool {
return false
}

// DecodeEIP3 decodes eip-service.json version 3
func DecodeEIP3(body string) (*EipServiceV3, error) {
var eip EipServiceV3
// DecodeEIPServiceV3 decodes eip-service.json version 3
func DecodeEIPServiceV3(body string) (*EIPServiceV3, error) {
var eip EIPServiceV3
err := json.Unmarshal([]byte(body), &eip)
if err != nil {
return nil, err
Expand Down
25 changes: 23 additions & 2 deletions internal/experiment/riseupvpn/riseupvpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,29 @@ func TestFailureGateway1TransportNOK(t *testing.T) {
}
}

func TestIgnoreOverloadedGateways(t *testing.T) {
eipService, err := riseupvpn.DecodeEIP3(eipservice)
func TestFailureTransport(t *testing.T) {
measurement := runDefaultMockTest(t, generateDefaultMockGetter(map[string]bool{
cacerturl: true,
eipserviceurl: true,
providerurl: true,
geoserviceurl: true,
openvpnurl1: false,
openvpnurl2: false,
obfs4url1: false,
}))
tk := measurement.TestKeys.(*riseupvpn.TestKeys)

if tk.TransportStatus == nil || tk.TransportStatus["openvpn"] != "blocked" {
t.Fatal("invalid TransportStatus: " + fmt.Sprint(tk.TransportStatus))
}

if tk.TransportStatus == nil || tk.TransportStatus["obfs4"] != "blocked" {
t.Fatal("invalid TransportStatus: " + fmt.Sprint(tk.TransportStatus))
}
}

func TestMissingTransport(t *testing.T) {
eipService, err := riseupvpn.DecodeEIPServiceV3(eipservice)
if err != nil {
t.Fatal("Preconditions for the test are not met.")
}
Expand Down

0 comments on commit 1ff4081

Please sign in to comment.