Repeater, room server, sensor: passwords can no longer be guessed over the air at full speed, and a replayed login no longer floods a reply
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
de92ca9ba2
commit
dbdae14566
8 files changed
+123
No files matched your search
@@ -0,0 +1,47 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "helpers/LoginGuard.h"
|
||||
|
||||
static const uint32_t WINDOW_MS = LOGIN_FAIL_SECS * 1000UL;
|
||||
|
||||
TEST(LoginGuard, LocksAfterTheCap) {
|
||||
LoginGuard g;
|
||||
for (int i = 0; i < LOGIN_FAIL_MAX; i++) {
|
||||
EXPECT_FALSE(g.locked(1000 + i));
|
||||
g.failed(1000 + i);
|
||||
}
|
||||
EXPECT_TRUE(g.locked(1000 + LOGIN_FAIL_MAX));
|
||||
}
|
||||
|
||||
TEST(LoginGuard, UnlocksWhenTheWindowEnds) {
|
||||
LoginGuard g;
|
||||
for (int i = 0; i < LOGIN_FAIL_MAX; i++) g.failed(1000);
|
||||
EXPECT_TRUE(g.locked(1000 + WINDOW_MS - 1));
|
||||
EXPECT_FALSE(g.locked(1000 + WINDOW_MS));
|
||||
}
|
||||
|
||||
TEST(LoginGuard, FailuresInAnOldWindowDoNotCount) {
|
||||
LoginGuard g;
|
||||
for (int i = 0; i < LOGIN_FAIL_MAX - 1; i++) g.failed(1000);
|
||||
g.failed(1000 + WINDOW_MS); // a new window: one failure, not LOGIN_FAIL_MAX
|
||||
EXPECT_FALSE(g.locked(1000 + WINDOW_MS + 1));
|
||||
}
|
||||
|
||||
TEST(LoginGuard, LockedFailuresDoNotExtendTheWindow) {
|
||||
LoginGuard g;
|
||||
for (int i = 0; i < LOGIN_FAIL_MAX; i++) g.failed(1000);
|
||||
for (uint32_t t = 1000; t < 1000 + WINDOW_MS; t += 1000) g.failed(t); // the caller does not, but still
|
||||
EXPECT_FALSE(g.locked(1000 + WINDOW_MS));
|
||||
}
|
||||
|
||||
TEST(LoginGuard, SurvivesTheMillisWrap) {
|
||||
LoginGuard g;
|
||||
const uint32_t start = 0xFFFFFFFFu - 1000;
|
||||
for (int i = 0; i < LOGIN_FAIL_MAX; i++) g.failed(start);
|
||||
EXPECT_TRUE(g.locked(start + 2000)); // wrapped past 0
|
||||
EXPECT_FALSE(g.locked(start + WINDOW_MS));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in new issue
Block a user