File indexing completed on 2024-10-06 03:43:31

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 "8021xsettingtest.h"
0008 
0009 #include "settings/security8021xsetting.h"
0010 
0011 #include <libnm/NetworkManager.h>
0012 
0013 #include <QTest>
0014 
0015 void Security8021xSettingTest::testSetting_data()
0016 {
0017     QTest::addColumn<QStringList>("eap");
0018     QTest::addColumn<QString>("identity");
0019     QTest::addColumn<QString>("anonymousIdentity");
0020     QTest::addColumn<QString>("pacFile");
0021     QTest::addColumn<QByteArray>("caCert");
0022     QTest::addColumn<QString>("domainSuffixMatch");
0023     QTest::addColumn<QString>("caPath");
0024     QTest::addColumn<QString>("subjectMatch");
0025     QTest::addColumn<QStringList>("altSubjectMatches");
0026     QTest::addColumn<QByteArray>("clientCert");
0027     QTest::addColumn<QString>("phase1PeapVer");
0028     QTest::addColumn<QString>("phase1PeapLabel");
0029     QTest::addColumn<QString>("phase1FastProvisioning");
0030     QTest::addColumn<QString>("phase2Auth");
0031     QTest::addColumn<QString>("phase2EapAuth");
0032     QTest::addColumn<QByteArray>("phase2CaCert");
0033     QTest::addColumn<QString>("phase2CaPath");
0034     QTest::addColumn<QString>("phase2SubjectMatch");
0035     QTest::addColumn<QStringList>("phase2AltSubjectMatches");
0036     QTest::addColumn<QByteArray>("phase2ClientCert");
0037     QTest::addColumn<QString>("password");
0038     QTest::addColumn<quint32>("passwordFlags");
0039     QTest::addColumn<QByteArray>("passwordRaw");
0040     QTest::addColumn<quint32>("passwordRawFlags");
0041     QTest::addColumn<QByteArray>("privateKey");
0042     QTest::addColumn<QString>("privateKeyPassword");
0043     QTest::addColumn<quint32>("privateKeyPasswordFlags");
0044     QTest::addColumn<QByteArray>("phase2PrivateKey");
0045     QTest::addColumn<QString>("phase2PrivateKeyPassword");
0046     QTest::addColumn<quint32>("phase2PrivateKeyPasswordFlags");
0047     QTest::addColumn<QString>("pin");
0048     QTest::addColumn<quint32>("pinFlags");
0049     QTest::addColumn<bool>("systemCaCerts");
0050 
0051     QStringList eapMethods;
0052     eapMethods << "leap"
0053                << "md5"
0054                << "tls"
0055                << "peap"
0056                << "ttls"
0057                << "fast";
0058 
0059     QStringList altSubjectMatches;
0060     altSubjectMatches << "subject1"
0061                       << "subject2";
0062 
0063     QTest::newRow("setting1") << eapMethods // eap
0064                               << QString("identity") // identity
0065                               << QString("anonymousIdentity") // anonymousIdentity
0066                               << QString("file://path/to/pac/file") // pacFile
0067                               << QByteArray("file://path/to/ca/cert") // caCert
0068                               << QString("example.com") // domainSuffixMatch
0069                               << QString("file://path/to/ca/cert") // caPath
0070                               << QString("subjectMatch") // subjectMatch
0071                               << altSubjectMatches // altSubjectMatches
0072                               << QByteArray("file://path/to/client/cert") // clientCert
0073                               << QString("1") // phase1PeapVer
0074                               << QString("1") // phase1PeapLabel
0075                               << QString("3") // phase1FastProvisioning
0076                               << QString("mschapv2") // phase2Auth
0077                               << QString("tls") // phase2EapAuth
0078                               << QByteArray("file://path/to/phase2/ca/cert") // phase2CaCert
0079                               << QString("file://path/to/phase2/ca/cert") // phase2CaPath
0080                               << QString("phase2SubjectMatch") // phase2SubjectMatch
0081                               << altSubjectMatches // phase2AltSubjectMatches
0082                               << QByteArray("file://path/to/phase2/client/cert") // phase2ClientCert
0083                               << QString("password") // password
0084                               << (quint32)2 // passwordFlags
0085                               << QByteArray("passwordRaw") // passwordRaw
0086                               << (quint32)4 // passwordFlags
0087                               << QByteArray("privateKey") // privateKey
0088                               << QString("privateKeyPassword") // privateKeyPassword
0089                               << (quint32)2 // privateKeyPasswordFlags
0090                               << QByteArray("phase2PrivateKey") // phase2PrivateKey
0091                               << QString("phase2PrivateKeyPassword") // phase2PrivateKeyPassword
0092                               << (quint32)4 // phase2PrivateKeyPasswordFlags
0093                               << QString("pin") // pin
0094                               << (quint32)2 // pinFlags
0095                               << true; // systemCaCerts
0096 }
0097 
0098 void Security8021xSettingTest::testSetting()
0099 {
0100     QFETCH(QStringList, eap);
0101     QFETCH(QString, identity);
0102     QFETCH(QString, anonymousIdentity);
0103     QFETCH(QString, pacFile);
0104     QFETCH(QByteArray, caCert);
0105     QFETCH(QString, domainSuffixMatch);
0106     QFETCH(QString, caPath);
0107     QFETCH(QString, subjectMatch);
0108     QFETCH(QStringList, altSubjectMatches);
0109     QFETCH(QByteArray, clientCert);
0110     QFETCH(QString, phase1PeapVer);
0111     QFETCH(QString, phase1PeapLabel);
0112     QFETCH(QString, phase1FastProvisioning);
0113     QFETCH(QString, phase2Auth);
0114     QFETCH(QString, phase2EapAuth);
0115     QFETCH(QByteArray, phase2CaCert);
0116     QFETCH(QString, phase2CaPath);
0117     QFETCH(QString, phase2SubjectMatch);
0118     QFETCH(QStringList, phase2AltSubjectMatches);
0119     QFETCH(QByteArray, phase2ClientCert);
0120     QFETCH(QString, password);
0121     QFETCH(quint32, passwordFlags);
0122     QFETCH(QByteArray, passwordRaw);
0123     QFETCH(quint32, passwordRawFlags);
0124     QFETCH(QByteArray, privateKey);
0125     QFETCH(QString, privateKeyPassword);
0126     QFETCH(quint32, privateKeyPasswordFlags);
0127     QFETCH(QByteArray, phase2PrivateKey);
0128     QFETCH(QString, phase2PrivateKeyPassword);
0129     QFETCH(quint32, phase2PrivateKeyPasswordFlags);
0130     QFETCH(QString, pin);
0131     QFETCH(quint32, pinFlags);
0132     QFETCH(bool, systemCaCerts);
0133 
0134     QVariantMap map;
0135 
0136     map.insert(QLatin1String(NM_SETTING_802_1X_EAP), eap);
0137     map.insert(QLatin1String(NM_SETTING_802_1X_IDENTITY), identity);
0138     map.insert(QLatin1String(NM_SETTING_802_1X_ANONYMOUS_IDENTITY), anonymousIdentity);
0139     map.insert(QLatin1String(NM_SETTING_802_1X_PAC_FILE), pacFile);
0140     map.insert(QLatin1String(NM_SETTING_802_1X_CA_CERT), caCert);
0141     map.insert(QLatin1String(NM_SETTING_802_1X_DOMAIN_SUFFIX_MATCH), domainSuffixMatch);
0142     map.insert(QLatin1String(NM_SETTING_802_1X_CA_PATH), caPath);
0143     map.insert(QLatin1String(NM_SETTING_802_1X_SUBJECT_MATCH), subjectMatch);
0144     map.insert(QLatin1String(NM_SETTING_802_1X_ALTSUBJECT_MATCHES), altSubjectMatches);
0145     map.insert(QLatin1String(NM_SETTING_802_1X_CLIENT_CERT), clientCert);
0146     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPVER), phase1PeapVer);
0147     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_PEAPLABEL), phase1PeapLabel);
0148     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING), phase1FastProvisioning);
0149     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTH), phase2Auth);
0150     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_AUTHEAP), phase2EapAuth);
0151     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_CERT), phase2CaCert);
0152     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CA_PATH), phase2CaPath);
0153     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH), phase2SubjectMatch);
0154     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES), phase2AltSubjectMatches);
0155     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_CLIENT_CERT), phase2ClientCert);
0156     map.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD), password);
0157     map.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD_FLAGS), passwordFlags);
0158     map.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW), passwordRaw);
0159     map.insert(QLatin1String(NM_SETTING_802_1X_PASSWORD_RAW_FLAGS), passwordRawFlags);
0160     map.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY), privateKey);
0161     map.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD), privateKeyPassword);
0162     map.insert(QLatin1String(NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS), privateKeyPasswordFlags);
0163     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY), phase2PrivateKey);
0164     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD), phase2PrivateKeyPassword);
0165     map.insert(QLatin1String(NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS), phase2PrivateKeyPasswordFlags);
0166     map.insert(QLatin1String(NM_SETTING_802_1X_PIN), pin);
0167     map.insert(QLatin1String(NM_SETTING_802_1X_PIN_FLAGS), pinFlags);
0168     map.insert(QLatin1String(NM_SETTING_802_1X_SYSTEM_CA_CERTS), systemCaCerts);
0169 
0170     NetworkManager::Security8021xSetting setting;
0171     setting.fromMap(map);
0172 
0173     QVariantMap map1 = setting.toMap();
0174     QVariantMap::const_iterator it = map.constBegin();
0175     while (it != map.constEnd()) {
0176         QCOMPARE(it.value(), map1.value(it.key()));
0177         ++it;
0178     }
0179 }
0180 
0181 QTEST_MAIN(Security8021xSettingTest)
0182 
0183 #include "moc_8021xsettingtest.cpp"