File indexing completed on 2024-10-06 09:44:10

0001 /*
0002     SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "wirelesssecuritysettingtest.h"
0008 
0009 #include <libnm/NetworkManager.h>
0010 
0011 #include "settings/wirelesssecuritysetting.h"
0012 
0013 #include <QTest>
0014 
0015 #if !NM_CHECK_VERSION(1, 10, 0)
0016 #define NM_SETTING_WIRELESS_SECURITY_PMF "pmf"
0017 #endif
0018 
0019 void WirelessSecuritySettingTest::testSetting_data()
0020 {
0021     QTest::addColumn<QString>("keyMgmt");
0022     QTest::addColumn<quint32>("wepTxKeyidx");
0023     QTest::addColumn<QString>("authAlg");
0024     QTest::addColumn<QStringList>("proto");
0025     QTest::addColumn<QStringList>("pairwise");
0026     QTest::addColumn<QStringList>("group");
0027     QTest::addColumn<QString>("leapUsername");
0028     QTest::addColumn<QString>("wepKey0");
0029     QTest::addColumn<QString>("wepKey1");
0030     QTest::addColumn<QString>("wepKey2");
0031     QTest::addColumn<QString>("wepKey3");
0032     QTest::addColumn<quint32>("wepKeyFlags");
0033     QTest::addColumn<quint32>("wepKeyType");
0034     QTest::addColumn<QString>("psk");
0035     QTest::addColumn<quint32>("pskFlags");
0036     QTest::addColumn<QString>("leapPassword");
0037     QTest::addColumn<quint32>("leapPasswordFlags");
0038     QTest::addColumn<quint32>("pmf");
0039 
0040     QStringList proto;
0041     proto << "wpa";
0042     proto << "rsn";
0043 
0044     QStringList pairwise;
0045     pairwise << "wep40";
0046     pairwise << "ccmp";
0047 
0048     QStringList group;
0049     group << "wep104";
0050     group << "tkip";
0051 
0052     QTest::newRow("setting1") << QString("none") // keyMgmt
0053                               << (quint32)1 // wepTxKeyIdx
0054                               << QString("open") // authAlg
0055                               << proto // proto
0056                               << pairwise // pairwise
0057                               << group // group
0058                               << QString("login") // leapUsername
0059                               << QString("abcde") // wepKey0
0060                               << QString("fghij") // wepKey1
0061                               << QString("klmno") // wepKey2
0062                               << QString("pqrst") // wepKey3
0063                               << (quint32)1 // wepKeyFlags
0064                               << (quint32)1 // wepKeyType
0065                               << QString("12345678") // psk
0066                               << (quint32)2 // pskFlags
0067                               << QString("leappass") // leapPassword
0068                               << (quint32)4 // leapPasswordFlags
0069                               << (quint32)3; // pmf
0070 }
0071 
0072 void WirelessSecuritySettingTest::testSetting()
0073 {
0074     QFETCH(QString, keyMgmt);
0075     QFETCH(quint32, wepTxKeyidx);
0076     QFETCH(QString, authAlg);
0077     QFETCH(QStringList, proto);
0078     QFETCH(QStringList, pairwise);
0079     QFETCH(QStringList, group);
0080     QFETCH(QString, leapUsername);
0081     QFETCH(QString, wepKey0);
0082     QFETCH(QString, wepKey1);
0083     QFETCH(QString, wepKey2);
0084     QFETCH(QString, wepKey3);
0085     QFETCH(quint32, wepKeyFlags);
0086     QFETCH(quint32, wepKeyType);
0087     QFETCH(QString, psk);
0088     QFETCH(quint32, pskFlags);
0089     QFETCH(QString, leapPassword);
0090     QFETCH(quint32, leapPasswordFlags);
0091     QFETCH(quint32, pmf);
0092 
0093     QVariantMap map;
0094 
0095     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), keyMgmt);
0096     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX), wepTxKeyidx);
0097     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), authAlg);
0098     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO), proto);
0099     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE), pairwise);
0100     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP), group);
0101     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), leapUsername);
0102     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), wepKey0);
0103     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), wepKey1);
0104     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), wepKey2);
0105     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), wepKey3);
0106     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS), wepKeyFlags);
0107     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), wepKeyType);
0108     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), psk);
0109     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS), pskFlags);
0110     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), leapPassword);
0111     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS), leapPasswordFlags);
0112     map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PMF), pmf);
0113 
0114     NetworkManager::WirelessSecuritySetting setting;
0115     setting.fromMap(map);
0116 
0117     QVariantMap map1 = setting.toMap();
0118 
0119     // Will fail if set some default values, because they are skipped in toMap() method
0120     QVariantMap::const_iterator it = map.constBegin();
0121     while (it != map.constEnd()) {
0122         QCOMPARE(it.value(), map1.value(it.key()));
0123         ++it;
0124     }
0125 }
0126 
0127 QTEST_MAIN(WirelessSecuritySettingTest)
0128 
0129 #include "moc_wirelesssecuritysettingtest.cpp"