~ubuntu-branches/ubuntu/precise/nss-pam-ldapd/precise-security

« back to all changes in this revision

Viewing changes to tests/test_pamcmds.expect

  • Committer: Package Import Robot
  • Author(s): Arthur de Jong
  • Date: 2011-09-04 21:00:00 UTC
  • mfrom: (14.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20110904210000-pe3u91iga88vtr16
Tags: 0.8.4
* Upload to unstable
* switch to using the member attribute by default instead of
  uniqueMember (backwards incompatible change)
* only return "x" as a password hash when the object has the shadowAccount
  objectClass and nsswitch.conf is configured to do shadow lookups using
  LDAP (this avoids some problems with pam_unix)
* fix problem with partial attribute name matches in DN (thanks Timothy
  White)
* fix a problem with objectSid mappings with recent versions of OpenLDAP
  (patch by Wesley Mason)
* set the socket timeout in a connection callback to avoid timeout
  issues during the SSL handshake (patch by Stefan Völkel)
* check for unknown variables in pam_authz_search
* only check password expiration when authenticating, only check account
  expiration when doing authorisation
* make buffer sizes consistent and grow all buffers holding string
  representations of numbers to be able to hold 64-bit numbers
* update AX_PTHREAD from autoconf-archive
* support querying DNS SRV records from a different domain than the current
  one (based on a patch by James M. Leddy)
* fix a problem with uninitialised memory while parsing the tls_ciphers
  option (closes: #638872) (but doesn't work yet due to #640384)
* implement bounds checking of numeric values read from LDAP (patch by
  Jakub Hrozek)
* correctly support large uid and gid values from LDAP (patch by Jakub
  Hrozek)
* improvements to the configure script (patch by Jakub Hrozek)
* switch to dh for debian/rules and bump debhelper compatibility to 8
* build Debian packages with multiarch support
* ship shlibs (but still no symbol files) for libnss-ldapd since that was
  the easiest way to support multiarch
* fix output in init script when restarting nslcd (closes: #637132)
* correctly handle leading and trailing spaces in preseeded debconf uri
  option (patch by Andreas B. Mundt) (closes: #637863)
* support spaces around database names in /etc/nsswitch.conf while
  configuring package (closes: #640185)
* updated Russian debconf translation by Yuri Kozlov (closes: #637751)
* updated French debconf translation by Christian Perrier (closes: #637756)
* added Slovak debconf translation by Slavko (closes: #637759)
* updated Danish debconf translation by Joe Hansen (closes :#637763)
* updated Brazilian Portuguese debconf translation by Denis Doria
* updated Portuguese debconf translation by Américo Monteiro
* updated Japanese debconf translation by Kenshi Muto (closes: #638195)
* updated Czech debconf translation by Miroslav Kure (closes: #639026)
* updated German debconf translation by Chris Leick (closes: #639107)
* updated Spanish debconf translation by Francisco Javier Cuadrado
  (closes: #639236)
* updated Dutch debconf translation by Arthur de Jong with help from Paul
  Gevers and Jeroen Schot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/expect --
 
2
 
 
3
# test_pamcmds.expect - test script to check output of PAM commands
 
4
#
 
5
# Copyright (C) 2011 Arthur de Jong
 
6
#
 
7
# This library is free software; you can redistribute it and/or
 
8
# modify it under the terms of the GNU Lesser General Public
 
9
# License as published by the Free Software Foundation; either
 
10
# version 2.1 of the License, or (at your option) any later version.
 
11
#
 
12
# This library is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
# Lesser General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU Lesser General Public
 
18
# License along with this library; if not, write to the Free Software
 
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
20
# 02110-1301 USA
 
21
 
 
22
# basic configuration
 
23
set timeout 5
 
24
log_file -a -noappend test_pamcmds.log
 
25
log_user 0
 
26
 
 
27
# basic error handling
 
28
proc abort {} {
 
29
  global expect_out
 
30
  send_user "\n\ntest_pamcmds.expect: ERROR found:\n"
 
31
  send_user "$expect_out(buffer)\n"
 
32
  exit 1
 
33
}
 
34
 
 
35
# function for resetting the password
 
36
proc reset_password {} {
 
37
  global expect_out
 
38
  send_user "test_pamcmds.expect: resetting passwd...\n"
 
39
  spawn passwd arthur
 
40
  expect {
 
41
    "LDAP administrator password" { send "test\r"; exp_continue }
 
42
    -regexp "(New|Retype new) password:" { send "test\r"; exp_continue }
 
43
    "password updated successfully" {}
 
44
    "Invalid credentials" abort
 
45
    "Authentication token manipulation error" abort
 
46
    default abort
 
47
  }
 
48
  #close
 
49
}
 
50
 
 
51
# find source directory
 
52
if { ! [info exists ::env(srcdir) ] } {
 
53
  set env(srcdir) "."
 
54
}
 
55
# ensure that we are running as root
 
56
if { [exec id -u] != "0" } {
 
57
  send_user "test_pamcmds.expect: not running as root\n"
 
58
  exit 77
 
59
}
 
60
# ensure that we are running in the test environment
 
61
spawn $env(srcdir)/in_testenv.sh
 
62
expect {
 
63
  "in_testenv.sh: using LDAP server" { expect eof }
 
64
  eof {
 
65
    send_user "test_pamcmds.expect: not running in test environment\n"
 
66
    exit 77
 
67
  }
 
68
}
 
69
 
 
70
# ensure that a correct password is set
 
71
reset_password
 
72
 
 
73
# start a shell as nobody
 
74
send_user "test_pamcmds.expect: start shell...\n"
 
75
spawn su - nobody -s /bin/sh
 
76
expect "\$ "
 
77
 
 
78
# function to do login, expecting OK result
 
79
proc test_login_ok {uid passwd} {
 
80
  send "su - $uid -s /bin/sh\r"
 
81
  expect "Password:"
 
82
  send "$passwd\r"
 
83
  expect {
 
84
    "\$ " {}
 
85
    "su: " abort
 
86
    default abort
 
87
  }
 
88
  # test whether we are really logged in
 
89
  send "id\r"
 
90
  expect {
 
91
    -regexp "uid=\[0-9\]*\\($uid\\)" {}
 
92
    "\$ " abort
 
93
    default abort
 
94
  }
 
95
  expect "\$ "
 
96
}
 
97
 
 
98
# function to do login, expecting FAIL result
 
99
proc test_login_authfail {uid passwd} {
 
100
  send "su - $uid -s /bin/sh\r"
 
101
  expect "Password:"
 
102
  send "$passwd\r"
 
103
  expect {
 
104
    "su: Authentication failure" {}
 
105
    "\$ " abort
 
106
    default abort
 
107
  }
 
108
  expect "\$ "
 
109
}
 
110
 
 
111
# function to do login, expecting FAIL result
 
112
proc test_login_unknown {uid passwd} {
 
113
  send "su - $uid -s /bin/sh\r"
 
114
  expect {
 
115
    "Password:" { send "$passwd\r"; exp_continue }
 
116
    "Unknown id" {}
 
117
    "\$ " abort
 
118
    default abort
 
119
  }
 
120
  expect "\$ "
 
121
}
 
122
 
 
123
# test incorrect password
 
124
send_user "test_pamcmds.expect: testing incorrect password...\n"
 
125
test_login_authfail arthur wrongpassword
 
126
 
 
127
# test correct password
 
128
send_user "test_pamcmds.expect: testing correct password...\n"
 
129
test_login_ok arthur test
 
130
 
 
131
# change password using incorrect old password
 
132
send_user "test_pamcmds.expect: testing password change with incorrect password...\n"
 
133
send "passwd\r"
 
134
expect {
 
135
  -nocase "password:" { send "wrongpassword\r" }
 
136
  "\$ " abort
 
137
  default abort
 
138
}
 
139
expect {
 
140
  -regexp "(New|Retype new) password:" { send "newpassword\r"; exp_continue }
 
141
  "password changed" abort
 
142
  "Invalid credentials" {}
 
143
  "Authentication token manipulation error" {}
 
144
  "\$ " abort
 
145
}
 
146
expect "\$ "
 
147
 
 
148
# change the password using the correct old password
 
149
send_user "test_pamcmds.expect: testing password change with correct password...\n"
 
150
send "passwd\r"
 
151
expect {
 
152
  -nocase "password:" { send "test\r" }
 
153
  "\$ " abort
 
154
  default abort
 
155
}
 
156
expect {
 
157
  -regexp "(New|Retype new) password:" { send "newpassword\r"; exp_continue }
 
158
  "password updated successfully" {}
 
159
  "Invalid credentials" abort
 
160
  "Authentication token manipulation error" abort
 
161
  "\$ " abort
 
162
}
 
163
expect "\$ "
 
164
 
 
165
# exist shell (back to nobody)
 
166
send "exit\r"
 
167
expect "\$ "
 
168
 
 
169
# logging in with the old password should fail now
 
170
send_user "test_pamcmds.expect: testing old password...\n"
 
171
test_login_authfail arthur test
 
172
 
 
173
# test correct password
 
174
send_user "test_pamcmds.expect: testing new password...\n"
 
175
test_login_ok arthur newpassword
 
176
 
 
177
# test invalid username
 
178
send_user "test_pamcmds.expect: testing with unknown username...\n"
 
179
test_login_unknown foo anypassword
 
180
 
 
181
# test login as root with incorrect password
 
182
send_user "test_pamcmds.expect: testing with root...\n"
 
183
test_login_authfail root anypassword
 
184
 
 
185
# test login as nobody with incorrect password
 
186
send_user "test_pamcmds.expect: testing with nobody...\n"
 
187
test_login_authfail nobody anypassword
 
188
 
 
189
# close the shell (first log of arthur)
 
190
send "exit\r"
 
191
expect "\$ "
 
192
send "exit\r"
 
193
expect {
 
194
  eof {}
 
195
  "\$ " abort
 
196
  timeout abort
 
197
}
 
198
 
 
199
# ensure that a correct password is set
 
200
reset_password
 
201
 
 
202
send_user "test_pamcmds.expect: everyting OK\n"
 
203
 
 
204
exit 0