summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2017-08-11 13:17:37 -0400
committerKali Kaneko <kali@leap.se>2017-08-11 14:22:00 -0400
commit8487dcd0b9565657e1e6e89c7d8467d54a7c41ba (patch)
tree8dafa611cba74fa0427200c485baa408a2c27d6b /tests/unit
parent7a5b050ca704792a9b1c87d038db9851e8802473 (diff)
[feature] allow manual gateway selection for vpn
For now, the way to select a gateway is to add a section in bitmaskd.cfg: [vpn_prefs] locations = ["frankfurt", "seattle__wa"] countries = ["DE", "US"] Note that the location indication has priority over country code. This will be exposed by the UI in release 0.11 - Resolves: #8855
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/vpn/test_gateways.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/unit/vpn/test_gateways.py b/tests/unit/vpn/test_gateways.py
index cc7fbca3..58b26761 100644
--- a/tests/unit/vpn/test_gateways.py
+++ b/tests/unit/vpn/test_gateways.py
@@ -126,3 +126,41 @@ class GatewaySelectorTestCase(unittest.TestCase):
14)
gateways = selector.select_gateways()
assert gateways == [ips[4], ips[2], ips[3], ips[1]]
+
+ def test_apply_user_preferences(self):
+ preferred = {
+ 'loc': ['anarres', 'paris__fr', 'montevideo'],
+ 'cc': ['BR', 'AR', 'UY'],
+ }
+ selector = GatewaySelector(preferred=preferred)
+ pre = [
+ ('Seattle', '1.1.1.1', 'US'),
+ ('Rio de Janeiro', '1.1.1.1', 'BR'),
+ ('Montevideo', '1.1.1.1', 'UY'),
+ ('Cordoba', '1.1.1.1', 'AR')]
+ ordered = selector.apply_user_preferences(pre)
+ locations = [x[0] for x in ordered]
+ # first the preferred location, then order by country
+ assert locations == ['Montevideo', 'Rio de Janeiro', 'Cordoba', 'Seattle']
+
+ pre = [
+ ('Seattle', '', ''),
+ ('Montevideo', '', ''),
+ ('Paris, FR', '', ''),
+ ('AnaRreS', '', '')]
+ ordered = selector.apply_user_preferences(pre)
+ locations = [x[0] for x in ordered]
+ # first the preferred location, then order by country (test normalization)
+ assert locations == ['AnaRreS', 'Paris, FR', 'Montevideo', 'Seattle']
+
+ pre = [
+ ('Rio De Janeiro', '', 'BR'),
+ ('Tacuarembo', '', 'UY'),
+ ('Sao Paulo', '', 'BR'),
+ ('Cordoba', '', 'AR')]
+ ordered = selector.apply_user_preferences(pre)
+ locations = [x[0] for x in ordered]
+ # no matching location, order by country
+ assert locations == ['Rio De Janeiro', 'Sao Paulo', 'Cordoba', 'Tacuarembo']
+
+