mirror of
https://github.com/Yubico/yubico-pam.git
synced 2025-02-20 21:54:16 +01:00
add test for check_user_token()
This commit is contained in:
parent
ba2775619f
commit
0b092d4d06
@ -32,6 +32,10 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
static void test_get_user_cfgfile_path(void) {
|
||||
@ -46,6 +50,34 @@ static void test_get_user_cfgfile_path(void) {
|
||||
free(file);
|
||||
}
|
||||
|
||||
static void test_check_user_token(void) {
|
||||
char file[] = "/tmp/pamtest.XXXXXX";
|
||||
int fd = mkstemp(file);
|
||||
FILE *handle;
|
||||
int ret;
|
||||
|
||||
assert(fd != -1);
|
||||
handle = fdopen(fd, "w");
|
||||
fprintf(handle, "foobar:hhhvhvhdhbid:hnhbhnhbhnhb:\n");
|
||||
fprintf(handle, "kaka:hdhrhbhjhvhu:hihbhdhrhbhj\n");
|
||||
fprintf(handle, "bar:hnhbhnhbhnhb\n");
|
||||
fclose(handle);
|
||||
|
||||
ret = check_user_token(file, "foobar", "hhhvhvhdhbid", 1);
|
||||
assert(ret == 1);
|
||||
ret = check_user_token(file, "foobar", "hnhbhnhbhnhb", 1);
|
||||
assert(ret == 1);
|
||||
ret = check_user_token(file, "foobar", "hnhbhnhbhnhc", 1);
|
||||
assert(ret == -1);
|
||||
ret = check_user_token(file, "kaka", "hihbhdhrhbhj", 1);
|
||||
assert(ret == 1);
|
||||
ret = check_user_token(file, "bar", "hnhbhnhbhnhb", 1);
|
||||
assert(ret == 1);
|
||||
ret = check_user_token(file, "foo", "hdhrhbhjhvhu", 1);
|
||||
assert(ret == -2);
|
||||
remove(file);
|
||||
}
|
||||
|
||||
#if HAVE_CR
|
||||
|
||||
#define CHALLENGE1 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
@ -95,6 +127,7 @@ static void test_load_chalresp_state(void) {
|
||||
|
||||
int main (void) {
|
||||
test_get_user_cfgfile_path();
|
||||
test_check_user_token();
|
||||
#if HAVE_CR
|
||||
test_load_chalresp_state();
|
||||
#endif /* HAVE_CR */
|
||||
|
Loading…
x
Reference in New Issue
Block a user