server/src/util/password.test.c

26 lines
789 B
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) {
const char *hash, *expect;
2016-07-13 19:10:22 +02:00
expect = "password";
2016-02-25 10:46:46 +01:00
if (password_is_implemented(PASSWORD_PLAINTEXT)) {
hash = password_encode("password", PASSWORD_PLAINTEXT);
CuAssertPtrNotNull(tc, hash);
CuAssertStrEquals(tc, hash, expect);
CuAssertIntEquals(tc, VERIFY_OK, password_verify(expect, "password"));
CuAssertIntEquals(tc, VERIFY_FAIL, password_verify(expect, "arseword"));
} else {
CuAssertIntEquals(tc, VERIFY_UNKNOWN, password_verify(expect, "password"));
}
}
CuSuite *get_password_suite(void) {
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_passwords);
return suite;
}