From d7b895b45d6b83001e5eb7220aae55324f56ca64 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 17 Aug 2020 14:05:03 +0200 Subject: [PATCH] [users] Extend tests - password requirements can disallow weak passwords - start checking for signals on password changes --- src/modules/users/Tests.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/modules/users/Tests.cpp b/src/modules/users/Tests.cpp index 75abd46c6..914821f63 100644 --- a/src/modules/users/Tests.cpp +++ b/src/modules/users/Tests.cpp @@ -206,6 +206,35 @@ UserTests::testUserPassword() QCOMPARE( c.userPasswordValidity(), int( Config::PasswordValidity::Invalid ) ); c.setUserPasswordSecondary( "bogus" ); QCOMPARE( c.userPasswordValidity(), int( Config::PasswordValidity::Weak ) ); + + QVERIFY( !c.requireStrongPasswords() ); + c.setRequireStrongPasswords( true ); + QVERIFY( c.requireStrongPasswords() ); + // Now changed requirements make the password invalid + QCOMPARE( c.userPassword(), "bogus" ); + QCOMPARE( c.userPasswordValidity(), int( Config::PasswordValidity::Invalid ) ); + } + + { + Config c; + QVERIFY( c.userPassword().isEmpty() ); + QCOMPARE( c.userPasswordValidity(), Config::PasswordValidity::Valid ); + + QSignalSpy spy_pwChanged( &c, &Config::userPasswordChanged ); + QSignalSpy spy_pwSecondaryChanged( &c, &Config::userPasswordSecondaryChanged ); + QSignalSpy spy_pwStatusChanged( &c, &Config::userPasswordStatusChanged ); + + c.setUserPassword( "bogus" ); + c.setUserPassword( "bogus" ); + QCOMPARE( spy_pwChanged.count(), 1 ); + QCOMPARE( spy_pwStatusChanged.count(), 1 ); + QCOMPARE( c.userPasswordValidity(), Config::PasswordValidity::Invalid ); + c.setUserPassword( "sugob" ); + c.setUserPasswordSecondary( "sugob" ); + QCOMPARE( spy_pwChanged.count(), 2 ); + QCOMPARE( spy_pwSecondaryChanged.count(), 1 ); + QCOMPARE( spy_pwStatusChanged.count(), 3 ); + QCOMPARE( c.userPasswordValidity(), Config::PasswordValidity::Valid ); } }