diff options
author | Ruben Pollan <meskio@sindominio.net> | 2017-10-06 11:50:36 +0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2017-10-06 18:38:42 +0200 |
commit | a5cb9c9940b34252da66d43498d705980532f60c (patch) | |
tree | 8a4c700c34e09c2faf6f8fe11504cd7c9a8a0350 /tests | |
parent | b66ec16f764be769e4a15dae783292ac4cd32f3b (diff) |
[feat] use bonafide Provider object as a singleton
There was common situations where two provider instances where running
in parallel. And was creating weird errors (like getting wrong api_uri)
because the bootstrap deferreds were global but the Provider objects
not.
I don't like much singletons, but I think now is simpler than before.
- Resolves: #9073
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/bonafide/test_config.py | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/tests/integration/bonafide/test_config.py b/tests/integration/bonafide/test_config.py index 5d45189..ee6cdc5 100644 --- a/tests/integration/bonafide/test_config.py +++ b/tests/integration/bonafide/test_config.py @@ -37,12 +37,14 @@ class ConfigTest(BaseHTTPSServerTestCase, unittest.TestCase, BaseLeapTest): self.cacert = os.path.join(os.path.dirname(__file__), "cacert.pem") + @defer.inlineCallbacks def test_bootstrap_self_sign_cert_fails(self): home = os.path.join(self.home, 'self_sign') os.mkdir(home) - provider = Provider(self.addr.domain, autoconf=True, basedir=home) + provider = Provider.get(self.addr.domain, autoconf=True, basedir=home) d = provider.callWhenMainConfigReady(lambda: "Cert was accepted") - return self.assertFailure(d, NetworkError) + yield self.assertFailure(d, NetworkError) + Provider.providers[self.addr.domain] = None @defer.inlineCallbacks def test_bootstrap_invalid_ca_cert(self): @@ -58,15 +60,17 @@ class ConfigTest(BaseHTTPSServerTestCase, unittest.TestCase, BaseLeapTest): provider._http.close() try: yield defer.gatherResults([ - d, provider.ongoing_bootstrap[provider._domain]]) + d, provider.ongoing_bootstrap]) except: pass + Provider.providers[self.addr.domain] = None + @defer.inlineCallbacks def test_bootstrap_pinned_cert(self): home = os.path.join(self.home, 'pinned') os.mkdir(home) - provider = Provider(self.addr.domain, autoconf=True, basedir=home, - cert_path=self.cacert) + provider = Provider.get(self.addr.domain, autoconf=True, basedir=home, + cert_path=self.cacert) def check_provider(): config = provider.config() @@ -74,9 +78,31 @@ class ConfigTest(BaseHTTPSServerTestCase, unittest.TestCase, BaseLeapTest): self.assertEqual(config["ca_cert_fingerprint"], "SHA256: %s" % fingerprint) - d = provider.callWhenMainConfigReady(check_provider) - return defer.gatherResults([ - d, provider.ongoing_bootstrap[provider._domain]]) + yield provider.callWhenMainConfigReady(check_provider) + provider._http.close() + yield provider.ongoing_bootstrap + Provider.providers[self.addr.domain] = None + + @defer.inlineCallbacks + def test_api_uri(self): + api_uri = "api.example.com" + self.addr.api_uri = api_uri + home = os.path.join(self.home, 'api_uri') + os.mkdir(home) + provider = Provider.get(self.addr.domain, autoconf=True, + basedir=home, cert_path=self.cacert) + + def check_api_uri(): + parsed_uri = provider.api_uri + self.assertEqual(api_uri, parsed_uri) + + yield provider.callWhenMainConfigReady(check_api_uri) + provider._http.close() + try: + yield provider.ongoing_bootstrap + except: + pass + Provider.providers[self.addr.domain] = None class Addr(object): @@ -84,6 +110,7 @@ class Addr(object): self.host = host self.port = port self.fingerprint = fingerprint + self.api_uri = "https://%s:%s" % (host, port) @property def domain(self): @@ -95,6 +122,7 @@ def request_handler(addr): def do_GET(self): if self.path == '/provider.json': body = provider_json % { + 'api_uri': addr.api_uri, 'host': addr.host, 'port': addr.port, 'fingerprint': addr.fingerprint @@ -126,7 +154,7 @@ fingerprint = \ "cd0131b3352b7a29c307156b24f09fe862b1f5a2e55be7cd888048b91770f220" provider_json = """ { - "api_uri": "https://%(host)s:%(port)s", + "api_uri": "%(api_uri)s", "api_version": "1", "ca_cert_fingerprint": "SHA256: %(fingerprint)s", "ca_cert_uri": "https://%(host)s:%(port)s/ca.crt", |