Ejemplo n.º 1
0
 def test_basic(self):
     fixture = TempDir()
     sentinel = object()
     self.assertEqual(sentinel, getattr(fixture, 'path', sentinel))
     fixture.setUp()
     try:
         path = fixture.path
         self.assertTrue(os.path.isdir(path))
     finally:
         fixture.cleanUp()
         self.assertFalse(os.path.isdir(path))
Ejemplo n.º 2
0
    def test_regular_file(self):
        """
        A ``file:`` description with any path other than ``-`` causes logs to be
        written to a file with that name.
        """
        tempdir = TempDir()
        self.useFixture(tempdir)

        reactor = object()
        path = tempdir.join("regular_file")

        self.assertThat(
            _parse_destination_description("file:{}".format(path))(reactor),
            MatchesStructure(
                file=MatchesStructure(
                    path=Equals(path),
                    rotateLength=AfterPreprocessing(bool, Equals(True)),
                    maxRotatedFiles=AfterPreprocessing(bool, Equals(True)),
                ),
            ),
        )
Ejemplo n.º 3
0
 def test_under_dir(self):
     root = self.useFixture(TempDir()).path
     fixture = TempDir(root)
     fixture.setUp()
     with fixture:
         self.assertThat(fixture.path, StartsWith(root))
Ejemplo n.º 4
0
 def _setUp(self):
     self.tempdir = FilePath(self.useFixture(TempDir()).join(b"storage"))
     self.storage_server = StorageServer(
         self.tempdir.asBytesMode().path,
         b"x" * 20,
     )
Ejemplo n.º 5
0
 def setUp(self):
     super().setUp()
     self.tempdir = Path(self.useFixture(TempDir()).path)
Ejemplo n.º 6
0
    def test_unblinded_tokens_spent(
            self,
            logger,
            get_config,
            now,
            announcement,
            voucher,
            num_passes,
    ):
        """
        The ``ZKAPAuthorizerStorageServer`` returned by ``get_storage_client``
        spends unblinded tokens from the plugin database.
        """
        tempdir = self.useFixture(TempDir())
        node_config = get_config(
            tempdir.join(b"node"),
            b"tub.port",
        )

        store = VoucherStore.from_node_config(node_config, lambda: now)

        controller = PaymentController(
            store,
            DummyRedeemer(),
            default_token_count=num_passes,
            num_redemption_groups=1,
            clock=Clock(),
        )
        # Get a token inserted into the store.
        redeeming = controller.redeem(voucher)
        self.assertThat(
            redeeming,
            succeeded(Always()),
        )

        storage_client = storage_server.get_storage_client(
            node_config,
            announcement,
            get_rref,
        )

        # None of the remote methods are implemented by our fake server and I
        # would like to continue to avoid to have a real server in these
        # tests, at least until creating a real server doesn't involve so much
        # complex setup.  So avoid using any of the client APIs that make a
        # remote call ... which is all of them.
        pass_group = storage_client._get_passes(u"request binding message", num_passes)
        pass_group.mark_spent()

        # There should be no unblinded tokens left to extract.
        self.assertThat(
            lambda: storage_client._get_passes(u"request binding message", 1),
            raises(NotEnoughTokens),
        )

        messages = LoggedMessage.of_type(logger.messages, GET_PASSES)
        self.assertThat(
            messages,
            MatchesAll(
                HasLength(1),
                AllMatch(
                    AfterPreprocessing(
                        lambda logged_message: logged_message.message,
                        ContainsDict({
                            u"message": Equals(u"request binding message"),
                            u"count": Equals(num_passes),
                        }),
                    ),
                ),
            ),
        )
Ejemplo n.º 7
0
 def setUp(self):
     super(TestCase, self).setUp()
     self.configs = FilePath(self.useFixture(TempDir()).path)
    def test_get_order_matches_use_order(self, get_config, api_auth_token,
                                         voucher, extra_tokens):
        """
        The first unblinded token returned in a response to a **GET** request is
        the first token to be used to authorize a storage request.
        """
        def after(d, f):
            new_d = Deferred()

            def f_and_continue(result):
                maybeDeferred(f).chainDeferred(new_d)
                return result

            d.addCallback(f_and_continue)
            return new_d

        def get_tokens():
            d = authorized_request(
                api_auth_token,
                agent,
                b"GET",
                b"http://127.0.0.1/unblinded-token",
            )
            d.addCallback(readBody)
            d.addCallback(lambda body: loads(body)[u"unblinded-tokens"], )
            return d

        def use_a_token():
            root.store.discard_unblinded_tokens(
                root.store.get_unblinded_tokens(1), )

        config = get_config_with_api_token(
            self.useFixture(TempDir()),
            get_config,
            api_auth_token,
        )
        root = root_from_config(config, datetime.now)

        num_tokens = root.controller.num_redemption_groups + extra_tokens

        # Put in a number of tokens with which to test.
        redeeming = root.controller.redeem(voucher, num_tokens)
        # Make sure the operation completed before proceeding.
        self.assertThat(
            redeeming,
            succeeded(Always()),
        )

        agent = RequestTraversalAgent(root)
        getting_initial_tokens = get_tokens()
        using_a_token = after(getting_initial_tokens, use_a_token)
        getting_tokens_after = after(using_a_token, get_tokens)

        self.assertThat(
            gatherResults([getting_initial_tokens, getting_tokens_after]),
            succeeded(
                MatchesPredicate(
                    lambda (initial_tokens, tokens_after): initial_tokens[1:]
                    == tokens_after,
                    u"initial, after (%s): initial[1:] != after",
                ), ),
        )