2016-02-06 14:52:32 +01:00
|
|
|
#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>
|
2016-02-06 14:52:32 +01:00
|
|
|
|
|
|
|
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)) {
|
2018-09-26 20:08:38 +02:00
|
|
|
int wf = bcrypt_workfactor;
|
2018-09-26 19:05:49 +02:00
|
|
|
bcrypt_workfactor = 4;
|
2018-09-26 21:06:56 +02:00
|
|
|
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]);
|
2018-09-26 19:05:49 +02:00
|
|
|
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"));
|
2018-09-26 20:08:38 +02:00
|
|
|
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)) {
|
2018-09-26 21:06:56 +02:00
|
|
|
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
|
|
|
}
|
2016-02-06 14:52:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_password_suite(void) {
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_passwords);
|
|
|
|
return suite;
|
|
|
|
}
|