1
0
mirror of https://github.com/Yubico/yubico-pam.git synced 2024-12-01 15:24:12 +01:00

test an OK authentication

add a simple http server in bash that validates the OTP
This commit is contained in:
Klas Lindfors 2015-01-16 11:32:29 +01:00
parent 5191397b59
commit 286de92cd3
3 changed files with 57 additions and 4 deletions

1
tests/aux/authfile Normal file
View File

@ -0,0 +1 @@
foo:vvincredible

32
tests/aux/ykval.sh Executable file
View File

@ -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

View File

@ -30,6 +30,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <assert.h>
#include <security/pam_appl.h>
#include <security/pam_modutil.h>
@ -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;
}