18
#include "TestPasswordHealth.h"
20
#include "core/PasswordHealth.h"
24
QTEST_GUILESS_MAIN(TestPasswordHealth)
26
void TestPasswordHealth::initTestCase()
30
void TestPasswordHealth::testNoDb()
32
const auto empty = PasswordHealth("");
33
QCOMPARE(empty.score(), 0);
34
QCOMPARE(empty.entropy(), 0.0);
35
QCOMPARE(empty.quality(), PasswordHealth::Quality::Bad);
36
QVERIFY(!empty.scoreReason().isEmpty());
37
QVERIFY(!empty.scoreDetails().isEmpty());
39
const auto poor = PasswordHealth("secret");
40
QCOMPARE(poor.score(), 6);
41
QCOMPARE(int(poor.entropy()), 6);
42
QCOMPARE(poor.quality(), PasswordHealth::Quality::Poor);
43
QVERIFY(!poor.scoreReason().isEmpty());
44
QVERIFY(!poor.scoreDetails().isEmpty());
46
const auto weak = PasswordHealth("Yohb2ChR4");
47
QCOMPARE(weak.score(), 47);
48
QCOMPARE(int(weak.entropy()), 47);
49
QCOMPARE(weak.quality(), PasswordHealth::Quality::Weak);
50
QVERIFY(!weak.scoreReason().isEmpty());
51
QVERIFY(!weak.scoreDetails().isEmpty());
53
const auto good = PasswordHealth("MIhIN9UKrgtPL2hp");
54
QCOMPARE(good.score(), 78);
55
QCOMPARE(int(good.entropy()), 78);
56
QCOMPARE(good.quality(), PasswordHealth::Quality::Good);
57
QVERIFY(good.scoreReason().isEmpty());
58
QVERIFY(good.scoreDetails().isEmpty());
60
const auto excellent = PasswordHealth("prompter-ream-oversleep-step-extortion-quarrel-reflected-prefix");
61
QCOMPARE(excellent.score(), 164);
62
QCOMPARE(int(excellent.entropy()), 164);
63
QCOMPARE(excellent.quality(), PasswordHealth::Quality::Excellent);
64
QVERIFY(excellent.scoreReason().isEmpty());
65
QVERIFY(excellent.scoreDetails().isEmpty());