|
| 1 | +# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 | + |
| 3 | +# Copyright (C) 2022 igo95862 |
| 4 | + |
| 5 | +# This file is part of python-sdbus |
| 6 | + |
| 7 | +# This library is free software; you can redistribute it and/or |
| 8 | +# modify it under the terms of the GNU Lesser General Public |
| 9 | +# License as published by the Free Software Foundation; either |
| 10 | +# version 2.1 of the License, or (at your option) any later version. |
| 11 | + |
| 12 | +# This library is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | +# Lesser General Public License for more details. |
| 16 | + |
| 17 | +# You should have received a copy of the GNU Lesser General Public |
| 18 | +# License along with this library; if not, write to the Free Software |
| 19 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | +from __future__ import annotations |
| 21 | + |
| 22 | +from unittest import TestCase |
| 23 | +from sdbus_async.networkmanager.settings import ConnectionProfile |
| 24 | + |
| 25 | +connection_dict = { |
| 26 | + 'connection': {'id': 'mlvd-wg', |
| 27 | + 'interface-name': 'mlvd-wg', |
| 28 | + 'timestamp': 150000, |
| 29 | + 'type': 'wireguard', |
| 30 | + 'uuid': 'uuid'}, |
| 31 | + 'ipv4': {'address-data': [{'address': '10.0.0.1', 'prefix': 32}], |
| 32 | + 'dns': [150000], |
| 33 | + 'dns-search': ['~'], |
| 34 | + 'method': 'manual'}, |
| 35 | + 'ipv6': {'addr-gen-mode': 1, |
| 36 | + 'address-data': [{'address': 'fc00:1', |
| 37 | + 'prefix': 128}], |
| 38 | + 'method': 'manual'}, |
| 39 | + 'wireguard': { |
| 40 | + 'peers': [ |
| 41 | + {'allowed-ips': ['::/0', '0.0.0.0/0'], |
| 42 | + 'endpoint': '1.1.1.1:51820', |
| 43 | + 'public-key': 'public_key'}]}} |
| 44 | + |
| 45 | +secret_dict = { |
| 46 | + 'connection': {}, |
| 47 | + 'ipv4': {}, |
| 48 | + 'ipv6': {}, |
| 49 | + 'proxy': {}, |
| 50 | + 'wireguard': { |
| 51 | + 'peers': [ |
| 52 | + {'public-key': 'public_key'} |
| 53 | + ], |
| 54 | + 'private-key': 'secret_key'}} |
| 55 | + |
| 56 | + |
| 57 | +class TestSettingsProfile(TestCase): |
| 58 | + def test_update(self) -> None: |
| 59 | + connection = ConnectionProfile.from_settings_dict(connection_dict) |
| 60 | + secrets = ConnectionProfile.from_settings_dict(secret_dict) |
| 61 | + |
| 62 | + connection.update(secrets) |
| 63 | + |
| 64 | + self.assertEqual(connection.wireguard.private_key, 'secret_key') |
0 commit comments