From bcfee637af1c94e84e5c02ca50af96b122fbad8c Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Mon, 19 Jan 2015 10:12:55 +0100 Subject: [PATCH] add test for wrong otp for user --- tests/aux/ykval.pl | 1 + tests/pam_test.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/aux/ykval.pl b/tests/aux/ykval.pl index cbdac7c..f4aa33b 100755 --- a/tests/aux/ykval.pl +++ b/tests/aux/ykval.pl @@ -34,6 +34,7 @@ use warnings; my %otps = ( 'vvincredibletrerdegkkrkkneieultcjdghrejjbckh' => 'OK', + 'vvincrediblltrerdegkkrkkneieultcjdghrejjbckh' => 'OK', ); my $port = shift; diff --git a/tests/pam_test.c b/tests/pam_test.c index 0babfcd..27c0086 100644 --- a/tests/pam_test.c +++ b/tests/pam_test.c @@ -47,6 +47,7 @@ static struct data { {1, "foo", "vvincredibletrerdegkkrkkneieultcjdghrejjbckh"}, {2, "foo", "vvincredibletrerdegkkrkkneieultcjdghrejjbckh"}, {3, "bar", "vvincredibletrerdegkkrkkneieultcjdghrejjbckh"}, + {4, "foo", "vvincrediblltrerdegkkrkkneieultcjdghrejjbckh"}, }; static const char *err = "error"; @@ -151,13 +152,21 @@ static int test_fail_authenticate1(void) { return pam_sm_authenticate(3, 0, sizeof(cfg) / sizeof(char*), cfg); } +static int test_fail_authenticate2(void) { + char *cfg[] = { + "id=1", + "urllist=http://localhost:8889/wsapi/2/verify;http://localhost:8888/wsapi/2/verify", + "authfile=aux/authfile", + "debug" + }; + return pam_sm_authenticate(4, 0, sizeof(cfg) / sizeof(char*), cfg); +} + static pid_t run_mock(const char *port) { pid_t pid = fork(); if(pid == 0) { execlp("aux/ykval.pl", port, NULL); } - /* Give the "server" time to settle */ - sleep(1); return pid; } @@ -166,6 +175,9 @@ int main () { pid_t child = run_mock("8888"); pid_t child2 = run_mock("8889"); + /* Give the "server" time to settle */ + sleep(1); + if(test_authenticate1() != PAM_SUCCESS) { ret = 1; goto out; @@ -178,6 +190,10 @@ int main () { ret = 3; goto out; } + if(test_fail_authenticate2() != PAM_AUTH_ERR) { + ret = 4; + goto out; + } out: kill(child, 9);