From 5aedd55cb4d19551097c5567c154ed22d5bab69b Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Tue, 16 Feb 2021 13:55:48 -0500
Subject: [PATCH] Introduce `direct_tahoe_configs` strategy

It builds _Configs instead of functions that return _Configs.
---
 src/_zkapauthorizer/tests/strategies.py  | 54 ++++++++++++++++++++----
 src/_zkapauthorizer/tests/test_plugin.py |  6 ++-
 2 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/src/_zkapauthorizer/tests/strategies.py b/src/_zkapauthorizer/tests/strategies.py
index 4384cac..a54282e 100644
--- a/src/_zkapauthorizer/tests/strategies.py
+++ b/src/_zkapauthorizer/tests/strategies.py
@@ -181,18 +181,15 @@ def minimal_tahoe_configs(storage_client_plugins=None, shares=just((None, None,
     Build complete Tahoe-LAFS configurations for a node.
 
     :param shares: See ``tahoe_config_texts``.
+
+    :return SearchStrategy[unicode]: A strategy that builds unicode strings
+        which are Tahoe-LAFS configuration file contents.
     """
     if storage_client_plugins is None:
         storage_client_plugins = {}
     return tahoe_config_texts(
         storage_client_plugins,
         shares,
-    ).map(
-        lambda config_text: lambda basedir, portnumfile: config_from_string(
-            basedir,
-            portnumfile,
-            config_text.encode("utf-8"),
-        ),
     )
 
 
@@ -310,7 +307,7 @@ def client_errorredeemer_configurations(details):
     })
 
 
-def tahoe_configs(
+def direct_tahoe_configs(
         zkapauthz_v1_configuration=client_dummyredeemer_configurations(),
         shares=just((None, None, None)),
 ):
@@ -319,10 +316,51 @@ def tahoe_configs(
     client plugin section.
 
     :param shares: See ``tahoe_config_texts``.
+
+    :return SearchStrategy[_Config]: A strategy that builds Tahoe config
+        objects.
     """
-    return minimal_tahoe_configs({
+    config_texts = minimal_tahoe_configs({
         u"privatestorageio-zkapauthz-v1": zkapauthz_v1_configuration,
     }, shares)
+    return config_texts.map(
+        lambda config_text: config_from_string(
+            u"/dev/null/illegal",
+            u"",
+            config_text.encode("utf-8"),
+        ),
+    )
+
+
+def tahoe_configs(
+        zkapauthz_v1_configuration=client_dummyredeemer_configurations(),
+        shares=just((None, None, None)),
+):
+    """
+    Build complete Tahoe-LAFS configurations including the zkapauthorizer
+    client plugin section.
+
+    You probably want ``direct_tahoe_configs``.
+
+    :param shares: See ``tahoe_config_texts``.
+
+    :return SearchStrategy[str -> str -> _Config]: A strategy that builds
+        two-argument functions that return a config object.  The two arguments
+        are the ``basedir`` and ``portnumfile`` arguments to Tahoe's
+        ``config_from_string.``
+    """
+    def path_setter(config):
+        def set_paths(basedir, portnumfile):
+            config._basedir = basedir.decode("ascii")
+            config.portnum_fname = portnumfile
+            return config
+        return set_paths
+    return direct_tahoe_configs(
+        zkapauthz_v1_configuration,
+        shares,
+    ).map(
+        path_setter,
+    )
 
 
 def share_parameters():
diff --git a/src/_zkapauthorizer/tests/test_plugin.py b/src/_zkapauthorizer/tests/test_plugin.py
index e28f06b..e0c4e8c 100644
--- a/src/_zkapauthorizer/tests/test_plugin.py
+++ b/src/_zkapauthorizer/tests/test_plugin.py
@@ -83,6 +83,7 @@ from allmydata.interfaces import (
     RIStorageServer,
 )
 from allmydata.client import (
+    config_from_string,
     create_client_from_config,
 )
 
@@ -375,15 +376,16 @@ class ClientPluginTests(TestCase):
 
 
     @given(tahoe_configs_with_mismatched_issuer, announcements())
-    def test_mismatched_ristretto_issuer(self, get_config, announcement):
+    def test_mismatched_ristretto_issuer(self, config_text, announcement):
         """
         ``get_storage_client`` raises an exception when called with an
         announcement and local configuration which specify different issuers.
         """
         tempdir = self.useFixture(TempDir())
-        node_config = get_config(
+        node_config = config_from_string(
             tempdir.join(b"node"),
             b"tub.port",
+            config_text.encode("utf-8"),
         )
         config_text = BytesIO()
         node_config.config.write(config_text)
-- 
GitLab