htauth 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,206 +0,0 @@
1
- require 'spec_helper'
2
- require 'htauth/passwd'
3
- require 'tempfile'
4
-
5
- describe HTAuth::Passwd do
6
-
7
- before(:each) do
8
-
9
- # existing
10
- @tf = Tempfile.new("rpasswrd-passwd-test")
11
- @tf.write(IO.read(PASSWD_ORIGINAL_TEST_FILE))
12
- @tf.close
13
- @htauth = HTAuth::Passwd.new
14
-
15
- # new file
16
- @new_file = File.join(File.dirname(@tf.path), "new-testfile")
17
-
18
- # rework stdout and stderr
19
- @stdout = StringIO.new
20
- @old_stdout = $stdout
21
- $stdout = @stdout
22
-
23
- @stderr = StringIO.new
24
- @old_stderr = $stderr
25
- $stderr = @stderr
26
-
27
- @stdin = StringIO.new
28
- @old_stdin = $stdin
29
- $stdin = @stdin
30
- end
31
-
32
- after(:each) do
33
- @tf.close(true)
34
- $stderr = @old_stderr
35
- $stdout = @old_stdout
36
- $stdin = @old_stdin
37
- File.unlink(@new_file) if File.exist?(@new_file)
38
- end
39
-
40
- it "displays help appropriately" do
41
- begin
42
- @htauth.run([ "-h" ])
43
- rescue SystemExit => se
44
- se.status.must_equal 1
45
- @stdout.string.must_match( /passwordfile username/m )
46
- end
47
- end
48
-
49
- it "displays the version appropriately" do
50
- begin
51
- @htauth.run([ "--version" ])
52
- rescue SystemExit => se
53
- se.status.must_equal 1
54
- @stdout.string.must_match( /version #{HTAuth::VERSION}/)
55
- end
56
- end
57
-
58
- it "creates a new file with one md5 entry" do
59
- begin
60
- @stdin.puts "a secret"
61
- @stdin.puts "a secret"
62
- @stdin.rewind
63
- @htauth.run([ "-m", "-c", @new_file, "alice" ])
64
- rescue SystemExit => se
65
- se.status.must_equal 0
66
- l = IO.readlines(@new_file)
67
- fields = l.first.split(':')
68
- fields.first.must_equal "alice"
69
- fields.last.must_match( /^\$apr1\$/ )
70
- end
71
- end
72
-
73
- it "truncates an exiting file if told to create a new file" do
74
- before_lines = IO.readlines(@tf.path)
75
- begin
76
- @stdin.puts "b secret"
77
- @stdin.puts "b secret"
78
- @stdin.rewind
79
- @htauth.run([ "-c", @tf.path, "bob"])
80
- rescue SystemExit => se
81
- se.status.must_equal 0
82
- after_lines = IO.readlines(@tf.path)
83
- after_lines.size.must_equal 1
84
- before_lines.size.must_equal 2
85
- end
86
- end
87
-
88
- it "adds an entry to an existing file and force SHA" do
89
- begin
90
- @stdin.puts "c secret"
91
- @stdin.puts "c secret"
92
- @stdin.rewind
93
- @htauth.run([ "-s", @tf.path, "charlie" ])
94
- rescue SystemExit => se
95
- se.status.must_equal 0
96
- after_lines = IO.readlines(@tf.path)
97
- after_lines.size.must_equal 3
98
- al = after_lines.last.split(':')
99
- al.first.must_equal "charlie"
100
- al.last.must_match( /\{SHA\}/ )
101
- end
102
- end
103
-
104
- it "can create a plaintext encrypted file" do
105
- begin
106
- @stdin.puts "a bad password"
107
- @stdin.puts "a bad password"
108
- @stdin.rewind
109
- @htauth.run(["-c", "-p", @tf.path, "bradley"])
110
- rescue SystemExit => se
111
- se.status.must_equal 0
112
- IO.read(@tf.path).strip.must_equal "bradley:a bad password"
113
- end
114
- end
115
-
116
- it "has a batch mode for command line passwords" do
117
- begin
118
- @htauth.run(["-c", "-p", "-b", @tf.path, "bradley", "a bad password"])
119
- rescue SystemExit => se
120
- se.status.must_equal 0
121
- IO.read(@tf.path).strip.must_equal "bradley:a bad password"
122
- end
123
- end
124
-
125
- it "updates an entry in an existing file and force crypt" do
126
- before_lines = IO.readlines(@tf.path)
127
- begin
128
- @stdin.puts "a new secret"
129
- @stdin.puts "a new secret"
130
- @stdin.rewind
131
- @htauth.run([ "-d", @tf.path, "alice" ])
132
- rescue SystemExit => se
133
- @stderr.string.must_equal ""
134
- se.status.must_equal 0
135
- after_lines = IO.readlines(@tf.path)
136
- after_lines.size.must_equal before_lines.size
137
-
138
- a_b = before_lines.first.split(":")
139
- a_a = after_lines.first.split(":")
140
-
141
- a_b.first.must_equal a_a.first
142
- a_b.last.wont_equal a_a.last
143
- end
144
- end
145
-
146
- it "deletes an entry in an existing file" do
147
- begin
148
- @htauth.run([ "-D", @tf.path, "bob" ])
149
- rescue SystemExit => se
150
- @stderr.string.must_equal ""
151
- se.status.must_equal 0
152
- IO.read(@tf.path).must_equal IO.read(PASSWD_DELETE_TEST_FILE)
153
- end
154
- end
155
-
156
- it "sends to STDOUT when the -n option is used" do
157
- begin
158
- @htauth.run(["-n", "-p", "-b", "bradley", "a bad password"])
159
- rescue SystemExit => se
160
- se.status.must_equal 0
161
- @stdout.string.strip.must_equal "bradley:a bad password"
162
- end
163
- end
164
-
165
- it "has an error if it does not have permissions on the file" do
166
- begin
167
- @stdin.puts "a secret"
168
- @stdin.puts "a secret"
169
- @stdin.rewind
170
- @htauth.run([ "-c", "/etc/you-cannot-create-me", "alice"])
171
- rescue SystemExit => se
172
- @stderr.string.must_match( %r{Password file failure \(/etc/you-cannot-create-me\)}m )
173
- se.status.must_equal 1
174
- end
175
- end
176
-
177
- it "has an error if the input passwords do not match" do
178
- begin
179
- @stdin.puts "a secret"
180
- @stdin.puts "a bad secret"
181
- @stdin.rewind
182
- @htauth.run([ @tf.path, "alice"])
183
- rescue SystemExit => se
184
- @stderr.string.must_match( /They don't match, sorry./m )
185
- se.status.must_equal 1
186
- end
187
- end
188
-
189
- it "has an error if the options are incorrect" do
190
- begin
191
- @htauth.run(["--blah"])
192
- rescue SystemExit => se
193
- @stderr.string.must_match( /ERROR:/m )
194
- se.status.must_equal 1
195
- end
196
- end
197
-
198
- it "errors if send to stdout and create a new file options are both used" do
199
- begin
200
- @htauth.run(["-c", "-n"])
201
- rescue SystemExit => se
202
- @stderr.string.must_match( /ERROR:/m )
203
- se.status.must_equal 1
204
- end
205
- end
206
- end