Skip to content

Commit

Permalink
add tests for empty OTP validation
Browse files Browse the repository at this point in the history
also fix around so ldap case checks with length of the authorized token,
not the length of the passed in id.
  • Loading branch information
klali committed Jun 13, 2016
1 parent fee0bcc commit 4fb0be3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pam_yubico.c
Expand Up @@ -357,7 +357,7 @@ authorize_user_token_ldap (struct cfg *cfg,
/* Only values containing this prefix are considered. */
if ((!cfg->yubi_attr_prefix || !strncmp (cfg->yubi_attr_prefix, vals[i]->bv_val, yubi_attr_prefix_len)))
{
if(!strncmp (token_id, vals[i]->bv_val + yubi_attr_prefix_len, strlen (token_id)))
if(!strncmp (token_id, vals[i]->bv_val + yubi_attr_prefix_len, strlen (vals[i]->bv_val + yubi_attr_prefix_len)))
{
DBG (("Token Found :: %s", vals[i]->bv_val));
retval = 1;
Expand Down
46 changes: 46 additions & 0 deletions tests/pam_test.c
Expand Up @@ -64,6 +64,8 @@ static struct data {
{"foo", "vvincrediblltrerdegkkrkkneieultcjdghrejjbckh"},
{"foo", "vvincredibletrerdegkkrkkneieultcjdghrejjbckl"},
{"test", "ccccccbchvthlivuitriujjifivbvtrjkjfirllluurj"},
{"foo", ""},
{"bar", ""},
};


Expand Down Expand Up @@ -194,6 +196,26 @@ static int test_authenticate3(void) {
return pam_sm_authenticate(4, 0, sizeof(cfg) / sizeof(char*), cfg);
}

static int test_authenticate4(void) {
const char *cfg[] = {
"id=1",
"urllist=http://localhost:"YKVAL_PORT1"/wsapi/2/verify;http://localhost:"YKVAL_PORT2"/wsapi/2/verify",
"authfile="AUTHFILE,
"debug",
};
return pam_sm_authenticate(5, 0, sizeof(cfg) / sizeof(char*), cfg);
}

static int test_authenticate5(void) {
const char *cfg[] = {
"id=1",
"urllist=http://localhost:"YKVAL_PORT1"/wsapi/2/verify;http://localhost:"YKVAL_PORT2"/wsapi/2/verify",
"authfile="AUTHFILE,
"debug",
};
return pam_sm_authenticate(6, 0, sizeof(cfg) / sizeof(char*), cfg);
}

static int test_fail_authenticate1(void) {
const char *cfg[] = {
"id=1",
Expand Down Expand Up @@ -244,6 +266,14 @@ static int test_authenticate_ldap3(void) {
return pam_sm_authenticate(4, 0, sizeof(ldap_cfg2) / sizeof(char*), ldap_cfg2);
}

static int test_authenticate_ldap4(void) {
return pam_sm_authenticate(5, 0, sizeof(ldap_cfg) / sizeof(char*), ldap_cfg);
}

static int test_authenticate_ldap5(void) {
return pam_sm_authenticate(6, 0, sizeof(ldap_cfg) / sizeof(char*), ldap_cfg);
}

static pid_t run_mock(const char *port, const char *type) {
pid_t pid = fork();
if(pid == 0) {
Expand Down Expand Up @@ -287,6 +317,14 @@ int main(void) {
ret = 6;
goto out;
}
if(test_authenticate4() != PAM_AUTH_ERR) {
ret = 7;
goto out;
}
if(test_authenticate5() != PAM_USER_UNKNOWN) {
ret = 8;
goto out;
}
#ifdef HAVE_LIBLDAP
if(test_authenticate_ldap1() != PAM_SUCCESS) {
ret = 1001;
Expand All @@ -308,6 +346,14 @@ int main(void) {
ret = 1005;
goto out;
}
if(test_authenticate_ldap4() != PAM_AUTH_ERR) {
ret = 1006;
goto out;
}
if(test_authenticate_ldap5() != PAM_USER_UNKNOWN) {
ret = 1007;
goto out;
}
#endif

out:
Expand Down

0 comments on commit 4fb0be3

Please sign in to comment.