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

add a test for wrong otp and small fixup to mock server

This commit is contained in:
Klas Lindfors 2015-01-19 10:37:51 +01:00
parent 9038130e88
commit 086bfbb3f7
2 changed files with 19 additions and 3 deletions

View File

@ -51,20 +51,21 @@ my $socket = new IO::Socket::INET (
while(1) { while(1) {
my $clientsocket = $socket->accept(); my $clientsocket = $socket->accept();
my $clientdata = <$clientsocket>; my $clientdata = <$clientsocket>;
my $ret = "status=MISSING_PARAMETER"; my $ret = "h=ZrU7UfjwazJVf5ay1P/oC3XCQlI=\n";
if($clientdata =~ m/nonce=([a-zA-Z0-9]+).*otp=([cbdefghijklnrtuv]+)/) { if($clientdata =~ m/nonce=([a-zA-Z0-9]+).*otp=([cbdefghijklnrtuv]+)/) {
my $nonce = $1; my $nonce = $1;
my $otp = $2; my $otp = $2;
if($otps{$otp}) { if($otps{$otp}) {
my $status = $otps{$otp}; my $status = $otps{$otp};
$ret = "h=ZrU7UfjwazJVf5ay1P/oC3XCQlI=\n";
$ret .= "nonce=$nonce\n"; $ret .= "nonce=$nonce\n";
$ret .= "otp=$otp\n"; $ret .= "otp=$otp\n";
$ret .= "status=$status"; $ret .= "status=$status";
} else { } else {
$ret = "status=BAD_OTP"; $ret .= "status=BAD_OTP";
} }
} else {
$ret .= "status=MISSING_PARAMETER";
} }
print $clientsocket "\n$ret\n"; print $clientsocket "\n$ret\n";
close $clientsocket; close $clientsocket;

View File

@ -46,6 +46,7 @@ static struct data {
{"foo", "vvincredibletrerdegkkrkkneieultcjdghrejjbckh"}, {"foo", "vvincredibletrerdegkkrkkneieultcjdghrejjbckh"},
{"bar", "vvincredibletrerdegkkrkkneieultcjdghrejjbckh"}, {"bar", "vvincredibletrerdegkkrkkneieultcjdghrejjbckh"},
{"foo", "vvincrediblltrerdegkkrkkneieultcjdghrejjbckh"}, {"foo", "vvincrediblltrerdegkkrkkneieultcjdghrejjbckh"},
{"foo", "vvincredibletrerdegkkrkkneieultcjdghrejjbckl"},
}; };
static const char *err = "error"; static const char *err = "error";
@ -154,6 +155,16 @@ static int test_fail_authenticate2(void) {
return pam_sm_authenticate(2, 0, sizeof(cfg) / sizeof(char*), cfg); return pam_sm_authenticate(2, 0, sizeof(cfg) / sizeof(char*), cfg);
} }
static int test_fail_authenticate3(void) {
char *cfg[] = {
"id=1",
"urllist=http://localhost:8889/wsapi/2/verify",
"authfile=aux/authfile",
"debug"
};
return pam_sm_authenticate(3, 0, sizeof(cfg) / sizeof(char*), cfg);
}
static pid_t run_mock(const char *port) { static pid_t run_mock(const char *port) {
pid_t pid = fork(); pid_t pid = fork();
if(pid == 0) { if(pid == 0) {
@ -186,6 +197,10 @@ int main () {
ret = 4; ret = 4;
goto out; goto out;
} }
if(test_fail_authenticate3() != PAM_AUTH_ERR) {
ret = 5;
goto out;
}
out: out:
kill(child, 9); kill(child, 9);