htauth 2.2.0 → 3.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +21 -1
  3. data/Manifest.txt +5 -27
  4. data/README.md +51 -31
  5. data/exe/htdigest-ruby +14 -0
  6. data/exe/htpasswd-ruby +14 -0
  7. data/htauth.gemspec +33 -0
  8. data/lib/htauth/algorithm.rb +42 -29
  9. data/lib/htauth/argon2.rb +86 -0
  10. data/lib/htauth/bcrypt.rb +17 -11
  11. data/lib/htauth/cli/digest.rb +42 -49
  12. data/lib/htauth/cli/passwd.rb +127 -114
  13. data/lib/htauth/cli.rb +5 -4
  14. data/lib/htauth/console.rb +9 -6
  15. data/lib/htauth/crypt.rb +11 -9
  16. data/lib/htauth/descendant_tracker.rb +11 -9
  17. data/lib/htauth/digest_entry.rb +22 -19
  18. data/lib/htauth/digest_file.rb +25 -18
  19. data/lib/htauth/entry.rb +3 -1
  20. data/lib/htauth/error.rb +6 -5
  21. data/lib/htauth/file.rb +35 -39
  22. data/lib/htauth/md5.rb +35 -34
  23. data/lib/htauth/passwd_entry.rb +29 -38
  24. data/lib/htauth/passwd_file.rb +32 -27
  25. data/lib/htauth/plaintext.rb +7 -5
  26. data/lib/htauth/sha1.rb +9 -7
  27. data/lib/htauth/version.rb +3 -1
  28. data/lib/htauth.rb +29 -28
  29. metadata +24 -113
  30. data/Rakefile +0 -27
  31. data/bin/htdigest-ruby +0 -12
  32. data/bin/htpasswd-ruby +0 -12
  33. data/spec/algorithm_spec.rb +0 -8
  34. data/spec/bcrypt_spec.rb +0 -33
  35. data/spec/cli/digest_spec.rb +0 -149
  36. data/spec/cli/passwd_spec.rb +0 -330
  37. data/spec/crypt_spec.rb +0 -12
  38. data/spec/digest_entry_spec.rb +0 -60
  39. data/spec/digest_file_spec.rb +0 -65
  40. data/spec/md5_spec.rb +0 -13
  41. data/spec/passwd_entry_spec.rb +0 -159
  42. data/spec/passwd_file_spec.rb +0 -84
  43. data/spec/plaintext_spec.rb +0 -11
  44. data/spec/sha1_spec.rb +0 -11
  45. data/spec/spec_helper.rb +0 -28
  46. data/spec/test.add.digest +0 -3
  47. data/spec/test.add.passwd +0 -3
  48. data/spec/test.delete.digest +0 -1
  49. data/spec/test.delete.passwd +0 -1
  50. data/spec/test.original.digest +0 -2
  51. data/spec/test.original.passwd +0 -2
  52. data/spec/test.update.digest +0 -2
  53. data/spec/test.update.passwd +0 -2
  54. data/tasks/default.rake +0 -242
  55. data/tasks/this.rb +0 -208
  56. /data/{LICENSE → LICENSE.txt} +0 -0
@@ -1,149 +0,0 @@
1
- require 'spec_helper'
2
- require 'htauth/cli/digest'
3
- require 'tempfile'
4
-
5
- describe HTAuth::CLI::Digest do
6
-
7
- before(:each) do
8
-
9
- # existing
10
- @tf = Tempfile.new("rpasswrd-digest-test")
11
- @tf.write(IO.read(DIGEST_ORIGINAL_TEST_FILE))
12
- @tf.close
13
- @rdigest = HTAuth::CLI::Digest.new
14
-
15
- # new file
16
- @new_file = File.join(File.dirname(@tf.path), "new-testfile")
17
-
18
- # rework stdout and stderr
19
- @stdout = ConsoleIO.new
20
- @old_stdout = $stdout
21
- $stdout = @stdout
22
-
23
- @stderr = ConsoleIO.new
24
- @old_stderr = $stderr
25
- $stderr = @stderr
26
-
27
- @stdin = ConsoleIO.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
- @rdigest.run([ "-h" ])
43
- rescue SystemExit => se
44
- _(se.status).must_equal 1
45
- _(@stdout.string).must_match( /passwordfile realm username/m )
46
- end
47
- end
48
-
49
- it "displays the version appropriately" do
50
- begin
51
- @rdigest.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 entries" do
59
- begin
60
- @stdin.puts "b secret"
61
- @stdin.puts "b secret"
62
- @stdin.rewind
63
- @rdigest.run([ "-c", @new_file, "htauth", "bob" ])
64
- rescue SystemExit => se
65
- _(se.status).must_equal 0
66
- _(IO.read(@new_file)).must_equal IO.readlines(DIGEST_ORIGINAL_TEST_FILE).first
67
- end
68
- end
69
-
70
- it "truncates an exiting file if told to create a new file" do
71
- begin
72
- @stdin.puts "b secret"
73
- @stdin.puts "b secret"
74
- @stdin.rewind
75
- @rdigest.run([ "-c", @tf.path, "htauth", "bob"])
76
- rescue SystemExit => se
77
- _(se.status).must_equal 0
78
- _(IO.read(@tf.path)).must_equal IO.read(DIGEST_DELETE_TEST_FILE)
79
- end
80
- end
81
-
82
- it "adds an entry to an existing file" do
83
- begin
84
- @stdin.puts "c secret"
85
- @stdin.puts "c secret"
86
- @stdin.rewind
87
- @rdigest.run([ @tf.path, "htauth-new", "charlie" ])
88
- rescue SystemExit => se
89
- _(se.status).must_equal 0
90
- _(IO.read(@tf.path)).must_equal IO.read(DIGEST_ADD_TEST_FILE)
91
- end
92
- end
93
-
94
- it "updates an entry in an existing file" do
95
- begin
96
- @stdin.puts "a new secret"
97
- @stdin.puts "a new secret"
98
- @stdin.rewind
99
- @rdigest.run([ @tf.path, "htauth", "alice" ])
100
- rescue SystemExit => se
101
- _(@stderr.string).must_equal ""
102
- _(se.status).must_equal 0
103
- _(IO.read(@tf.path)).must_equal IO.read(DIGEST_UPDATE_TEST_FILE)
104
- end
105
- end
106
-
107
- it "deletes an entry in an existing file" do
108
- begin
109
- @rdigest.run([ "-d", @tf.path, "htauth", "alice" ])
110
- rescue SystemExit => se
111
- _(@stderr.string).must_equal ""
112
- _(se.status).must_equal 0
113
- _(IO.read(@tf.path)).must_equal IO.read(DIGEST_DELETE_TEST_FILE)
114
- end
115
- end
116
-
117
- it "has an error if it does not have permissions on the file" do
118
- begin
119
- @stdin.puts "a secret"
120
- @stdin.puts "a secret"
121
- @stdin.rewind
122
- @rdigest.run([ "-c", "/etc/you-cannot-create-me", "htauth", "alice"])
123
- rescue SystemExit => se
124
- _(@stderr.string).must_match( %r{Could not open password file /etc/you-cannot-create-me}m )
125
- _(se.status).must_equal 1
126
- end
127
- end
128
-
129
- it "has an error if the input passwords do not match" do
130
- begin
131
- @stdin.puts "a secret"
132
- @stdin.puts "a bad secret"
133
- @stdin.rewind
134
- @rdigest.run([ @tf.path, "htauth", "alice"])
135
- rescue SystemExit => se
136
- _(@stderr.string).must_match( /They don't match, sorry./m )
137
- _(se.status).must_equal 1
138
- end
139
- end
140
-
141
- it "has an error if the options are incorrect" do
142
- begin
143
- @rdigest.run(["--blah"])
144
- rescue SystemExit => se
145
- _(@stderr.string).must_match( /ERROR:/m )
146
- _(se.status).must_equal 1
147
- end
148
- end
149
- end
@@ -1,330 +0,0 @@
1
- require 'spec_helper'
2
- require 'htauth/cli/passwd'
3
- require 'tempfile'
4
-
5
- describe HTAuth::CLI::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::CLI::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 = ConsoleIO.new
20
- @old_stdout = $stdout
21
- $stdout = @stdout
22
-
23
- @stderr = ConsoleIO.new
24
- @old_stderr = $stderr
25
- $stderr = @stderr
26
-
27
- @stdin = ConsoleIO.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 "creates a new file with one bcrypt entry" do
74
- begin
75
- @stdin.puts "b secret"
76
- @stdin.puts "b secret"
77
- @stdin.rewind
78
- @htauth.run([ "-B", "-c", @new_file, "brenda" ])
79
- rescue SystemExit => se
80
- _(se.status).must_equal 0
81
- l = IO.readlines(@new_file)
82
- fields = l.first.split(':')
83
- _(fields.first).must_equal "brenda"
84
- bcrypt_hash = fields.last
85
-
86
- _(::BCrypt::Password.valid_hash?(bcrypt_hash)).wont_be_nil
87
- end
88
- end
89
-
90
- it "allows the bcrypt cost to be set" do
91
- begin
92
- cost = 12
93
- @stdin.puts "b secret"
94
- @stdin.puts "b secret"
95
- @stdin.rewind
96
- @htauth.run([ "-C", "#{cost}", "-B", "-c", @new_file, "brenda" ])
97
- rescue SystemExit => se
98
- _(se.status).must_equal 0
99
- l = IO.readlines(@new_file)
100
- fields = l.first.split(':')
101
- _(fields.first).must_equal "brenda"
102
- bcrypt_hash = fields.last
103
- _(::BCrypt::Password.valid_hash?(bcrypt_hash)).wont_be_nil
104
-
105
- _, _version, count, _rest = bcrypt_hash.split("$")
106
- _(count).must_equal ("%02d" % cost)
107
- end
108
- end
109
-
110
- it "raises an error if the bcrypt cost is out of range" do
111
- begin
112
- @stdin.puts "b secret"
113
- @stdin.puts "b secret"
114
- @stdin.rewind
115
- @htauth.run([ "-C", "42", "-B", "-c", @new_file, "brenda" ])
116
- rescue SystemExit => se
117
- _(@stderr.string).must_match( /ERROR:/m )
118
- _(se.status).must_equal 1
119
- end
120
- end
121
-
122
- it "raises an error if the bcrypt cost is not an integer" do
123
- begin
124
- @stdin.puts "b secret"
125
- @stdin.puts "b secret"
126
- @stdin.rewind
127
- @htauth.run([ "-C", "forty-two", "-B", "-c", @new_file, "brenda" ])
128
- rescue SystemExit => se
129
- _(@stderr.string).must_match( /ERROR:/m )
130
- _(se.status).must_equal 1
131
- end
132
-
133
- end
134
-
135
- it "does not verify the password from stdin on -i option" do
136
- begin
137
- @stdin.puts "b secret"
138
- @stdin.rewind
139
- @htauth.run([ "-i", "-B", "-c", @new_file, "brenda" ])
140
- rescue SystemExit => se
141
- _(se.status).must_equal 0
142
- l = IO.readlines(@new_file)
143
- fields = l.first.split(':')
144
- _(fields.first).must_equal "brenda"
145
- bcrypt_hash = fields.last
146
-
147
- _(::BCrypt::Password.valid_hash?(bcrypt_hash)).wont_be_nil
148
- end
149
- end
150
-
151
- it "does not allow options -i and -b to both be set" do
152
- begin
153
- @stdin.puts "b secret"
154
- @stdin.rewind
155
- @htauth.run([ "-i", "-b", "-B", "-c", @new_file, "brenda", "b-secret" ])
156
- rescue SystemExit => se
157
- _(@stderr.string).must_match( /ERROR:/m )
158
- _(se.status).must_equal 1
159
- end
160
- end
161
-
162
- it "truncates an exiting file if told to create a new file" do
163
- before_lines = IO.readlines(@tf.path)
164
- begin
165
- @stdin.puts "b secret"
166
- @stdin.puts "b secret"
167
- @stdin.rewind
168
- @htauth.run([ "-c", @tf.path, "bob"])
169
- rescue SystemExit => se
170
- _(se.status).must_equal 0
171
- after_lines = IO.readlines(@tf.path)
172
- _(after_lines.size).must_equal 1
173
- _(before_lines.size).must_equal 2
174
- end
175
- end
176
-
177
- it "adds an entry to an existing file and force SHA" do
178
- begin
179
- @stdin.puts "c secret"
180
- @stdin.puts "c secret"
181
- @stdin.rewind
182
- @htauth.run([ "-s", @tf.path, "charlie" ])
183
- rescue SystemExit => se
184
- _(se.status).must_equal 0
185
- after_lines = IO.readlines(@tf.path)
186
- _(after_lines.size).must_equal 3
187
- al = after_lines.last.split(':')
188
- _(al.first).must_equal "charlie"
189
- _(al.last).must_match( /\{SHA\}/ )
190
- end
191
- end
192
-
193
- it "can create a plaintext encrypted file" do
194
- begin
195
- @stdin.puts "a bad password"
196
- @stdin.puts "a bad password"
197
- @stdin.rewind
198
- @htauth.run(["-c", "-p", @tf.path, "bradley"])
199
- rescue SystemExit => se
200
- _(se.status).must_equal 0
201
- _(IO.read(@tf.path).strip).must_equal "bradley:a bad password"
202
- end
203
- end
204
-
205
- it "has a batch mode for command line passwords" do
206
- begin
207
- @htauth.run(["-c", "-p", "-b", @tf.path, "bradley", "a bad password"])
208
- rescue SystemExit => se
209
- _(se.status).must_equal 0
210
- _(IO.read(@tf.path).strip).must_equal "bradley:a bad password"
211
- end
212
- end
213
-
214
- it "updates an entry in an existing file and force crypt" do
215
- before_lines = IO.readlines(@tf.path)
216
- begin
217
- @stdin.puts "a new secret"
218
- @stdin.puts "a new secret"
219
- @stdin.rewind
220
- @htauth.run([ "-d", @tf.path, "alice" ])
221
- rescue SystemExit => se
222
- _(@stderr.string).must_equal ""
223
- _(se.status).must_equal 0
224
- after_lines = IO.readlines(@tf.path)
225
- _(after_lines.size).must_equal before_lines.size
226
-
227
- a_b = before_lines.first.split(":")
228
- a_a = after_lines.first.split(":")
229
-
230
- _(a_b.first).must_equal a_a.first
231
- _(a_b.last).wont_equal a_a.last
232
- end
233
- end
234
-
235
- it "deletes an entry in an existing file" do
236
- begin
237
- @htauth.run([ "-D", @tf.path, "bob" ])
238
- rescue SystemExit => se
239
- _(@stderr.string).must_equal ""
240
- _(se.status).must_equal 0
241
- _(IO.read(@tf.path)).must_equal IO.read(PASSWD_DELETE_TEST_FILE)
242
- end
243
- end
244
-
245
- it "sends to STDOUT when the -n option is used" do
246
- begin
247
- @htauth.run(["-n", "-p", "-b", "bradley", "a bad password"])
248
- rescue SystemExit => se
249
- _(se.status).must_equal 0
250
- _(@stdout.string.strip).must_equal "bradley:a bad password"
251
- end
252
- end
253
-
254
- it "verifies a password when --verify is used - valid" do
255
- begin
256
- @htauth.run(["--verify", "-b", @tf.path, "alice", "a secret"])
257
- rescue SystemExit => se
258
- _(@stderr.string.strip).must_equal "Password for user alice correct."
259
- _(se.status).must_equal 0
260
- end
261
- end
262
-
263
- it "verifies a password when --verify is used - invalid" do
264
- begin
265
- @htauth.run(["--verify", "-b", @tf.path, "alice", "the wrong secret"])
266
- rescue SystemExit => se
267
- _(@stderr.string.strip).must_equal "Password verification for user alice failed."
268
- _(se.status).must_equal 1
269
- end
270
- end
271
-
272
- it "has an error if it does not have permissions on the file" do
273
- begin
274
- @stdin.puts "a secret"
275
- @stdin.puts "a secret"
276
- @stdin.rewind
277
- @htauth.run([ "-c", "/etc/you-cannot-create-me", "alice"])
278
- rescue SystemExit => se
279
- _(@stderr.string).must_match( %r{Password file failure \(/etc/you-cannot-create-me\)}m )
280
- _(se.status).must_equal 1
281
- end
282
- end
283
-
284
- it "has an error if the input passwords do not match" do
285
- begin
286
- @stdin.puts "a secret"
287
- @stdin.puts "a bad secret"
288
- @stdin.rewind
289
- @htauth.run([ @tf.path, "alice"])
290
- rescue SystemExit => se
291
- _(@stderr.string).must_match( /They don't match, sorry./m )
292
- _(se.status).must_equal 1
293
- end
294
- end
295
-
296
- it "has an error if the options are incorrect" do
297
- begin
298
- @htauth.run(["--blah"])
299
- rescue SystemExit => se
300
- _(@stderr.string).must_match( /ERROR:/m )
301
- _(se.status).must_equal 1
302
- end
303
- end
304
-
305
- it "errors if send to stdout and create a new file options are both used" do
306
- begin
307
- @htauth.run(["-c", "-n"])
308
- rescue SystemExit => se
309
- _(@stderr.string).must_match( /ERROR:/m )
310
- _(se.status).must_equal 1
311
- end
312
- end
313
-
314
- it "errors if multiple types of operations are attmpted to be used at once" do
315
- begin
316
- @htauth.run(["-n", "-D"])
317
- rescue SystemExit => se
318
- _(@stderr.string).must_match( /ERROR:/m )
319
- _(se.status).must_equal 1
320
- end
321
-
322
- begin
323
- @htauth.run(["--verify", "-D"])
324
- rescue SystemExit => se
325
- _(@stderr.string).must_match( /ERROR:/m )
326
- _(se.status).must_equal 1
327
- end
328
-
329
- end
330
- end
data/spec/crypt_spec.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'htauth/crypt'
3
-
4
- describe HTAuth::Crypt do
5
- it "encrypts the same way that apache does" do
6
- apache_salt = "L0LDd/.."
7
- apache_result = "L0ekWYm59LT1M"
8
- crypt = HTAuth::Crypt.new({ :salt => apache_salt} )
9
- _(crypt.encode("a secret")).must_equal apache_result
10
- end
11
- end
12
-
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
- require 'htauth/digest_entry'
3
-
4
- describe HTAuth::DigestEntry do
5
- before(:each) do
6
- @alice = HTAuth::DigestEntry.new("alice", "htauth")
7
- @bob = HTAuth::DigestEntry.new("bob", "htauth", "b secret")
8
- end
9
-
10
- it "initializes with a user and realm" do
11
- _(@alice.user).must_equal "alice"
12
- _(@alice.realm).must_equal "htauth"
13
- end
14
-
15
- it "has the correct digest for a password" do
16
- @alice.password = "digit"
17
- _(@alice.digest).must_equal "4ed9e5744c6747af8f292d28afd6372e"
18
- end
19
-
20
- it "returns username:realm for a key" do
21
- _(@alice.key).must_equal "alice:htauth"
22
- end
23
-
24
- it "checks the password correctly" do
25
- _(@bob.authenticated?("b secret")).must_equal true
26
- end
27
-
28
- it "formats correctly when put to a string" do
29
- _(@bob.to_s).must_equal "bob:htauth:fcbeab6821d2ab3b00934c958db0fd1e"
30
- end
31
-
32
- it "parses an input line" do
33
- @bob_new = HTAuth::DigestEntry.from_line("bob:htauth:fcbeab6821d2ab3b00934c958db0fd1e")
34
- _(@bob.user).must_equal @bob_new.user
35
- _(@bob.digest).must_equal @bob_new.digest
36
- _(@bob.realm).must_equal @bob_new.realm
37
- end
38
-
39
- it "knows if an input line is a possible entry and raises an exception" do
40
- _ { HTAuth::DigestEntry.is_entry!("#stuff") }.must_raise(HTAuth::InvalidDigestEntry)
41
- _ { HTAuth::DigestEntry.is_entry!("this:that:other:stuff") }.must_raise(HTAuth::InvalidDigestEntry)
42
- _ { HTAuth::DigestEntry.is_entry!("this:that:other") }.must_raise(HTAuth::InvalidDigestEntry)
43
- _ { HTAuth::DigestEntry.is_entry!("this:that:0a90549e8ffb2dd62f98252a95d88xyz") }.must_raise(HTAuth::InvalidDigestEntry)
44
- end
45
-
46
- it "knows if an input line is a possible entry and returns false" do
47
- _(HTAuth::DigestEntry.is_entry?("#stuff")).must_equal false
48
- _(HTAuth::DigestEntry.is_entry?("this:that:other:stuff")).must_equal false
49
- _(HTAuth::DigestEntry.is_entry?("this:that:other")).must_equal false
50
- _(HTAuth::DigestEntry.is_entry?("this:that:0a90549e8ffb2dd62f98252a95d88xyz")).must_equal false
51
- end
52
-
53
- it "knows if an input line is a possible entry and returns true" do
54
- _(HTAuth::DigestEntry.is_entry?("bob:htauth:0a90549e8ffb2dd62f98252a95d88697")).must_equal true
55
- end
56
-
57
- it "duplicates itself" do
58
- _(@alice.dup.to_s).must_equal @alice.to_s
59
- end
60
- end
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
- require 'htauth/digest_file'
3
- require 'tempfile'
4
-
5
- describe HTAuth::DigestFile do
6
-
7
- before(:each) do
8
- @tf = Tempfile.new("rpasswrd-digest")
9
- @tf.write(IO.read(DIGEST_ORIGINAL_TEST_FILE))
10
- @tf.close
11
- @digest_file = HTAuth::DigestFile.new(@tf.path)
12
-
13
- @tf2 = Tempfile.new("rpasswrd-digest-empty")
14
- @tf2.close
15
- @empty_digest_file = HTAuth::DigestFile.new(@tf2.path)
16
- end
17
-
18
- after(:each) do
19
- @tf2.close(true)
20
- @tf.close(true)
21
- end
22
-
23
- it "can add a new entry to an already existing digest file" do
24
- @digest_file.add_or_update("charlie", "htauth-new", "c secret")
25
- _(@digest_file.contents).must_equal IO.read(DIGEST_ADD_TEST_FILE)
26
- end
27
-
28
- it "can tell if an entry already exists in the digest file" do
29
- _(@digest_file.has_entry?("alice", "htauth")).must_equal true
30
- _(@digest_file.has_entry?("alice", "some other realm")).must_equal false
31
- end
32
-
33
- it "can update an entry in an already existing digest file" do
34
- @digest_file.add_or_update("alice", "htauth", "a new secret")
35
- _(@digest_file.contents).must_equal IO.read(DIGEST_UPDATE_TEST_FILE)
36
- end
37
-
38
- it "fetches a copy of an entry" do
39
- _(@digest_file.fetch("alice", "htauth").to_s).must_equal "alice:htauth:2f361db93147d84831eb34f19d05bfbb"
40
- end
41
-
42
- it "raises an error if an attempt is made to alter a non-existenet file" do
43
- _ { HTAuth::DigestFile.new("some-file") }.must_raise(HTAuth::FileAccessError)
44
- end
45
-
46
- # this test will only work on systems that have /etc/ssh_host_rsa_key
47
- it "raises an error if an attempt is made to open a file where no permissions are granted" do
48
- _ { HTAuth::DigestFile.new("/etc/ssh_host_rsa_key") }.must_raise(HTAuth::FileAccessError)
49
- end
50
-
51
- it "deletes an entry" do
52
- @digest_file.delete("alice", "htauth")
53
- _(@digest_file.contents).must_equal IO.read(DIGEST_DELETE_TEST_FILE)
54
- end
55
-
56
- it "is usable in a ruby manner and yeilds itself when opened" do
57
- HTAuth::DigestFile.open(@tf.path) do |pf|
58
- pf.add_or_update("alice", "htauth", "a secret")
59
- pf.delete('bob', 'htauth')
60
- end
61
- lines = IO.readlines(@tf.path)
62
- _(lines.size).must_equal 1
63
- _(lines.first.strip).must_equal "alice:htauth:2f361db93147d84831eb34f19d05bfbb"
64
- end
65
- end
data/spec/md5_spec.rb DELETED
@@ -1,13 +0,0 @@
1
- require File.join(File.dirname(__FILE__),"spec_helper.rb")
2
-
3
- require 'htauth/md5'
4
-
5
- describe HTAuth::Md5 do
6
- it "encrypts the same way that apache does" do
7
- apache_salt = "L0LDd/.."
8
- apache_result = "$apr1$L0LDd/..$yhUzDjpxam5F1kWdtwMco1"
9
- md5 = HTAuth::Md5.new({ 'salt' => apache_salt })
10
- _(md5.encode("a secret")).must_equal apache_result
11
- end
12
- end
13
-