htauth 1.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.
- data/CHANGES +4 -0
- data/LICENSE +19 -0
- data/README +94 -0
- data/bin/htdigest-ruby +12 -0
- data/bin/htpasswd-ruby +12 -0
- data/lib/htauth/algorithm.rb +67 -0
- data/lib/htauth/crypt.rb +20 -0
- data/lib/htauth/digest.rb +128 -0
- data/lib/htauth/digest_entry.rb +72 -0
- data/lib/htauth/digest_file.rb +85 -0
- data/lib/htauth/entry.rb +9 -0
- data/lib/htauth/file.rb +102 -0
- data/lib/htauth/gemspec.rb +52 -0
- data/lib/htauth/md5.rb +82 -0
- data/lib/htauth/passwd.rb +174 -0
- data/lib/htauth/passwd_entry.rb +97 -0
- data/lib/htauth/passwd_file.rb +86 -0
- data/lib/htauth/plaintext.rb +18 -0
- data/lib/htauth/sha1.rb +23 -0
- data/lib/htauth/specification.rb +128 -0
- data/lib/htauth/version.rb +18 -0
- data/lib/htauth.rb +27 -0
- data/spec/crypt_spec.rb +18 -0
- data/spec/digest_entry_spec.rb +61 -0
- data/spec/digest_file_spec.rb +66 -0
- data/spec/digest_spec.rb +150 -0
- data/spec/md5_spec.rb +17 -0
- data/spec/passwd_entry_spec.rb +139 -0
- data/spec/passwd_file_spec.rb +67 -0
- data/spec/passwd_spec.rb +208 -0
- data/spec/plaintext_spec.rb +18 -0
- data/spec/sha1_spec.rb +17 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/test.add.digest +3 -0
- data/spec/test.add.passwd +3 -0
- data/spec/test.delete.digest +1 -0
- data/spec/test.delete.passwd +1 -0
- data/spec/test.original.digest +2 -0
- data/spec/test.original.passwd +2 -0
- data/spec/test.update.digest +2 -0
- data/spec/test.update.passwd +2 -0
- metadata +122 -0
data/spec/passwd_spec.rb
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),"spec_helper.rb")
|
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.should == 1
|
45
|
+
@stdout.string.should =~ /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.should == 1
|
54
|
+
@stdout.string.should =~ /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.should == 0
|
66
|
+
l = IO.readlines(@new_file)
|
67
|
+
fields = l.first.split(':')
|
68
|
+
fields.first.should == "alice"
|
69
|
+
fields.last.should =~ /^\$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.should == 0
|
82
|
+
after_lines = IO.readlines(@tf.path)
|
83
|
+
after_lines.size.should == 1
|
84
|
+
before_lines.size.should == 2
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "adds an entry to an existing file and force SHA" do
|
89
|
+
before_lines = IO.readlines(@tf.path)
|
90
|
+
begin
|
91
|
+
@stdin.puts "c secret"
|
92
|
+
@stdin.puts "c secret"
|
93
|
+
@stdin.rewind
|
94
|
+
@htauth.run([ "-s", @tf.path, "charlie" ])
|
95
|
+
rescue SystemExit => se
|
96
|
+
se.status.should == 0
|
97
|
+
after_lines = IO.readlines(@tf.path)
|
98
|
+
after_lines.should have(3).lines
|
99
|
+
al = after_lines.last.split(':')
|
100
|
+
al.first.should == "charlie"
|
101
|
+
al.last.should =~ /\{SHA\}/
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it "can create a plaintext encrypted file" do
|
106
|
+
begin
|
107
|
+
@stdin.puts "a bad password"
|
108
|
+
@stdin.puts "a bad password"
|
109
|
+
@stdin.rewind
|
110
|
+
@htauth.run(["-c", "-p", @tf.path, "bradley"])
|
111
|
+
rescue SystemExit => se
|
112
|
+
se.status.should == 0
|
113
|
+
IO.read(@tf.path).strip.should == "bradley:a bad password"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it "has a batch mode for command line passwords" do
|
118
|
+
begin
|
119
|
+
@htauth.run(["-c", "-p", "-b", @tf.path, "bradley", "a bad password"])
|
120
|
+
rescue SystemExit => se
|
121
|
+
se.status.should == 0
|
122
|
+
IO.read(@tf.path).strip.should == "bradley:a bad password"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "updates an entry in an existing file and force crypt" do
|
127
|
+
before_lines = IO.readlines(@tf.path)
|
128
|
+
begin
|
129
|
+
@stdin.puts "a new secret"
|
130
|
+
@stdin.puts "a new secret"
|
131
|
+
@stdin.rewind
|
132
|
+
@htauth.run([ "-d", @tf.path, "alice" ])
|
133
|
+
rescue SystemExit => se
|
134
|
+
@stderr.string.should == ""
|
135
|
+
se.status.should == 0
|
136
|
+
after_lines = IO.readlines(@tf.path)
|
137
|
+
after_lines.size.should == before_lines.size
|
138
|
+
|
139
|
+
a_b = before_lines.first.split(":")
|
140
|
+
a_a = after_lines.first.split(":")
|
141
|
+
|
142
|
+
a_b.first.should == a_a.first
|
143
|
+
a_b.last.should_not == a_a.last
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
it "deletes an entry in an existing file" do
|
148
|
+
begin
|
149
|
+
@htauth.run([ "-D", @tf.path, "bob" ])
|
150
|
+
rescue SystemExit => se
|
151
|
+
@stderr.string.should == ""
|
152
|
+
se.status.should == 0
|
153
|
+
IO.read(@tf.path).should == IO.read(PASSWD_DELETE_TEST_FILE)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it "sends to STDOUT when the -n option is used" do
|
158
|
+
begin
|
159
|
+
@htauth.run(["-n", "-p", "-b", "bradley", "a bad password"])
|
160
|
+
rescue SystemExit => se
|
161
|
+
se.status.should == 0
|
162
|
+
STDOUT.puts @stdout.string
|
163
|
+
@stdout.string.strip.should == "bradley:a bad password"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
it "has an error if it does not have permissions on the file" do
|
168
|
+
begin
|
169
|
+
@stdin.puts "a secret"
|
170
|
+
@stdin.puts "a secret"
|
171
|
+
@stdin.rewind
|
172
|
+
@htauth.run([ "-c", "/etc/you-cannot-create-me", "alice"])
|
173
|
+
rescue SystemExit => se
|
174
|
+
@stderr.string.should =~ %r{Password file failure \(/etc/you-cannot-create-me\)}m
|
175
|
+
se.status.should == 1
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
it "has an error if the input passwords do not match" do
|
180
|
+
begin
|
181
|
+
@stdin.puts "a secret"
|
182
|
+
@stdin.puts "a bad secret"
|
183
|
+
@stdin.rewind
|
184
|
+
@htauth.run([ @tf.path, "alice"])
|
185
|
+
rescue SystemExit => se
|
186
|
+
@stderr.string.should =~ /They don't match, sorry./m
|
187
|
+
se.status.should == 1
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
it "has an error if the options are incorrect" do
|
192
|
+
begin
|
193
|
+
@htauth.run(["--blah"])
|
194
|
+
rescue SystemExit => se
|
195
|
+
@stderr.string.should =~ /ERROR:/m
|
196
|
+
se.status.should == 1
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
it "errors if send to stdout and create a new file options are both used" do
|
201
|
+
begin
|
202
|
+
@htauth.run(["-c", "-n"])
|
203
|
+
rescue SystemExit => se
|
204
|
+
@stderr.string.should =~ /ERROR:/m
|
205
|
+
se.status.should == 1
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__),"spec_helper.rb")
|
4
|
+
|
5
|
+
require 'htauth/sha1'
|
6
|
+
|
7
|
+
describe HTAuth::Plaintext do
|
8
|
+
it "has a prefix" do
|
9
|
+
HTAuth::Plaintext.new.prefix.should == ""
|
10
|
+
end
|
11
|
+
|
12
|
+
it "encrypts the same way that apache does" do
|
13
|
+
apache_result = "a secret"
|
14
|
+
pt = HTAuth::Plaintext.new
|
15
|
+
pt.encode("a secret").should == apache_result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
data/spec/sha1_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__),"spec_helper.rb")
|
3
|
+
|
4
|
+
require 'htauth/sha1'
|
5
|
+
|
6
|
+
describe HTAuth::Sha1 do
|
7
|
+
it "has a prefix" do
|
8
|
+
HTAuth::Sha1.new.prefix.should == "{SHA}"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "encrypts the same way that apache does" do
|
12
|
+
apache_result = "{SHA}ZrnlrvmM7ZCOV3FAvM7la89NKbk="
|
13
|
+
sha1 = HTAuth::Sha1.new
|
14
|
+
sha1.encode("a secret").should == apache_result
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
|
5
|
+
require 'htauth'
|
6
|
+
|
7
|
+
PASSWD_ORIGINAL_TEST_FILE = File.join(File.dirname(__FILE__), "test.original.passwd")
|
8
|
+
PASSWD_ADD_TEST_FILE = File.join(File.dirname(__FILE__), "test.add.passwd")
|
9
|
+
PASSWD_UPDATE_TEST_FILE = File.join(File.dirname(__FILE__), "test.update.passwd")
|
10
|
+
PASSWD_DELETE_TEST_FILE = File.join(File.dirname(__FILE__), "test.delete.passwd")
|
11
|
+
PASSWD_COMMENTED_TEST_FILE = File.join(File.dirname(__FILE__), "test.comments.passwd")
|
12
|
+
|
13
|
+
DIGEST_ORIGINAL_TEST_FILE = File.join(File.dirname(__FILE__), "test.original.digest")
|
14
|
+
DIGEST_ADD_TEST_FILE = File.join(File.dirname(__FILE__), "test.add.digest")
|
15
|
+
DIGEST_UPDATE_TEST_FILE = File.join(File.dirname(__FILE__), "test.update.digest")
|
16
|
+
DIGEST_DELETE_TEST_FILE = File.join(File.dirname(__FILE__), "test.delete.digest")
|
17
|
+
DIGEST_COMMENTED_TEST_FILE = File.join(File.dirname(__FILE__), "test.comments.digest")
|
@@ -0,0 +1 @@
|
|
1
|
+
bob:htauth:fcbeab6821d2ab3b00934c958db0fd1e
|
@@ -0,0 +1 @@
|
|
1
|
+
alice:$apr1$DghnA...$CsPcgerfsI/Ryy0AOAJtb0
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: htauth
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2008-02-06 00:00:00 -07:00
|
8
|
+
summary: HTAuth provides htdigest and htpasswd support.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: jeremy@hinegardner.org
|
12
|
+
homepage: http://copiousfreetime.rubyforge.org/htauth
|
13
|
+
rubyforge_project: copiousfreetime
|
14
|
+
description: HTAuth is a pure ruby replacement for the Apache support programs htdigest and htpasswd. Command line and API access are provided for access to htdigest and htpasswd files.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message: |
|
29
|
+
Try out 'htpasswd-ruby' or 'htdigest-ruby' to get started.
|
30
|
+
|
31
|
+
authors:
|
32
|
+
- Jeremy Hinegardner
|
33
|
+
files:
|
34
|
+
- spec/crypt_spec.rb
|
35
|
+
- spec/digest_entry_spec.rb
|
36
|
+
- spec/digest_file_spec.rb
|
37
|
+
- spec/digest_spec.rb
|
38
|
+
- spec/md5_spec.rb
|
39
|
+
- spec/passwd_entry_spec.rb
|
40
|
+
- spec/passwd_file_spec.rb
|
41
|
+
- spec/passwd_spec.rb
|
42
|
+
- spec/plaintext_spec.rb
|
43
|
+
- spec/sha1_spec.rb
|
44
|
+
- spec/spec_helper.rb
|
45
|
+
- spec/test.add.digest
|
46
|
+
- spec/test.add.passwd
|
47
|
+
- spec/test.delete.digest
|
48
|
+
- spec/test.delete.passwd
|
49
|
+
- spec/test.original.digest
|
50
|
+
- spec/test.original.passwd
|
51
|
+
- spec/test.update.digest
|
52
|
+
- spec/test.update.passwd
|
53
|
+
- CHANGES
|
54
|
+
- LICENSE
|
55
|
+
- README
|
56
|
+
- lib/htauth/algorithm.rb
|
57
|
+
- lib/htauth/crypt.rb
|
58
|
+
- lib/htauth/digest.rb
|
59
|
+
- lib/htauth/digest_entry.rb
|
60
|
+
- lib/htauth/digest_file.rb
|
61
|
+
- lib/htauth/entry.rb
|
62
|
+
- lib/htauth/file.rb
|
63
|
+
- lib/htauth/gemspec.rb
|
64
|
+
- lib/htauth/md5.rb
|
65
|
+
- lib/htauth/passwd.rb
|
66
|
+
- lib/htauth/passwd_entry.rb
|
67
|
+
- lib/htauth/passwd_file.rb
|
68
|
+
- lib/htauth/plaintext.rb
|
69
|
+
- lib/htauth/sha1.rb
|
70
|
+
- lib/htauth/specification.rb
|
71
|
+
- lib/htauth/version.rb
|
72
|
+
- lib/htauth.rb
|
73
|
+
- bin/htdigest-ruby
|
74
|
+
- bin/htpasswd-ruby
|
75
|
+
test_files:
|
76
|
+
- spec/crypt_spec.rb
|
77
|
+
- spec/digest_entry_spec.rb
|
78
|
+
- spec/digest_file_spec.rb
|
79
|
+
- spec/digest_spec.rb
|
80
|
+
- spec/md5_spec.rb
|
81
|
+
- spec/passwd_entry_spec.rb
|
82
|
+
- spec/passwd_file_spec.rb
|
83
|
+
- spec/passwd_spec.rb
|
84
|
+
- spec/plaintext_spec.rb
|
85
|
+
- spec/sha1_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
- spec/test.add.digest
|
88
|
+
- spec/test.add.passwd
|
89
|
+
- spec/test.delete.digest
|
90
|
+
- spec/test.delete.passwd
|
91
|
+
- spec/test.original.digest
|
92
|
+
- spec/test.original.passwd
|
93
|
+
- spec/test.update.digest
|
94
|
+
- spec/test.update.passwd
|
95
|
+
rdoc_options:
|
96
|
+
- --line-numbers
|
97
|
+
- --inline-source
|
98
|
+
- --main
|
99
|
+
- README
|
100
|
+
- --title
|
101
|
+
- "'htauth -- HTAuth provides htdigest and htpasswd support.'"
|
102
|
+
extra_rdoc_files:
|
103
|
+
- CHANGES
|
104
|
+
- LICENSE
|
105
|
+
- README
|
106
|
+
executables:
|
107
|
+
- htdigest-ruby
|
108
|
+
- htpasswd-ruby
|
109
|
+
extensions: []
|
110
|
+
|
111
|
+
requirements: []
|
112
|
+
|
113
|
+
dependencies:
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: highline
|
116
|
+
version_requirement:
|
117
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 1.4.0
|
122
|
+
version:
|