File indexing completed on 2024-12-01 04:35:28
0001 /* 0002 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "ruqolaserverconfigtest.h" 0008 #include "ruqola_autotest_helper.h" 0009 #include "ruqolaserverconfig.h" 0010 0011 QTEST_GUILESS_MAIN(RuqolaServerConfigTest) 0012 0013 RuqolaServerConfigTest::RuqolaServerConfigTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void RuqolaServerConfigTest::shouldHaveDefaultValues() 0019 { 0020 RuqolaServerConfig config; 0021 QVERIFY(config.jitsiMeetPrefix().isEmpty()); 0022 QVERIFY(config.jitsiMeetUrl().isEmpty()); 0023 QVERIFY(config.uniqueId().isEmpty()); 0024 QVERIFY(config.fileUploadStorageType().isEmpty()); 0025 QVERIFY(config.siteName().isEmpty()); 0026 QVERIFY(config.siteUrl().isEmpty()); 0027 QVERIFY(!config.needAdaptNewSubscriptionRC60()); 0028 QCOMPARE(config.blockEditingMessageInMinutes(), 5); 0029 QCOMPARE(config.blockDeletingMessageInMinutes(), 5); 0030 QCOMPARE(config.ruqolaOauthTypes(), AuthenticationManager::AuthMethodType::Unknown); 0031 QCOMPARE(config.serverAuthMethodTypes(), AuthenticationManager::AuthMethodType::Unknown); 0032 QVERIFY(config.autoTranslateGoogleKey().isEmpty()); 0033 QCOMPARE(config.fileMaxFileSize(), -1); 0034 QVERIFY(config.logoUrl().isEmpty()); 0035 QVERIFY(config.faviconUrl().isEmpty()); 0036 QCOMPARE(config.loginExpiration(), -1); 0037 QVERIFY(config.userNameValidation().isEmpty()); 0038 QVERIFY(config.channelNameValidation().isEmpty()); 0039 QCOMPARE(config.messageMaximumAllowedSize(), -1); 0040 QVERIFY(!config.messageAllowConvertLongMessagesToAttachment()); 0041 QVERIFY(!config.useRealName()); 0042 QVERIFY(!config.hasEnterpriseSupport()); 0043 QVERIFY(config.accountsAllowInvisibleStatusOption()); 0044 QVERIFY(config.userDataDownloadEnabled()); 0045 QVERIFY(!config.deviceManagementEnableLoginEmails()); 0046 QVERIFY(!config.deviceManagementAllowLoginEmailpreference()); 0047 QCOMPARE(config.messageGroupingPeriod(), -1); 0048 QCOMPARE(config.directMessageMaximumUser(), -1); 0049 QCOMPARE(config.messageQuoteChainLimit(), -1); 0050 QVERIFY(!config.allowCustomStatusMessage()); 0051 0052 QVERIFY(config.mediaBlackList().isEmpty()); 0053 QVERIFY(config.mediaWhiteList().isEmpty()); 0054 0055 RuqolaServerConfig::ConfigWithDefaultValue defaultValue; 0056 QVERIFY(defaultValue.url.isEmpty()); 0057 QVERIFY(defaultValue.defaultUrl.isEmpty()); 0058 QVERIFY(defaultValue.isEmpty()); 0059 QVERIFY(!config.previewEmbed()); 0060 0061 QCOMPARE(config.embedCacheExpirationDays(), 30); 0062 0063 defaultValue.url = QStringLiteral("dd"); 0064 QVERIFY(defaultValue.isEmpty()); 0065 0066 defaultValue.defaultUrl = QStringLiteral("dd1"); 0067 QVERIFY(!defaultValue.isEmpty()); 0068 } 0069 0070 void RuqolaServerConfigTest::shouldAssignValues() 0071 { 0072 const QString jitsimeetprefix = QStringLiteral("test 1"); 0073 const QString jitsimeeturl = QStringLiteral("test 2"); 0074 const QString uniqueId = QStringLiteral("test 3"); 0075 const QString filestoragetype = QStringLiteral("test 4"); 0076 const QString googleKey = QStringLiteral("Google12"); 0077 const int minutes = 12; 0078 const int minutesDeletingMessage = 15; 0079 const QString siteName = QStringLiteral("sitename"); 0080 const QString siteUrl = QStringLiteral("siteurl"); 0081 0082 RuqolaServerConfig::ConfigWithDefaultValue logoUrl; 0083 logoUrl.url = QStringLiteral("path/to/logo"); 0084 RuqolaServerConfig::ConfigWithDefaultValue faviconUrl; 0085 faviconUrl.url = QStringLiteral("path/to/favicon"); 0086 0087 RuqolaServerConfig config; 0088 config.setJitsiMeetPrefix(jitsimeetprefix); 0089 config.setJitsiMeetUrl(jitsimeeturl); 0090 config.setUniqueId(uniqueId); 0091 config.setFileUploadStorageType(filestoragetype); 0092 config.setBlockEditingMessageInMinutes(minutes); 0093 config.setBlockDeletingMessageInMinutes(minutesDeletingMessage); 0094 config.setSiteName(siteName); 0095 config.setSiteUrl(siteUrl); 0096 config.setAutoTranslateGoogleKey(googleKey); 0097 config.setLogoUrl(logoUrl); 0098 config.setFaviconUrl(faviconUrl); 0099 0100 quint64 uploadFileMax = 222222; 0101 0102 config.setFileMaxFileSize(uploadFileMax); 0103 0104 QCOMPARE(config.jitsiMeetPrefix(), jitsimeetprefix); 0105 QCOMPARE(config.jitsiMeetUrl(), jitsimeeturl); 0106 QCOMPARE(config.uniqueId(), uniqueId); 0107 QCOMPARE(config.fileUploadStorageType(), filestoragetype); 0108 QCOMPARE(config.blockEditingMessageInMinutes(), minutes); 0109 QCOMPARE(config.blockDeletingMessageInMinutes(), minutesDeletingMessage); 0110 QCOMPARE(config.fileMaxFileSize(), uploadFileMax); 0111 0112 QCOMPARE(config.siteUrl(), siteUrl); 0113 QCOMPARE(config.siteName(), siteName); 0114 0115 QCOMPARE(config.autoTranslateGoogleKey(), googleKey); 0116 0117 QCOMPARE(config.logoUrl(), logoUrl); 0118 QCOMPARE(config.faviconUrl(), faviconUrl); 0119 0120 QCOMPARE(config.serverConfigFeatureTypes(), RuqolaServerConfig::ServerConfigFeatureType::None); 0121 } 0122 0123 void RuqolaServerConfigTest::shouldEnabledRc60_data() 0124 { 0125 QTest::addColumn<QString>("serverVersion"); 0126 QTest::addColumn<bool>("needRc60"); 0127 QTest::newRow("0.1.0") << QStringLiteral("0.1.0") << false; 0128 QTest::newRow("0.60.0") << QStringLiteral("0.60.0") << true; 0129 QTest::newRow("0.70.0") << QStringLiteral("0.70.0") << true; 0130 QTest::newRow("invalid") << QStringLiteral("foo") << false; 0131 QTest::newRow("invalid-2") << QStringLiteral("0.6foo") << false; 0132 QTest::newRow("1.0.0-develop") << QStringLiteral("1.0.0") << true; 0133 QTest::newRow("4.0") << QStringLiteral("4.0") << true; 0134 } 0135 0136 void RuqolaServerConfigTest::shouldEnabledRc60() 0137 { 0138 QFETCH(QString, serverVersion); 0139 QFETCH(bool, needRc60); 0140 RuqolaServerConfig config; 0141 config.setServerVersion(serverVersion); 0142 // qDebug() << " config " << config; 0143 QCOMPARE(config.needAdaptNewSubscriptionRC60(), needRc60); 0144 } 0145 0146 void RuqolaServerConfigTest::shouldVerifyOauthType_data() 0147 { 0148 QTest::addColumn<QStringList>("oauthlist"); 0149 QTest::addColumn<AuthenticationManager::AuthMethodTypes>("types"); 0150 0151 { 0152 QStringList lst; 0153 // By default ruqola has password support 0154 AuthenticationManager::AuthMethodTypes types; 0155 types |= AuthenticationManager::AuthMethodType::Unknown; 0156 QTest::newRow("empty") << lst << types; 0157 } 0158 { 0159 const QStringList lst = {QStringLiteral("Accounts_OAuth_FaceBook")}; 0160 AuthenticationManager::AuthMethodTypes types; 0161 types |= AuthenticationManager::AuthMethodType::FaceBook; 0162 QTest::newRow("fb") << lst << types; 0163 } 0164 { 0165 const QStringList lst = {QStringLiteral("Accounts_OAuth_Twitter")}; 0166 AuthenticationManager::AuthMethodTypes types; 0167 types |= AuthenticationManager::AuthMethodType::Twitter; 0168 QTest::newRow("tw") << lst << types; 0169 } 0170 { 0171 const QStringList lst = {QStringLiteral("Accounts_OAuth_Google")}; 0172 AuthenticationManager::AuthMethodTypes types; 0173 types |= AuthenticationManager::AuthMethodType::Google; 0174 QTest::newRow("go") << lst << types; 0175 } 0176 { 0177 const QStringList lst = {QStringLiteral("Accounts_OAuth_Google"), QStringLiteral("Accounts_OAuth_Twitter"), QStringLiteral("Accounts_OAuth_FaceBook")}; 0178 AuthenticationManager::AuthMethodTypes types; 0179 types |= AuthenticationManager::AuthMethodType::Google; 0180 types |= AuthenticationManager::AuthMethodType::FaceBook; 0181 types |= AuthenticationManager::AuthMethodType::Twitter; 0182 QTest::newRow("go-tw-fb") << lst << types; 0183 } 0184 { 0185 const QStringList lst = {QStringLiteral("Accounts_OAuth_Blable")}; 0186 AuthenticationManager::AuthMethodTypes types; 0187 types |= AuthenticationManager::AuthMethodType::Unknown; 0188 QTest::newRow("unknown") << lst << types; 0189 } 0190 { 0191 const QStringList lst = {QStringLiteral("Accounts_OAuth_Blable"), QStringLiteral("Accounts_OAuth_Twitter")}; 0192 AuthenticationManager::AuthMethodTypes types; 0193 types |= AuthenticationManager::AuthMethodType::Twitter; 0194 QTest::newRow("unknown-2") << lst << types; 0195 } 0196 } 0197 0198 void RuqolaServerConfigTest::shouldVerifyOauthType() 0199 { 0200 QFETCH(QStringList, oauthlist); 0201 QFETCH(AuthenticationManager::AuthMethodTypes, types); 0202 RuqolaServerConfig config; 0203 for (const QString &t : oauthlist) { 0204 config.addOauthService(t); 0205 } 0206 QCOMPARE(config.serverAuthMethodTypes(), types); 0207 } 0208 0209 void RuqolaServerConfigTest::shouldVerifyThatServerSupportService() 0210 { 0211 RuqolaServerConfig config; 0212 QVERIFY(!config.serverHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::Twitter)); 0213 config.addOauthService(QStringLiteral("Accounts_OAuth_Twitter")); 0214 QVERIFY(config.serverHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::Twitter)); 0215 0216 QVERIFY(!config.serverHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::FaceBook)); 0217 config.addOauthService(QStringLiteral("Accounts_OAuth_Google")); 0218 QVERIFY(config.serverHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::Google)); 0219 0220 config.addOauthService(QStringLiteral("Accounts_OAuth_FaceBook")); 0221 QVERIFY(config.serverHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::FaceBook)); 0222 } 0223 0224 void RuqolaServerConfigTest::shouldAddRuqolaAuthenticationSupport() 0225 { 0226 RuqolaServerConfig config; 0227 QVERIFY(!config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::Twitter)); 0228 config.addRuqolaAuthenticationSupport(AuthenticationManager::AuthMethodType::Twitter); 0229 QVERIFY(config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::Twitter)); 0230 0231 QVERIFY(!config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::FaceBook)); 0232 config.addRuqolaAuthenticationSupport(AuthenticationManager::AuthMethodType::FaceBook); 0233 QVERIFY(config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::FaceBook)); 0234 0235 QVERIFY(!config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::Google)); 0236 config.addRuqolaAuthenticationSupport(AuthenticationManager::AuthMethodType::Google); 0237 QVERIFY(config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::Google)); 0238 0239 QVERIFY(!config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::GitHub)); 0240 config.addRuqolaAuthenticationSupport(AuthenticationManager::AuthMethodType::GitHub); 0241 QVERIFY(config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::GitHub)); 0242 0243 QVERIFY(!config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::GitLab)); 0244 config.addRuqolaAuthenticationSupport(AuthenticationManager::AuthMethodType::GitLab); 0245 QVERIFY(config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::GitLab)); 0246 0247 QVERIFY(!config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::Linkedin)); 0248 config.addRuqolaAuthenticationSupport(AuthenticationManager::AuthMethodType::Linkedin); 0249 QVERIFY(config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::Linkedin)); 0250 0251 QVERIFY(!config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::Apple)); 0252 config.addRuqolaAuthenticationSupport(AuthenticationManager::AuthMethodType::Apple); 0253 QVERIFY(config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::Apple)); 0254 0255 QVERIFY(!config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::NextCloud)); 0256 config.addRuqolaAuthenticationSupport(AuthenticationManager::AuthMethodType::NextCloud); 0257 QVERIFY(config.ruqolaHasSupportForAuthMethodType(AuthenticationManager::AuthMethodType::NextCloud)); 0258 } 0259 0260 void RuqolaServerConfigTest::shouldTestVersion_data() 0261 { 0262 QTest::addColumn<QString>("serverVersion"); 0263 QTest::addColumn<int>("major"); 0264 QTest::addColumn<int>("minor"); 0265 QTest::addColumn<int>("patch"); 0266 QTest::addColumn<bool>("hasCorrectVersion"); 0267 QTest::newRow("0.60.0") << QStringLiteral("0.60.0") << 0 << 60 << 0 << true; 0268 QTest::newRow("0.59.0-incorrect") << QStringLiteral("0.59.0") << 0 << 60 << 0 << false; 0269 QTest::newRow("0.60.0-supperior") << QStringLiteral("0.61.0") << 0 << 60 << 0 << true; 0270 QTest::newRow("0.60.0-supperior-2") << QStringLiteral("0.60.1") << 0 << 60 << 0 << true; 0271 QTest::newRow("1.0.0-develop") << QStringLiteral("1.0.0-develop") << 0 << 60 << 0 << true; 0272 QTest::newRow("4.0") << QStringLiteral("4.0") << 4 << 0 << 0 << true; 0273 } 0274 0275 void RuqolaServerConfigTest::shouldTestVersion() 0276 { 0277 QFETCH(QString, serverVersion); 0278 QFETCH(int, major); 0279 QFETCH(int, minor); 0280 QFETCH(int, patch); 0281 QFETCH(bool, hasCorrectVersion); 0282 0283 RuqolaServerConfig config; 0284 config.setServerVersion(serverVersion); 0285 QCOMPARE(config.hasAtLeastVersion(major, minor, patch), hasCorrectVersion); 0286 } 0287 0288 void RuqolaServerConfigTest::shouldSerializeConfig_data() 0289 { 0290 QTest::addColumn<QString>("name"); 0291 QTest::addColumn<AuthenticationManager::AuthMethodTypes>("authentications"); 0292 0293 { 0294 AuthenticationManager::AuthMethodTypes type = AuthenticationManager::AuthMethodType::Unknown; 0295 QTest::newRow("empty") << QStringLiteral("empty.json") << type; 0296 } 0297 { 0298 AuthenticationManager::AuthMethodTypes type = AuthenticationManager::AuthMethodType::Password; 0299 QTest::newRow("test1") << QStringLiteral("test1.json") << type; 0300 } 0301 { 0302 AuthenticationManager::AuthMethodTypes type = AuthenticationManager::AuthMethodType::GitHub; 0303 QTest::newRow("onlygithub") << QStringLiteral("onlygithub.json") << type; 0304 } 0305 { 0306 AuthenticationManager::AuthMethodTypes type = AuthenticationManager::AuthMethodType::GitHub; 0307 type |= AuthenticationManager::AuthMethodType::GitLab; 0308 QTest::newRow("github-gitlab") << QStringLiteral("github-gitlab.json") << type; 0309 } 0310 { 0311 AuthenticationManager::AuthMethodTypes type = AuthenticationManager::AuthMethodType::GitHub; 0312 type |= AuthenticationManager::AuthMethodType::GitLab; 0313 type |= AuthenticationManager::AuthMethodType::Password; 0314 QTest::newRow("github-gitlab-password") << QStringLiteral("github-gitlab-password.json") << type; 0315 } 0316 } 0317 0318 void RuqolaServerConfigTest::shouldSerializeConfig() 0319 { 0320 QFETCH(QString, name); 0321 QFETCH(AuthenticationManager::AuthMethodTypes, authentications); 0322 0323 const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/serverconfig/%1").arg(name); 0324 const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile); 0325 0326 RuqolaServerConfig config; 0327 config.parsePublicSettings(obj, false); 0328 0329 const QByteArray ba = config.serialize(false); 0330 0331 const QJsonDocument doc = QJsonDocument::fromJson(ba); 0332 const QJsonObject newObj = doc.object(); 0333 0334 RuqolaServerConfig newConfig; 0335 newConfig.deserialize(newObj); 0336 0337 bool compare = (config == newConfig); 0338 if (!compare) { 0339 qDebug() << "config " << config; 0340 qDebug() << "newConfig " << newConfig; 0341 } 0342 QCOMPARE(config.serverAuthMethodTypes(), authentications); 0343 QVERIFY(compare); 0344 } 0345 0346 #include "moc_ruqolaserverconfigtest.cpp"