diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/pixelated/bitmask_libraries/provider.py | 4 | ||||
-rw-r--r-- | service/pixelated/config/leap.py | 2 | ||||
-rw-r--r-- | service/pixelated/config/leap_config.py | 2 | ||||
-rw-r--r-- | service/test/reactor/concurrent_logins.rb | 33 | ||||
-rwxr-xr-x | service/test/reactor/create_users.py | 69 |
5 files changed, 107 insertions, 3 deletions
diff --git a/service/pixelated/bitmask_libraries/provider.py b/service/pixelated/bitmask_libraries/provider.py index 07791624..cd4af7e2 100644 --- a/service/pixelated/bitmask_libraries/provider.py +++ b/service/pixelated/bitmask_libraries/provider.py @@ -30,7 +30,6 @@ class LeapProvider(object): self.server_name = server_name self.local_ca_crt = '%s/ca.crt' % leap_config.leap_home self.provider_json = self.fetch_provider_json() - self.soledad_json = self.fetch_soledad_json() @property def api_uri(self): @@ -66,6 +65,9 @@ class LeapProvider(object): if 'mx' not in self.services: raise Exception + def download_soledad_json(self): + self.soledad_json = self.fetch_soledad_json() + def download_certificate(self, filename=None): """ Downloads the server certificate, validates it against the provided fingerprint and stores it to file diff --git a/service/pixelated/config/leap.py b/service/pixelated/config/leap.py index b14aacc7..52e84386 100644 --- a/service/pixelated/config/leap.py +++ b/service/pixelated/config/leap.py @@ -21,7 +21,7 @@ def initialize_leap_provider(provider_hostname, provider_cert, provider_fingerpr provider = LeapProvider(provider_hostname) provider.download_certificate() LeapCertificate(provider).setup_ca_bundle() - + provider.download_soledad_json() return provider diff --git a/service/pixelated/config/leap_config.py b/service/pixelated/config/leap_config.py index 324edc5e..7319d82b 100644 --- a/service/pixelated/config/leap_config.py +++ b/service/pixelated/config/leap_config.py @@ -30,7 +30,7 @@ def discover_gpg_binary(): SYSTEM_CA_BUNDLE = True -leap_home = '~/.leap/' +leap_home = os.path.expanduser('~/.leap/') gpg_binary = discover_gpg_binary() diff --git a/service/test/reactor/concurrent_logins.rb b/service/test/reactor/concurrent_logins.rb new file mode 100644 index 00000000..a10d0394 --- /dev/null +++ b/service/test/reactor/concurrent_logins.rb @@ -0,0 +1,33 @@ +# We use this script to simulate the login of multiple concurrent users, with +# one login per second. +# +# To use it, you need: +# -ruby +# -pre-created users +# +# This can be run with `ruby blocking_spawner <x>` +# where x is the number of users you want to login. +# +# It was created to measure login times internally on the application with +# varying number of users + + +USER_PATTERN = "loadtest%d" +PASSWORD_PATTERN = "password_%d" +COUNT = ARGV[0].to_i + +def curl_command(index) + username = USER_PATTERN % [index] + password = PASSWORD_PATTERN % [index] + "curl --silent -X POST --data 'username=#{username}&password=#{password}' --cookie 'XSRF-TOKEN: blablabla' --header 'X-Requested-With: XMLHttpRequest' --header 'X-XSRF-TOKEN: blablabla' http://localhost:3333/login" +end + +ts = (1...(1+COUNT)).map do |ix| + t = Thread.new do + `#{curl_command(ix)}` + end + sleep 1 + t +end + +ts.each(&:join) diff --git a/service/test/reactor/create_users.py b/service/test/reactor/create_users.py new file mode 100755 index 00000000..7c35df60 --- /dev/null +++ b/service/test/reactor/create_users.py @@ -0,0 +1,69 @@ +# This script is used to mass register users +# ATTENTION: this script does not log +# the user in, so key creation will only +# happen on the first login +# +# You can run this with the following command: +# python create_users.py -n<number of users> -p<provider> -i<invite_code> + +import argparse +import os +import tempfile +from leap.auth import SRPAuth +from leap.exceptions import SRPAuthenticationError + +import requests +from requests.packages.urllib3.exceptions import InsecureRequestWarning +requests.packages.urllib3.disable_warnings(InsecureRequestWarning) + + +class User(object): + def __init__(self, number, provider, certificate): + self._username = 'loadtest%d' % number + self._password = 'password_%d' % number + self._set_srp_auth(provider, certificate) + + def _set_srp_auth(self, leap_provider, certificate): + leap_api_server = 'https://api.%s:4430' % leap_provider + self._srp_auth = SRPAuth(leap_api_server, certificate) + + def get_or_create_user(self, invite_code=None): + try: + self.authenticate() + except SRPAuthenticationError: + self.register(invite_code) + return self._username, self._password + + def authenticate(self): + self._srp_auth.authenticate(self._username, self._password) + + def register(self, invite_code=None): + self._srp_auth.register(self._username, self._password, invite_code) + + +def mass_register(number, invite_code, provider, certificate): + for index in xrange(1, number + 1): + User(index, provider, certificate).register(invite_code) + print 'done registering loadtest%d' % index + + +def fetch_leap_certificate(leap_provider): + _, certificate_path = tempfile.mkstemp() + certificate = requests.get('https://%s/ca.crt' % leap_provider) + with open(certificate_path, 'w') as cert: + cert.write('%s' % certificate.content) + return certificate_path + + +def _parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--number', '-n', default=1, type=int, help='the number of user to be registered') + parser.add_argument('--invite-code', '-i', default=None, help='invite code') + parser.add_argument('--provider', '-p', default=None, help='leap provider e.g. unstable.pix.org') + return parser.parse_args() + + +if __name__ == '__main__': + args = _parse_args() + certificate_file = fetch_leap_certificate(args.provider) + mass_register(args.number, args.invite_code, args.provider, certificate_file) |