[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH 5/6] unit-tests: add two example test cases
From: Bartosz Golaszewski <bartekgola () gmail ! com>
Date: 2014-04-15 21:07:17
Message-ID: 1397603199-12864-6-git-send-email-bartekgola () gmail ! com
[Download RAW message or body]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
---
libbb/obscure.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/libbb/obscure.c b/libbb/obscure.c
index 9ecc1f6..c38b652 100644
--- a/libbb/obscure.c
+++ b/libbb/obscure.c
@@ -182,3 +182,43 @@ int FAST_FUNC obscure(const char *old, const char *newval, const struct passwd *
}
return 0;
}
+
+#if ENABLE_UNIT_TEST
+
+#include "bbunit.h"
+
+/* Test obscure_msg() instead of obscure() in order not to print anything. */
+
+static const struct passwd pw = {
+ .pw_name = (char *)"johndoe",
+ .pw_gecos = (char *)"John Doe",
+};
+
+BBUNIT_DEFINE_TEST(obscure_weak_pass)
+{
+ /* Empty password */
+ BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "", &pw));
+ /* Pure numbers */
+ BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "23577315", &pw));
+ /* Similar to pw_name */
+ BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "johndoe123%", &pw));
+ /* Similar to pw_gecos, reversed */
+ BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "eoD nhoJ^44@", &pw));
+ /* Similar to the old password */
+ BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "d4#21?'S", &pw));
+ /* adjacent letters */
+ BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "qwerty123", &pw));
+ /* Many similar chars */
+ BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "^33Daaaaaa1", &pw));
+
+ BBUNIT_ENDTEST;
+}
+
+BBUNIT_DEFINE_TEST(obscure_strong_pass)
+{
+ BBUNIT_ASSERT_NULL(obscure_msg("Rt4##2&:'|", "}(^#rrSX3S*22", &pw));
+
+ BBUNIT_ENDTEST;
+}
+
+#endif /* ENABLE_UNIT_TEST */
--
1.8.4.5
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic