Skip to content

Commit

Permalink
Fix connect for country and city name using local servers list (#524)
Browse files Browse the repository at this point in the history
Signed-off-by: Marius Sincovici <[email protected]>

* Fix how server tags are generated when combining country and city name.
* Update unit-tests to check connect when using the API servers and also for local cached servers list
  • Loading branch information
mariusSincovici authored Aug 6, 2024
1 parent acc355c commit 4835f2d
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 114 deletions.
104 changes: 94 additions & 10 deletions daemon/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@ func serversList() core.Servers {
},
}

dipGroups := core.Groups{
core.Group{
ID: config.DedicatedIP,
Title: "Dedicated IP",
},
core.Group{
ID: config.StandardVPNServers,
Title: "Standard VPN Servers",
},
}

virtualServer := []core.Specification{
{
Identifier: core.VirtualLocation,
Expand Down Expand Up @@ -322,8 +333,7 @@ func serversList() core.Servers {
},
},
},
Groups: groups,
Specifications: virtualServer,
Groups: groups,
},
core.Server{
ID: 3,
Expand All @@ -345,8 +355,7 @@ func serversList() core.Servers {
},
},
},
Specifications: virtualServer,
Groups: groups,
Groups: groups,
},
core.Server{
ID: 4,
Expand Down Expand Up @@ -384,18 +393,86 @@ func serversList() core.Servers {
Groups: groups,
},
core.Server{
ID: 6,
Name: "Canada #944",
Hostname: "ca944.nordvpn.com",
ID: 7,
Hostname: "lt7.nordvpn.com",
Status: core.Online,
Technologies: technologies,
CreatedAt: "2006-01-02 15:04:05",
Station: "127.0.0.1",
Locations: core.Locations{
core.Location{
Country: core.Country{Name: "Lithuania",
Code: "LT",
City: core.City{Name: "Vilnius"},
},
},
},
Groups: dipGroups,
},
core.Server{
ID: 8,
Hostname: "lt8.nordvpn.com",
Status: core.Online,
Technologies: technologies,
CreatedAt: "2006-01-02 15:04:05",
Station: "127.0.0.1",
Locations: core.Locations{
core.Location{
Country: core.Country{Name: "Lithuania",
Code: "LT",
City: core.City{Name: "Kaunas"},
},
},
},
Groups: dipGroups,
},
core.Server{
ID: 9,
Hostname: "lt9.nordvpn.com",
Status: core.Offline,
Technologies: technologies,
CreatedAt: "2006-01-02 15:04:05",
Station: "127.0.0.1",
Locations: core.Locations{
core.Location{
Country: core.Country{Name: "Lithuania",
Code: "LT",
City: core.City{Name: "Kaunas"},
},
},
},
Groups: dipGroups,
},
core.Server{
ID: 10,
Hostname: "dz1.nordvpn.com",
Status: core.Online,
Technologies: technologies,
CreatedAt: "2006-01-02 15:04:05",
Station: "127.0.0.1",
Locations: core.Locations{
core.Location{
Country: core.Country{Name: "Algeria",
Code: "DZ",
City: core.City{Name: "Algiers"},
},
},
},
Specifications: virtualServer,
Groups: groups,
},
core.Server{
ID: 11,
Hostname: "dz2.nordvpn.com",
Status: core.Online,
Technologies: obfuscatedTechnologies,
CreatedAt: "2006-01-02 15:04:05",
Station: "127.0.0.1",
Locations: core.Locations{
core.Location{
Country: core.Country{Name: "Canada",
Code: "CA",
City: core.City{Name: "Toronto"},
Country: core.Country{Name: "Algeria",
Code: "DZ",
City: core.City{Name: "Algiers"},
},
},
},
Expand Down Expand Up @@ -450,5 +527,12 @@ func countriesList() core.Countries {
{Name: "Berlin"},
},
},
{
Name: "Algeria",
Code: "DZ",
Cities: []core.City{
{Name: "Algiers"},
},
},
}
}
4 changes: 2 additions & 2 deletions daemon/job_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func generateKeys(server core.Server) []string {
return append([]string{
loweredCountryName,
loweredCountryCode,
loweredCountryName + loweredCityName,
loweredCountryCode + loweredCityName,
loweredCountryName + " " + loweredCityName,
loweredCountryCode + " " + loweredCityName,
loweredCityName,
loweredHostnameID,
}, loweredGroupTitles...)
Expand Down
28 changes: 4 additions & 24 deletions daemon/job_servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (mockServersAPI) Servers() (core.Servers, http.Header, error) {
}

func (mockServersAPI) RecommendedServers(filter core.ServersFilter, _ float64, _ float64) (core.Servers, http.Header, error) {
if filter.Group == config.DedicatedIP {
return nil, nil, fmt.Errorf("API must not be called for Dedicated IP")
}

var servers core.Servers
for _, server := range serversList() {
if server.Status != core.Online || isDedicatedIP(server) {
Expand All @@ -35,30 +39,6 @@ func (mockServersAPI) RecommendedServers(filter core.ServersFilter, _ float64, _
servers = append(servers, server)
}

if filter.Group == config.DedicatedIP {
return core.Servers{{
Name: "dedicated-ip",
Status: core.Online,
Station: "127.0.0.1",
CreatedAt: "2006-01-02 15:04:05",
Locations: core.Locations{
{
Country: core.Country{Name: "Romania"},
},
},
Technologies: core.Technologies{
{ID: core.WireguardTech, Pivot: core.Pivot{Status: core.Online}},
{ID: core.OpenVPNUDP, Pivot: core.Pivot{Status: core.Online}},
},
IPRecords: []core.ServerIPRecord{
{
ServerIP: core.ServerIP{IP: "127.0.0.1", Version: 4},
Type: "some type",
},
},
Groups: core.Groups{core.Group{ID: config.DedicatedIP, Title: "DedicatedIP"}},
}}, nil, nil
}
return servers, nil, nil
}

Expand Down
12 changes: 5 additions & 7 deletions daemon/rpc_cities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,27 @@ func TestRPCCities(t *testing.T) {
name: "results for country name with virtual servers only",
cm: newMockConfigManager(),
servers: serversList(),
countryName: "liThuania",
countryName: "alGeria",
statusCode: internal.CodeSuccess,
expected: []*pb.ServerGroup{
{Name: "Kaunas", VirtualLocation: true},
{Name: "Vilnius", VirtualLocation: true},
{Name: "Algiers", VirtualLocation: true},
},
},
{
name: "results for country code with virtual servers only",
cm: newMockConfigManager(),
servers: serversList(),
countryName: "lT",
countryName: "dz",
statusCode: internal.CodeSuccess,
expected: []*pb.ServerGroup{
{Name: "Kaunas", VirtualLocation: true},
{Name: "Vilnius", VirtualLocation: true},
{Name: "Algiers", VirtualLocation: true},
},
},
{
name: "no servers for country with virtual servers only and virtual location is off",
cm: newMockConfigManager(),
servers: serversList(),
countryName: "lT",
countryName: "dZ",
disableVirtualServers: true,
statusCode: internal.CodeSuccess,
expected: []*pb.ServerGroup{},
Expand Down
Loading

0 comments on commit 4835f2d

Please sign in to comment.