Exemplo n.º 1
0
    def test_get_public_copy(self):
        """Test the function hide_secrets."""
        data_1 = self.Data()
        data_1.a = "a"
        data_1.b.set_secret("b")
        data_1.c.set_secret(["c1", "c2", "c3"])
        data_2 = get_public_copy(data_1)

        self.assertIsNot(data_1, data_2)

        self.assertEqual(
            get_native(self.Data.to_structure(data_1)), {
                "a": "a",
                "b": {
                    "type": SECRET_TYPE_TEXT,
                    "value": "b"
                },
                "c": {
                    "type": SECRET_TYPE_TEXT,
                    "value": ["c1", "c2", "c3"]
                },
            })

        self.assertEqual(
            get_native(self.Data.to_structure(data_2)), {
                "a": "a",
                "b": {
                    "type": SECRET_TYPE_HIDDEN,
                    "value": ""
                },
                "c": {
                    "type": SECRET_TYPE_HIDDEN,
                    "value": []
                },
            })
Exemplo n.º 2
0
    def subscription_request(self):
        """Subscription request.

        A DBus structure holding data to be used to subscribe the system.

        :return: subscription request DBus structure
        :rtype: DBusData instance
        """
        # Return a deep copy of the subscription request that
        # has also been cleared of private data.
        # Thankfully the secret Dbus structures modules
        # has the get_public_copy() method that does just
        # that. It creates a deep copy & clears
        # all SecretData and SecretDataList instances.
        return get_public_copy(self._subscription_request)