server/src/util/password.test.c

32 lines
1.1 KiB
C
Raw Normal View History

#include <platform.h>
#include "password.h"
2016-02-13 07:50:06 +01:00
#include <CuTest.h>
2016-02-13 13:56:49 +01:00
#include <string.h>
static void test_passwords(CuTest *tc) {
2018-09-26 18:43:30 +02:00
const char *hash;
2016-07-13 19:10:22 +02:00
2018-09-26 18:43:30 +02:00
if (password_is_implemented(PASSWORD_BCRYPT)) {
hash = password_encode("password", PASSWORD_BCRYPT);
CuAssertPtrNotNull(tc, hash);
CuAssertIntEquals(tc, '$', hash[0]);
CuAssertIntEquals(tc, '2', hash[1]);
CuAssertIntEquals(tc, '$', hash[3]);
CuAssertIntEquals(tc, VERIFY_OK, password_verify(hash, "password"));
CuAssertIntEquals(tc, VERIFY_FAIL, password_verify(hash, "arseword"));
}
2016-02-25 10:46:46 +01:00
if (password_is_implemented(PASSWORD_PLAINTEXT)) {
hash = password_encode("password", PASSWORD_PLAINTEXT);
CuAssertPtrNotNull(tc, hash);
2018-09-26 18:43:30 +02:00
CuAssertStrEquals(tc, hash, "password");
CuAssertIntEquals(tc, VERIFY_OK, password_verify(hash, "password"));
CuAssertIntEquals(tc, VERIFY_FAIL, password_verify(hash, "arseword"));
2016-02-25 10:46:46 +01:00
}
}
CuSuite *get_password_suite(void) {
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_passwords);
return suite;
}