server/src/util/password.test.c

38 lines
1.3 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)) {
int wf = bcrypt_workfactor;
bcrypt_workfactor = 4;
hash = password_hash("password", PASSWORD_BCRYPT);
2018-09-26 18:43:30 +02:00
CuAssertPtrNotNull(tc, hash);
CuAssertIntEquals(tc, '$', hash[0]);
CuAssertIntEquals(tc, '2', hash[1]);
CuAssertIntEquals(tc, '$', hash[3]);
CuAssertIntEquals(tc, '0', hash[4]);
CuAssertIntEquals(tc, '4', hash[5]);
CuAssertIntEquals(tc, '$', hash[6]);
2018-09-26 18:43:30 +02:00
CuAssertIntEquals(tc, VERIFY_OK, password_verify(hash, "password"));
CuAssertIntEquals(tc, VERIFY_FAIL, password_verify(hash, "arseword"));
bcrypt_workfactor = wf;
2018-09-26 18:43:30 +02:00
}
2016-02-25 10:46:46 +01:00
if (password_is_implemented(PASSWORD_PLAINTEXT)) {
hash = password_hash("password", PASSWORD_PLAINTEXT);
2016-02-25 10:46:46 +01:00
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;
}