htauth 1.0.1 → 1.0.2

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.
@@ -2,96 +2,96 @@ require 'htauth/entry'
2
2
  require 'htauth/algorithm'
3
3
 
4
4
  module HTAuth
5
- class InvalidPasswdEntry < StandardError ; end
5
+ class InvalidPasswdEntry < StandardError ; end
6
6
 
7
- # A single record in an htdigest file.
8
- class PasswdEntry < Entry
7
+ # A single record in an htdigest file.
8
+ class PasswdEntry < Entry
9
9
 
10
- attr_accessor :user
11
- attr_accessor :digest
12
- attr_reader :algorithm
10
+ attr_accessor :user
11
+ attr_accessor :digest
12
+ attr_reader :algorithm
13
13
 
14
- class << self
15
- def from_line(line)
16
- parts = is_entry!(line)
17
- d = PasswdEntry.new(parts[0])
18
- d.digest = parts[1]
19
- d.algorithm = Algorithm.algorithms_from_field(parts[1])
20
- return d
21
- end
14
+ class << self
15
+ def from_line(line)
16
+ parts = is_entry!(line)
17
+ d = PasswdEntry.new(parts[0])
18
+ d.digest = parts[1]
19
+ d.algorithm = Algorithm.algorithms_from_field(parts[1])
20
+ return d
21
+ end
22
22
 
23
- # test if a line is an entry, raise InvalidPasswdEntry if it is not.
24
- # an entry must be composed of 2 parts, username:encrypted_password
25
- # where username, and password do not contain the ':' character
26
- def is_entry!(line)
27
- raise InvalidPasswdEntry, "line commented out" if line =~ /\A#/
28
- parts = line.strip.split(":")
29
- raise InvalidPasswdEntry, "line must be of the format username:pssword" if parts.size != 2
30
- return parts
31
- end
23
+ # test if a line is an entry, raise InvalidPasswdEntry if it is not.
24
+ # an entry must be composed of 2 parts, username:encrypted_password
25
+ # where username, and password do not contain the ':' character
26
+ def is_entry!(line)
27
+ raise InvalidPasswdEntry, "line commented out" if line =~ /\A#/
28
+ parts = line.strip.split(":")
29
+ raise InvalidPasswdEntry, "line must be of the format username:pssword" if parts.size != 2
30
+ return parts
31
+ end
32
32
 
33
- # test if a line is an entry and return true or false
34
- def is_entry?(line)
35
- begin
36
- is_entry!(line)
37
- return true
38
- rescue InvalidPasswdEntry
39
- return false
40
- end
41
- end
33
+ # test if a line is an entry and return true or false
34
+ def is_entry?(line)
35
+ begin
36
+ is_entry!(line)
37
+ return true
38
+ rescue InvalidPasswdEntry
39
+ return false
42
40
  end
41
+ end
42
+ end
43
43
 
44
- def initialize(user, password = "", alg = Algorithm::DEFAULT, alg_params = {} )
45
- @user = user
46
- alg = Algorithm::DEFAULT if alg == Algorithm::EXISTING
47
- @algorithm = Algorithm.algorithm_from_name(alg, alg_params)
48
- @digest = algorithm.encode(password)
49
- end
44
+ def initialize(user, password = "", alg = Algorithm::DEFAULT, alg_params = {} )
45
+ @user = user
46
+ alg = Algorithm::DEFAULT if alg == Algorithm::EXISTING
47
+ @algorithm = Algorithm.algorithm_from_name(alg, alg_params)
48
+ @digest = algorithm.encode(password)
49
+ end
50
50
 
51
- def algorithm=(alg)
52
- if alg.kind_of?(Array) then
53
- if alg.size == 1 then
54
- @algorithm = alg.first
55
- else
56
- @algorithm = alg
57
- end
58
- else
59
- @algorithm = Algorithm.algorithm_from_name(alg) unless Algorithm::EXISTING == alg
60
- end
61
- return @algorithm
51
+ def algorithm=(alg)
52
+ if alg.kind_of?(Array) then
53
+ if alg.size == 1 then
54
+ @algorithm = alg.first
55
+ else
56
+ @algorithm = alg
62
57
  end
58
+ else
59
+ @algorithm = Algorithm.algorithm_from_name(alg) unless Algorithm::EXISTING == alg
60
+ end
61
+ return @algorithm
62
+ end
63
63
 
64
- def password=(new_password)
65
- if algorithm.kind_of?(Array) then
66
- @algorithm = Algorithm.algorithm_from_name("crypt")
67
- end
68
- @digest = algorithm.encode(new_password)
69
- end
64
+ def password=(new_password)
65
+ if algorithm.kind_of?(Array) then
66
+ @algorithm = Algorithm.algorithm_from_name("crypt")
67
+ end
68
+ @digest = algorithm.encode(new_password)
69
+ end
70
70
 
71
- # check the password and make sure it works, in the case that the algorithm is unknown it
72
- # tries all of the ones that it thinks it could be, and marks the algorithm if it matches
73
- def authenticated?(check_password)
74
- authed = false
75
- if algorithm.kind_of?(Array) then
76
- algorithm.each do |alg|
77
- if alg.encode(check_password) == digest then
78
- @algorithm = alg
79
- authed = true
80
- break
81
- end
82
- end
83
- else
84
- authed = digest == algorithm.encode(check_password)
85
- end
86
- return authed
71
+ # check the password and make sure it works, in the case that the algorithm is unknown it
72
+ # tries all of the ones that it thinks it could be, and marks the algorithm if it matches
73
+ def authenticated?(check_password)
74
+ authed = false
75
+ if algorithm.kind_of?(Array) then
76
+ algorithm.each do |alg|
77
+ if alg.encode(check_password) == digest then
78
+ @algorithm = alg
79
+ authed = true
80
+ break
81
+ end
87
82
  end
83
+ else
84
+ authed = digest == algorithm.encode(check_password)
85
+ end
86
+ return authed
87
+ end
88
88
 
89
- def key
90
- return "#{user}"
91
- end
89
+ def key
90
+ return "#{user}"
91
+ end
92
92
 
93
- def to_s
94
- "#{user}:#{digest}"
95
- end
93
+ def to_s
94
+ "#{user}:#{digest}"
96
95
  end
96
+ end
97
97
  end
@@ -73,10 +73,6 @@ module HTAuth
73
73
  ENTRY_KLASS
74
74
  end
75
75
 
76
- def file_type
77
- "passwd"
78
- end
79
-
80
76
  private
81
77
 
82
78
  def internal_record(username)
@@ -1,19 +1,22 @@
1
1
  require 'htauth'
2
2
  module HTAuth
3
- class Version
4
- MAJOR = 1
5
- MINOR = 0
6
- BUILD = 1
3
+ module Version
4
+ MAJOR = 1
5
+ MINOR = 0
6
+ BUILD = 2
7
7
 
8
- class << self
9
- def to_a
10
- [MAJOR, MINOR, BUILD]
11
- end
8
+ def to_a
9
+ [MAJOR, MINOR, BUILD]
10
+ end
12
11
 
13
- def to_s
14
- to_a.join(".")
15
- end
16
- end
12
+ def to_s
13
+ to_a.join(".")
17
14
  end
18
- VERSION = Version.to_s
15
+
16
+ module_function :to_a
17
+ module_function :to_s
18
+
19
+ STRING = Version.to_s
20
+ end
21
+ VERSION = Version.to_s
19
22
  end
@@ -0,0 +1,38 @@
1
+ require 'tasks/config'
2
+ #-------------------------------------------------------------------------------
3
+ # announcement methods
4
+ #-------------------------------------------------------------------------------
5
+
6
+ proj_config = Configuration.for('project')
7
+ namespace :announce do
8
+ desc "create email for ruby-talk"
9
+ task :email do
10
+ info = Utils.announcement
11
+
12
+ File.open("email.txt", "w") do |mail|
13
+ mail.puts "From: #{proj_config.author} <#{proj_config.email}>"
14
+ mail.puts "To: ruby-talk@ruby-lang.org"
15
+ mail.puts "Date: #{Time.now.rfc2822}"
16
+ mail.puts "Subject: [ANN] #{info[:subject]}"
17
+ mail.puts
18
+ mail.puts info[:title]
19
+ mail.puts
20
+ mail.puts info[:urls]
21
+ mail.puts
22
+ mail.puts info[:description]
23
+ mail.puts
24
+ mail.puts "{{ Release notes for Version #{HTAuth::VERSION} }}"
25
+ mail.puts
26
+ mail.puts info[:release_notes]
27
+ mail.puts
28
+ mail.puts info[:urls]
29
+ end
30
+ puts "Created the following as email.txt:"
31
+ puts "-" * 72
32
+ puts File.read("email.txt")
33
+ puts "-" * 72
34
+ end
35
+
36
+ CLOBBER << "email.txt"
37
+ end
38
+
@@ -0,0 +1,98 @@
1
+ require 'configuration'
2
+
3
+ require 'rake'
4
+ require 'tasks/utils'
5
+
6
+ #-----------------------------------------------------------------------
7
+ # General project configuration
8
+ #-----------------------------------------------------------------------
9
+ Configuration.for('project') {
10
+ name "htauth"
11
+ version "1.0.1"
12
+ author "Jeremy Hinegardner"
13
+ email "jeremy@copiousfreetime.org"
14
+ homepage "http://copiousfreetime.rubyforge.org/htauth"
15
+ description Utils.section_of("README", "description")
16
+ summary description.split(".").first
17
+ history "HISTORY"
18
+ license FileList["LICENSE", ]
19
+ readme "README"
20
+ }
21
+
22
+ #-----------------------------------------------------------------------
23
+ # Packaging
24
+ #-----------------------------------------------------------------------
25
+ Configuration.for('packaging') {
26
+ # files in the project
27
+ proj_conf = Configuration.for('project')
28
+ files {
29
+ bin FileList["bin/*"]
30
+ lib FileList["lib/**/*.rb"]
31
+ test FileList["spec/**/*.rb", "test/**/*.rb"]
32
+ data FileList["data/**/*"]
33
+ tasks FileList["tasks/**/*.r{ake,b}"]
34
+ rdoc FileList[proj_conf.readme, proj_conf.history,
35
+ proj_conf.license] + lib
36
+ all bin + lib + test + data + rdoc + tasks
37
+ }
38
+
39
+ # ways to package the results
40
+ formats {
41
+ tgz true
42
+ zip true
43
+ rubygem Configuration::Table.has_key?('rubygem')
44
+ }
45
+ }
46
+
47
+ #-----------------------------------------------------------------------
48
+ # Gem packaging
49
+ #-----------------------------------------------------------------------
50
+ Configuration.for("rubygem") {
51
+ spec "gemspec.rb"
52
+ Configuration.for('packaging').files.all << spec
53
+ }
54
+
55
+ #-----------------------------------------------------------------------
56
+ # Testing
57
+ # - change mode to 'testunit' to use unit testing
58
+ #-----------------------------------------------------------------------
59
+ Configuration.for('test') {
60
+ mode "spec"
61
+ files Configuration.for("packaging").files.test
62
+ options %w[ --format specdoc --color ]
63
+ ruby_opts %w[ ]
64
+ }
65
+
66
+ #-----------------------------------------------------------------------
67
+ # Rcov
68
+ #-----------------------------------------------------------------------
69
+ Configuration.for('rcov') {
70
+ output_dir "coverage"
71
+ libs %w[ lib ]
72
+ rcov_opts %w[ --html ]
73
+ ruby_opts %w[ ]
74
+ test_files Configuration.for('packaging').files.test
75
+ }
76
+
77
+ #-----------------------------------------------------------------------
78
+ # Rdoc
79
+ #-----------------------------------------------------------------------
80
+ Configuration.for('rdoc') {
81
+ files Configuration.for('packaging').files.rdoc
82
+ main_page files.first
83
+ title Configuration.for('project').name
84
+ options %w[ --line-numbers --inline-source ]
85
+ output_dir "doc"
86
+ }
87
+
88
+ #-----------------------------------------------------------------------
89
+ # Rubyforge
90
+ #-----------------------------------------------------------------------
91
+ Configuration.for('rubyforge') {
92
+ project "copiousfreetime"
93
+ user "jjh"
94
+ host "rubyforge.org"
95
+ rdoc_location "#{user}@#{host}:/var/www/gforge-projects/#{project}/htauth"
96
+ }
97
+
98
+
@@ -0,0 +1,46 @@
1
+ require 'tasks/config'
2
+
3
+ #-------------------------------------------------------------------------------
4
+ # Distribution and Packaging
5
+ #-------------------------------------------------------------------------------
6
+ if pkg_config = Configuration.for_if_exist?("packaging") then
7
+
8
+ require 'gemspec'
9
+ require 'rake/gempackagetask'
10
+ require 'rake/contrib/sshpublisher'
11
+
12
+ namespace :dist do
13
+
14
+ Rake::GemPackageTask.new(HTAuth::GEM_SPEC) do |pkg|
15
+ pkg.need_tar = pkg_config.formats.tgz
16
+ pkg.need_zip = pkg_config.formats.zip
17
+ end
18
+
19
+ desc "Install as a gem"
20
+ task :install => [:clobber, :package] do
21
+ sh "sudo gem install pkg/#{HTAuth::GEM_SPEC.full_name}.gem"
22
+ end
23
+
24
+ desc "Uninstall gem"
25
+ task :uninstall do
26
+ sh "sudo gem uninstall -x #{HTAuth::GEM_SPEC.name}"
27
+ end
28
+
29
+ desc "dump gemspec"
30
+ task :gemspec do
31
+ puts HTAuth::GEM_SPEC.to_ruby
32
+ end
33
+
34
+ desc "distribute copiously"
35
+ task :copious => [ :package ] do
36
+ Rake::SshFilePublisher.new('jeremy@copiousfreetime.org',
37
+ '/var/www/vhosts/www.copiousfreetime.org/htdocs/gems/gems',
38
+ 'pkg' ,"#{HTAuth::GEM_SPEC.full_name}.gem").upload
39
+ sh "ssh jeremy@copiousfreetime.org rake -f /var/www/vhosts/www.copiousfreetime.org/htdocs/gems/Rakefile"
40
+ end
41
+
42
+ desc "reinstall gem"
43
+ task :reinstall => [:uninstall, :repackage, :install]
44
+
45
+ end
46
+ end
@@ -0,0 +1,31 @@
1
+ require 'tasks/config'
2
+
3
+ #-----------------------------------------------------------------------
4
+ # Documentation
5
+ #-----------------------------------------------------------------------
6
+
7
+ if rdoc_config = Configuration.for_if_exist?('rdoc') then
8
+
9
+ namespace :doc do
10
+
11
+ require 'rake/rdoctask'
12
+
13
+ # generating documentation locally
14
+ Rake::RDocTask.new do |rdoc|
15
+ rdoc.rdoc_dir = rdoc_config.output_dir
16
+ rdoc.options = rdoc_config.options
17
+ rdoc.rdoc_files = rdoc_config.files
18
+ rdoc.title = rdoc_config.title
19
+ rdoc.main = rdoc_config.main_page
20
+ end
21
+
22
+ if rubyforge_config = Configuration.for_if_exist?('rubyforge') then
23
+ desc "Deploy the RDoc documentation to #{rubyforge_config.rdoc_location}"
24
+ task :deploy => :rerdoc do
25
+ sh "rsync -zav --delete #{rdoc_config.output_dir}/ #{rubyforge_config.rdoc_location}"
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+
@@ -0,0 +1,29 @@
1
+
2
+ require 'tasks/config'
3
+
4
+ #--------------------------------------------------------------------------------
5
+ # configuration for running rspec. This shows up as the test:default task
6
+ #--------------------------------------------------------------------------------
7
+ if spec_config = Configuration.for_if_exist?("test") then
8
+ if spec_config.mode == "spec" then
9
+ namespace :test do
10
+
11
+ task :default => :spec
12
+
13
+ require 'spec/rake/spectask'
14
+ Spec::Rake::SpecTask.new do |r|
15
+ r.ruby_opts = spec_config.ruby_opts
16
+ r.libs = [ HTAuth.lib_path,
17
+ HTAuth.root_dir ]
18
+ r.spec_files = spec_config.files
19
+ r.spec_opts = spec_config.options
20
+
21
+ if rcov_config = Configuration.for_if_exist?('rcov') then
22
+ r.rcov = true
23
+ r.rcov_dir = rcov_config.output_dir
24
+ r.rcov_opts = rcov_config.rcov_opts
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end