diff --git a/tests/aux/authfile b/tests/aux/authfile new file mode 100644 index 0000000..bef21e5 --- /dev/null +++ b/tests/aux/authfile @@ -0,0 +1 @@ +foo:vvincredible diff --git a/tests/aux/ykval.sh b/tests/aux/ykval.sh new file mode 100755 index 0000000..c0668b4 --- /dev/null +++ b/tests/aux/ykval.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +out=`mktemp /tmp/ykval_mock.XXXXXX` +rm -f $out +mkfifo $out +trap "rm -f $out" EXIT +while true +do + cat $out | nc -l 8888 > >( + while read line + do + line=$(echo "$line" | tr -d '[\r\n]') + + if echo "$line" | grep -qE '^GET /'; then + REQUEST=$(echo "$line" | cut -d ' ' -f2) + elif [ "x$line" = x ]; then + echo $REQUEST + nonce=`echo "$REQUEST" | awk -F\& '{print $2}'` + otp=`echo "$REQUEST" | awk -F\& '{print $3}'` + if [ x$otp = "xotp=vvincredibletrerdegkkrkkneieultcjdghrejjbckh" ]; then + status="status=OK" + else + status="status=BAD_OTP" + fi + echo "h=ZrU7UfjwazJVf5ay1P/oC3XCQlI= +$nonce +$otp +$status" > $out + fi + done + ) +done diff --git a/tests/pam_test.c b/tests/pam_test.c index fb47c59..3436469 100644 --- a/tests/pam_test.c +++ b/tests/pam_test.c @@ -30,6 +30,11 @@ #include #include +#include +#include + +#include + #include #include @@ -40,10 +45,11 @@ static const char *otp = "vvincredibletrerdegkkrkkneieultcjdghrejjbckh"; void test_authenticate1(void) { char *cfg[] = { "id=1", - // "url=http://localhost:8888/wsapi/2/verify", - "debug" + "url=http://localhost:8888/wsapi/2/verify?id=%d&otp=%s", + "authfile=aux/authfile", + "debug", }; - pam_sm_authenticate(0, 0, 2, cfg); + assert(pam_sm_authenticate(0, 0, 4, cfg) == PAM_SUCCESS); } const char * pam_strerror(pam_handle_t *pamh, int errnum) { @@ -105,8 +111,22 @@ int pam_set_item(pam_handle_t *pamh, int item_type, const void *item) { return PAM_SUCCESS; } +pid_t run_mock(void) { + pid_t pid = fork(); + if(pid == 0) { + execvp("aux/ykval.sh", NULL); + exit(0); + } + sleep(1); + return pid; +} + +int main () { + pid_t child = run_mock(); -int main (void) { test_authenticate1(); + + kill(child, 9); + printf("killed %d\n", child); return 0; }