htauth 2.3.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.
- checksums.yaml +4 -4
- data/HISTORY.md +14 -0
- data/Manifest.txt +4 -28
- data/exe/htdigest-ruby +14 -0
- data/exe/htpasswd-ruby +14 -0
- data/htauth.gemspec +33 -0
- data/lib/htauth/algorithm.rb +30 -29
- data/lib/htauth/argon2.rb +45 -36
- data/lib/htauth/bcrypt.rb +12 -11
- data/lib/htauth/cli/digest.rb +42 -46
- data/lib/htauth/cli/passwd.rb +126 -115
- data/lib/htauth/cli.rb +5 -3
- data/lib/htauth/console.rb +9 -6
- data/lib/htauth/crypt.rb +11 -9
- data/lib/htauth/descendant_tracker.rb +11 -9
- data/lib/htauth/digest_entry.rb +22 -20
- data/lib/htauth/digest_file.rb +25 -18
- data/lib/htauth/entry.rb +3 -1
- data/lib/htauth/error.rb +6 -5
- data/lib/htauth/file.rb +35 -39
- data/lib/htauth/md5.rb +35 -34
- data/lib/htauth/passwd_entry.rb +26 -24
- data/lib/htauth/passwd_file.rb +26 -21
- data/lib/htauth/plaintext.rb +7 -5
- data/lib/htauth/sha1.rb +9 -7
- data/lib/htauth/version.rb +3 -1
- data/lib/htauth.rb +29 -28
- metadata +15 -133
- data/Rakefile +0 -29
- data/bin/htdigest-ruby +0 -12
- data/bin/htpasswd-ruby +0 -12
- data/spec/algorithm_spec.rb +0 -7
- data/spec/argon2_spec.rb +0 -28
- data/spec/bcrypt_spec.rb +0 -32
- data/spec/cli/digest_spec.rb +0 -149
- data/spec/cli/passwd_spec.rb +0 -346
- data/spec/crypt_spec.rb +0 -11
- data/spec/digest_entry_spec.rb +0 -59
- data/spec/digest_file_spec.rb +0 -64
- data/spec/md5_spec.rb +0 -11
- data/spec/passwd_entry_spec.rb +0 -172
- data/spec/passwd_file_spec.rb +0 -84
- data/spec/plaintext_spec.rb +0 -11
- data/spec/sha1_spec.rb +0 -10
- data/spec/spec_helper.rb +0 -25
- data/spec/test.add.digest +0 -3
- data/spec/test.add.passwd +0 -3
- data/spec/test.delete.digest +0 -1
- data/spec/test.delete.passwd +0 -1
- data/spec/test.original.digest +0 -2
- data/spec/test.original.passwd +0 -2
- data/spec/test.update.digest +0 -2
- data/spec/test.update.passwd +0 -2
- data/tasks/default.rake +0 -250
- data/tasks/this.rb +0 -208
- /data/{LICENSE → LICENSE.txt} +0 -0
data/lib/htauth.rb
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
#--
|
|
2
4
|
# Copyrigth (c) 2008 Jeremy Hinegardner
|
|
3
5
|
# All rights reserved. See LICENSE and/or COPYING for details
|
|
4
6
|
#++
|
|
5
7
|
|
|
8
|
+
# Public: module wrapper for library
|
|
9
|
+
#
|
|
6
10
|
module HTAuth
|
|
7
|
-
|
|
8
11
|
# The root directory of the project is considered to be the parent directory
|
|
9
12
|
# of the 'lib' directory.
|
|
10
13
|
#
|
|
11
14
|
def self.root_dir
|
|
12
15
|
unless @root_dir
|
|
13
|
-
path_parts = ::File.expand_path(
|
|
14
|
-
lib_index = path_parts.rindex(
|
|
15
|
-
@root_dir = path_parts[
|
|
16
|
+
path_parts = ::File.expand_path(__FILE__).split(::File::SEPARATOR)
|
|
17
|
+
lib_index = path_parts.rindex("lib")
|
|
18
|
+
@root_dir = path_parts[0...lib_index].join(::File::SEPARATOR) + ::File::SEPARATOR
|
|
16
19
|
end
|
|
17
|
-
|
|
20
|
+
@root_dir
|
|
18
21
|
end
|
|
19
22
|
|
|
20
|
-
def self.lib_path(
|
|
21
|
-
|
|
23
|
+
def self.lib_path(*args)
|
|
24
|
+
sub_path("lib", *args)
|
|
22
25
|
end
|
|
23
26
|
|
|
24
|
-
def self.sub_path(
|
|
25
|
-
sp = ::File.join(
|
|
26
|
-
|
|
27
|
+
def self.sub_path(sub, *args)
|
|
28
|
+
sp = ::File.join(root_dir, sub) + ::File::SEPARATOR
|
|
29
|
+
::File.join(sp, *args) if args
|
|
27
30
|
end
|
|
28
|
-
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
require
|
|
32
|
-
require
|
|
33
|
-
require
|
|
34
|
-
require
|
|
35
|
-
require
|
|
36
|
-
require
|
|
37
|
-
require
|
|
38
|
-
require
|
|
39
|
-
require
|
|
40
|
-
require
|
|
41
|
-
require
|
|
42
|
-
require
|
|
43
|
-
require
|
|
44
|
-
require
|
|
45
|
-
require
|
|
46
|
-
|
|
33
|
+
require "htauth/version"
|
|
34
|
+
require "htauth/algorithm"
|
|
35
|
+
require "htauth/argon2"
|
|
36
|
+
require "htauth/bcrypt"
|
|
37
|
+
require "htauth/crypt"
|
|
38
|
+
require "htauth/digest_entry"
|
|
39
|
+
require "htauth/digest_file"
|
|
40
|
+
require "htauth/entry"
|
|
41
|
+
require "htauth/error"
|
|
42
|
+
require "htauth/file"
|
|
43
|
+
require "htauth/md5"
|
|
44
|
+
require "htauth/passwd_entry"
|
|
45
|
+
require "htauth/passwd_file"
|
|
46
|
+
require "htauth/plaintext"
|
|
47
|
+
require "htauth/sha1"
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: htauth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeremy Hinegardner
|
|
8
|
-
|
|
9
|
-
bindir: bin
|
|
8
|
+
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2026-05-23 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: bcrypt
|
|
@@ -39,89 +38,19 @@ dependencies:
|
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
39
|
version: '0.2'
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
41
|
+
name: ostruct
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
44
43
|
requirements:
|
|
45
44
|
- - "~>"
|
|
46
45
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
48
|
-
type: :
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '2.3'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: rake
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - "~>"
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '13.1'
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - "~>"
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '13.1'
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: minitest
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - "~>"
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '5.21'
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - "~>"
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '5.21'
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
|
-
name: minitest-junit
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - "~>"
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: '1.1'
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - "~>"
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: '1.1'
|
|
97
|
-
- !ruby/object:Gem::Dependency
|
|
98
|
-
name: rdoc
|
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
|
100
|
-
requirements:
|
|
101
|
-
- - "~>"
|
|
102
|
-
- !ruby/object:Gem::Version
|
|
103
|
-
version: '6.6'
|
|
104
|
-
type: :development
|
|
105
|
-
prerelease: false
|
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
-
requirements:
|
|
108
|
-
- - "~>"
|
|
109
|
-
- !ruby/object:Gem::Version
|
|
110
|
-
version: '6.6'
|
|
111
|
-
- !ruby/object:Gem::Dependency
|
|
112
|
-
name: simplecov
|
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
|
114
|
-
requirements:
|
|
115
|
-
- - "~>"
|
|
116
|
-
- !ruby/object:Gem::Version
|
|
117
|
-
version: '0.21'
|
|
118
|
-
type: :development
|
|
46
|
+
version: '0.6'
|
|
47
|
+
type: :runtime
|
|
119
48
|
prerelease: false
|
|
120
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
50
|
requirements:
|
|
122
51
|
- - "~>"
|
|
123
52
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: '0.
|
|
53
|
+
version: '0.6'
|
|
125
54
|
description: HTAuth provides an API and commandline tools for managing Apache/httpd
|
|
126
55
|
style htpasswd and htdigest files.
|
|
127
56
|
email: jeremy@copiousfreetime.org
|
|
@@ -132,17 +61,18 @@ extensions: []
|
|
|
132
61
|
extra_rdoc_files:
|
|
133
62
|
- CONTRIBUTING.md
|
|
134
63
|
- HISTORY.md
|
|
64
|
+
- LICENSE.txt
|
|
135
65
|
- Manifest.txt
|
|
136
66
|
- README.md
|
|
137
67
|
files:
|
|
138
68
|
- CONTRIBUTING.md
|
|
139
69
|
- HISTORY.md
|
|
140
|
-
- LICENSE
|
|
70
|
+
- LICENSE.txt
|
|
141
71
|
- Manifest.txt
|
|
142
72
|
- README.md
|
|
143
|
-
-
|
|
144
|
-
-
|
|
145
|
-
-
|
|
73
|
+
- exe/htdigest-ruby
|
|
74
|
+
- exe/htpasswd-ruby
|
|
75
|
+
- htauth.gemspec
|
|
146
76
|
- lib/htauth.rb
|
|
147
77
|
- lib/htauth/algorithm.rb
|
|
148
78
|
- lib/htauth/argon2.rb
|
|
@@ -164,30 +94,6 @@ files:
|
|
|
164
94
|
- lib/htauth/plaintext.rb
|
|
165
95
|
- lib/htauth/sha1.rb
|
|
166
96
|
- lib/htauth/version.rb
|
|
167
|
-
- spec/algorithm_spec.rb
|
|
168
|
-
- spec/argon2_spec.rb
|
|
169
|
-
- spec/bcrypt_spec.rb
|
|
170
|
-
- spec/cli/digest_spec.rb
|
|
171
|
-
- spec/cli/passwd_spec.rb
|
|
172
|
-
- spec/crypt_spec.rb
|
|
173
|
-
- spec/digest_entry_spec.rb
|
|
174
|
-
- spec/digest_file_spec.rb
|
|
175
|
-
- spec/md5_spec.rb
|
|
176
|
-
- spec/passwd_entry_spec.rb
|
|
177
|
-
- spec/passwd_file_spec.rb
|
|
178
|
-
- spec/plaintext_spec.rb
|
|
179
|
-
- spec/sha1_spec.rb
|
|
180
|
-
- spec/spec_helper.rb
|
|
181
|
-
- spec/test.add.digest
|
|
182
|
-
- spec/test.add.passwd
|
|
183
|
-
- spec/test.delete.digest
|
|
184
|
-
- spec/test.delete.passwd
|
|
185
|
-
- spec/test.original.digest
|
|
186
|
-
- spec/test.original.passwd
|
|
187
|
-
- spec/test.update.digest
|
|
188
|
-
- spec/test.update.passwd
|
|
189
|
-
- tasks/default.rake
|
|
190
|
-
- tasks/this.rb
|
|
191
97
|
homepage: http://github.com/copiousfreetime/htauth
|
|
192
98
|
licenses:
|
|
193
99
|
- MIT
|
|
@@ -196,7 +102,6 @@ metadata:
|
|
|
196
102
|
changelog_uri: https://github.com/copiousfreetime/htauth/blob/master/HISTORY.md
|
|
197
103
|
homepage_uri: https://github.com/copiousfreetime/htauth
|
|
198
104
|
source_code_uri: https://github.com/copiousfreetime/htauth
|
|
199
|
-
post_install_message:
|
|
200
105
|
rdoc_options:
|
|
201
106
|
- "--main"
|
|
202
107
|
- README.md
|
|
@@ -208,38 +113,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
208
113
|
requirements:
|
|
209
114
|
- - ">="
|
|
210
115
|
- !ruby/object:Gem::Version
|
|
211
|
-
version:
|
|
116
|
+
version: 3.0.0
|
|
212
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
118
|
requirements:
|
|
214
119
|
- - ">="
|
|
215
120
|
- !ruby/object:Gem::Version
|
|
216
121
|
version: '0'
|
|
217
122
|
requirements: []
|
|
218
|
-
rubygems_version:
|
|
219
|
-
signing_key:
|
|
123
|
+
rubygems_version: 4.0.10
|
|
220
124
|
specification_version: 4
|
|
221
125
|
summary: HTAuth provides an API and commandline tools for managing Apache/httpd style
|
|
222
126
|
htpasswd and htdigest files.
|
|
223
|
-
test_files:
|
|
224
|
-
- spec/algorithm_spec.rb
|
|
225
|
-
- spec/argon2_spec.rb
|
|
226
|
-
- spec/bcrypt_spec.rb
|
|
227
|
-
- spec/cli/digest_spec.rb
|
|
228
|
-
- spec/cli/passwd_spec.rb
|
|
229
|
-
- spec/crypt_spec.rb
|
|
230
|
-
- spec/digest_entry_spec.rb
|
|
231
|
-
- spec/digest_file_spec.rb
|
|
232
|
-
- spec/md5_spec.rb
|
|
233
|
-
- spec/passwd_entry_spec.rb
|
|
234
|
-
- spec/passwd_file_spec.rb
|
|
235
|
-
- spec/plaintext_spec.rb
|
|
236
|
-
- spec/sha1_spec.rb
|
|
237
|
-
- spec/spec_helper.rb
|
|
238
|
-
- spec/test.add.digest
|
|
239
|
-
- spec/test.add.passwd
|
|
240
|
-
- spec/test.delete.digest
|
|
241
|
-
- spec/test.delete.passwd
|
|
242
|
-
- spec/test.original.digest
|
|
243
|
-
- spec/test.original.passwd
|
|
244
|
-
- spec/test.update.digest
|
|
245
|
-
- spec/test.update.passwd
|
|
127
|
+
test_files: []
|
data/Rakefile
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# vim: syntax=ruby
|
|
2
|
-
load 'tasks/this.rb'
|
|
3
|
-
|
|
4
|
-
This.name = "htauth"
|
|
5
|
-
This.author = "Jeremy Hinegardner"
|
|
6
|
-
This.email = "jeremy@copiousfreetime.org"
|
|
7
|
-
This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
|
|
8
|
-
|
|
9
|
-
This.ruby_gemspec do |spec|
|
|
10
|
-
spec.add_dependency( 'bcrypt', '~> 3.1' )
|
|
11
|
-
spec.add_dependency( 'base64', '~> 0.2' )
|
|
12
|
-
|
|
13
|
-
spec.add_development_dependency( 'argon2' , '~> 2.3')
|
|
14
|
-
spec.add_development_dependency( 'rake' , '~> 13.1')
|
|
15
|
-
spec.add_development_dependency( 'minitest' , '~> 5.21' )
|
|
16
|
-
spec.add_development_dependency( 'minitest-junit' , '~> 1.1' )
|
|
17
|
-
spec.add_development_dependency( 'rdoc' , '~> 6.6' )
|
|
18
|
-
spec.add_development_dependency( 'simplecov', '~> 0.21' )
|
|
19
|
-
|
|
20
|
-
spec.metadata = {
|
|
21
|
-
"bug_tracker_uri" => "https://github.com/copiousfreetime/htauth/issues",
|
|
22
|
-
"changelog_uri" => "https://github.com/copiousfreetime/htauth/blob/master/HISTORY.md",
|
|
23
|
-
"homepage_uri" => "https://github.com/copiousfreetime/htauth",
|
|
24
|
-
"source_code_uri" => "https://github.com/copiousfreetime/htauth",
|
|
25
|
-
}
|
|
26
|
-
spec.license = "MIT"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
load 'tasks/default.rake'
|
data/bin/htdigest-ruby
DELETED
data/bin/htpasswd-ruby
DELETED
data/spec/algorithm_spec.rb
DELETED
data/spec/argon2_spec.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'argon2'
|
|
3
|
-
|
|
4
|
-
describe HTAuth::Argon2 do
|
|
5
|
-
|
|
6
|
-
it "decodes the hash back to the original options" do
|
|
7
|
-
hash = '$argon2id$v=19$m=65536,t=3,p=4$V1ln1M4o1RS7SzWHAtqyWQ$jEHi1Qo2FSBgLAPpOa1mPx6OD/twtjj8M1AlVZwamPg'
|
|
8
|
-
options = HTAuth::Argon2.extract_options_from_existing_password_field(hash)
|
|
9
|
-
_(options).must_equal ::Argon2::Profiles[:rfc_9106_low_memory]
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "encrypts the same way that argon2 does by default" do
|
|
13
|
-
argon2 = HTAuth::Argon2.new
|
|
14
|
-
hash = argon2.encode("a secret")
|
|
15
|
-
_(::Argon2::Password.verify_password('a secret', hash)).must_equal true
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "allow changing the parameters directly" do
|
|
19
|
-
hash = '$argon2id$v=19$m=262144,t=3,p=4$7DRAuE1yIHPHqISmcyaJTg$M0EErpbxqv8dvrMrQMoGDEA7KQCw67jGdXwtCbRINFs'
|
|
20
|
-
options = HTAuth::Argon2.extract_options_from_existing_password_field(hash)
|
|
21
|
-
|
|
22
|
-
options[:m_cost] = 11
|
|
23
|
-
|
|
24
|
-
argon2 = HTAuth::Argon2.new(options)
|
|
25
|
-
local_hash = argon2.encode("a secret")
|
|
26
|
-
_(::Argon2::Password.verify_password('a secret', local_hash)).must_equal true
|
|
27
|
-
end
|
|
28
|
-
end
|
data/spec/bcrypt_spec.rb
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe HTAuth::Bcrypt do
|
|
4
|
-
it "encrypts the same way that apache does by default" do
|
|
5
|
-
apache_hash = '$2y$05$X7XeXxp0uAO92AGG2P4/fu0mj7MrRDQnlBTkwZLd9rKiH2OUBb9/K'
|
|
6
|
-
reparsed = ::BCrypt::Password.new(apache_hash)
|
|
7
|
-
cost = reparsed.cost
|
|
8
|
-
|
|
9
|
-
_(cost).must_equal HTAuth::Bcrypt::DEFAULT_APACHE_COST
|
|
10
|
-
_(reparsed.is_password?("a secret")).must_equal true
|
|
11
|
-
|
|
12
|
-
bcrypt = HTAuth::Bcrypt.new(:cost => cost)
|
|
13
|
-
local_hash = bcrypt.encode("a secret")
|
|
14
|
-
|
|
15
|
-
_(local_hash.is_password?("a secret")).must_equal true
|
|
16
|
-
_(local_hash.cost).must_equal cost
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "encrypts the same way that apache does with different cost" do
|
|
20
|
-
apache_hash = '$2y$12$O3mBah33UilOkwXrS0kXuOPFBKLBCIp7V.AVvEZQcbnAM5SJLQnfq'
|
|
21
|
-
reparsed = ::BCrypt::Password.new(apache_hash)
|
|
22
|
-
cost = reparsed.cost
|
|
23
|
-
|
|
24
|
-
_(reparsed.is_password?("a secret")).must_equal true
|
|
25
|
-
|
|
26
|
-
bcrypt = HTAuth::Bcrypt.new(:cost => cost)
|
|
27
|
-
local_hash = bcrypt.encode("a secret")
|
|
28
|
-
|
|
29
|
-
_(local_hash.is_password?("a secret")).must_equal true
|
|
30
|
-
_(local_hash.cost).must_equal cost
|
|
31
|
-
end
|
|
32
|
-
end
|
data/spec/cli/digest_spec.rb
DELETED
|
@@ -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
|