Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
correct test
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Lux committed Oct 30, 2020
1 parent ba616fe commit 087bec8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ language: python
sudo: false
python:
- 2.7
- 3.5
- 3.6
- 3.7
- 3.8

# command to install dependencies
install:
Expand Down
Binary file modified pam-test.sqlite
Binary file not shown.
36 changes: 16 additions & 20 deletions privacyidea_pam.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,12 @@ def offline_refill(self, serial, password):
startdb(self.sql)
refilltoken = None
# get all possible serial/tokens for a user
for row in sql_select_statement("SELECT refilltoken FROM refilltokens WHERE serial=?",
(serial)):
c.execute(sql_abstract("SELECT refilltoken FROM refilltokens WHERE serial=?"),
(serial, ))
for row in c.fetchall():
refilltoken = row[0]
syslog.syslog("Doing refill with token {0!s}".format(refilltoken))

closedb()

if refilltoken:
Expand Down Expand Up @@ -484,7 +486,6 @@ def pam_sm_authenticate(pamh, flags, argv):
return pamh.PAM_AUTHINFO_UNAVAIL

try:

if grace_time is not None:
syslog.syslog(syslog.LOG_DEBUG,
"Grace period in minutes: %s " % (str(grace_time)))
Expand All @@ -494,7 +495,6 @@ def pam_sm_authenticate(pamh, flags, argv):
rval = pamh.PAM_SUCCESS

if rval != pamh.PAM_SUCCESS:

# Check if user has tokens
Auth.check_user_tokens(Auth.user)

Expand Down Expand Up @@ -571,15 +571,18 @@ def check_offline_otp(sql_params, user, otp, window=10, refill=True):
# get all possible serial/tokens for a user
serials = []
matching_serial = None
for row in sql_select_statement("SELECT serial, user FROM authitems WHERE user=?"
"GROUP by serial", (user,)):

c.execute(sql_abstract("SELECT serial, user FROM authitems WHERE user=?"
"GROUP by serial"), (user,))
for row in c.fetchall():
serials.append(row[0])

for serial in serials:
for row in sql_select_statement("SELECT counter, user, otp, serial FROM authitems "
c.execute(sql_abstract("SELECT counter, user, otp, serial FROM authitems "
"WHERE user=? and serial=? ORDER by counter "
"LIMIT ?",
(user, serial, window)):
"LIMIT ?"),
(user, serial, window))
for row in c.fetchall():
hash_value = row[2]
if passlib.hash.pbkdf2_sha512.verify(otp, hash_value):
res = True
Expand Down Expand Up @@ -660,11 +663,12 @@ def check_last_history(sql_params, user, rhost, grace_time, window=10):
res = False
events = []

for row in sql_select_statement("SELECT user, rhost, serial, last_success, last_error "
c.execute(sql_abstract("SELECT user, rhost, serial, last_success, last_error "
"FROM history "
"WHERE user=? AND rhost=? ORDER by last_success "
"LIMIT ?",
(user, rhost, window)):
"LIMIT ?"),
(user, rhost, window))
for row in c.fetchall():
events.append(row)

if len(events)>0:
Expand Down Expand Up @@ -788,11 +792,3 @@ def sql_abstract(sql_statement):
return sql_statement
else:
return sql_statement.replace('?','%s')

# Handle SQLite/MySQL SELECT statement
def sql_select_statement(select_statement, sql_args):
exec_statement = c.execute(sql_abstract(select_statement),sql_args)
if SQLite:
return exec_statement
else:
return c.fetchall()
5 changes: 4 additions & 1 deletion tests/test_pam_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ def test_06_refill(self):

# now with refill
with responses.RequestsMock() as rsps:
rsps.add(responses.GET,
"http://my.privacyidea.server/token",
body=json.dumps(USER_TOKEN_BODY),
content_type="application/json")
rsps.add(responses.POST,
"http://my.privacyidea.server/validate/offlinerefill",
body=json.dumps(REFILL_BODY),
Expand All @@ -335,7 +339,6 @@ def test_06_refill(self):
"try_first_pass"]
r = pam_sm_authenticate(pamh, flags, argv)
self.assertEqual(r, PAMH.PAM_SUCCESS)
print rsps.calls[1].request
self.assertIn('refilltoken=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
rsps.calls[1].request.body)

Expand Down

0 comments on commit 087bec8

Please sign in to comment.