authtools 0.2.0 → 0.3.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/CHANGELOG +7 -0
- data/Rakefile +10 -18
- data/VERSION +1 -1
- data/authtools.gemspec +10 -5
- data/lib/authtools/token.rb +15 -20
- data/spec/authtools_spec.rb +76 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +8 -0
- metadata +8 -6
- data/TODO +0 -3
data/CHANGELOG
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
Authtools changelog.
|
2
2
|
|
3
|
+
v0.3.0 [4.07.2010]
|
4
|
+
* Added specs
|
5
|
+
* Added symbolic names for token sizes (:tiny, :short, :medium, :long)
|
6
|
+
* Added tiny (128bit) md5-like token
|
7
|
+
* Minor improvments
|
8
|
+
* TODO empty
|
9
|
+
|
3
10
|
v0.2.0 [4.07.2010]
|
4
11
|
* Improvements in implementation
|
5
12
|
* Minor bug fixes
|
data/Rakefile
CHANGED
@@ -16,29 +16,21 @@ rescue LoadError
|
|
16
16
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
17
17
|
end
|
18
18
|
|
19
|
-
require 'rake/
|
20
|
-
Rake::
|
21
|
-
|
22
|
-
|
23
|
-
test.verbose = true
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
|
+
spec.libs << 'lib' << 'spec'
|
22
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
24
23
|
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
test.pattern = 'test/**/test_*.rb'
|
31
|
-
test.verbose = true
|
32
|
-
end
|
33
|
-
rescue LoadError
|
34
|
-
task :rcov do
|
35
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
-
end
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
28
|
+
spec.rcov = true
|
37
29
|
end
|
38
30
|
|
39
|
-
task :
|
31
|
+
task :spec => :check_dependencies
|
40
32
|
|
41
|
-
task :default => :
|
33
|
+
task :default => :spec
|
42
34
|
|
43
35
|
require 'rake/rdoctask'
|
44
36
|
Rake::RDocTask.new do |rdoc|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/authtools.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{authtools}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kris Kowalik"]
|
@@ -15,8 +15,7 @@ h or unique token and check if specified password string is valid for stored has
|
|
15
15
|
s.email = %q{kriss.kowalik@gmail.com}
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE",
|
18
|
-
"README.rdoc"
|
19
|
-
"TODO"
|
18
|
+
"README.rdoc"
|
20
19
|
]
|
21
20
|
s.files = [
|
22
21
|
".gitignore",
|
@@ -24,19 +23,25 @@ h or unique token and check if specified password string is valid for stored has
|
|
24
23
|
"LICENSE",
|
25
24
|
"README.rdoc",
|
26
25
|
"Rakefile",
|
27
|
-
"TODO",
|
28
26
|
"VERSION",
|
29
27
|
"authtools.gemspec",
|
30
28
|
"lib/authtools.rb",
|
31
29
|
"lib/authtools/common.rb",
|
32
30
|
"lib/authtools/password.rb",
|
33
|
-
"lib/authtools/token.rb"
|
31
|
+
"lib/authtools/token.rb",
|
32
|
+
"spec/authtools_spec.rb",
|
33
|
+
"spec/spec.opts",
|
34
|
+
"spec/spec_helper.rb"
|
34
35
|
]
|
35
36
|
s.homepage = %q{http://github.com/kriss/authtools}
|
36
37
|
s.rdoc_options = ["--charset=UTF-8"]
|
37
38
|
s.require_paths = ["lib"]
|
38
39
|
s.rubygems_version = %q{1.3.6}
|
39
40
|
s.summary = %q{Usefull staff for tokens, passwords and authorization}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/spec_helper.rb",
|
43
|
+
"spec/authtools_spec.rb"
|
44
|
+
]
|
40
45
|
|
41
46
|
if s.respond_to? :specification_version then
|
42
47
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/lib/authtools/token.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'digest/sha2'
|
2
|
+
require 'digest/md5'
|
2
3
|
require 'authtools/common'
|
3
4
|
|
4
5
|
module Authtools
|
@@ -6,15 +7,21 @@ module Authtools
|
|
6
7
|
extend Common
|
7
8
|
extend self
|
8
9
|
|
9
|
-
|
10
|
+
TINY = 128
|
11
|
+
SHORT = 256
|
10
12
|
MEDIUM = 384
|
11
|
-
LONG
|
13
|
+
LONG = 512
|
12
14
|
|
13
15
|
# Generates new token with specified size.
|
14
16
|
#
|
15
17
|
def generate(size=SHORT)
|
16
|
-
|
17
|
-
|
18
|
+
size = const_get(size.to_s.upcase) if [:tiny, :short, :medium, :long].include?(size)
|
19
|
+
if size > 128
|
20
|
+
hash = Digest::SHA2.new(size)
|
21
|
+
hash << self.salt
|
22
|
+
else
|
23
|
+
hash = Digest::MD5.hexdigest(self.salt)
|
24
|
+
end
|
18
25
|
hash.to_s
|
19
26
|
end
|
20
27
|
|
@@ -24,22 +31,10 @@ module Authtools
|
|
24
31
|
generate(size)
|
25
32
|
end
|
26
33
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
# Shortcut for generate 384 bit token.
|
34
|
-
#
|
35
|
-
def medium
|
36
|
-
generate(MEDIUM)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Shortcut for generate 512 bit token.
|
40
|
-
#
|
41
|
-
def long
|
42
|
-
generate(LONG)
|
34
|
+
%w{tiny short medium long}.each do |label|
|
35
|
+
module_eval do
|
36
|
+
define_method(label) { generate(label.to_sym) }
|
37
|
+
end
|
43
38
|
end
|
44
39
|
end
|
45
40
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "Authtools" do
|
4
|
+
describe "Password" do
|
5
|
+
it "should be properly extended by Authtools::Common" do
|
6
|
+
Authtools::Password.should respond_to :salt
|
7
|
+
end
|
8
|
+
|
9
|
+
before do
|
10
|
+
@hash = Authtools::Password.generate('secret')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should allow to generate hash based on given string" do
|
14
|
+
@hash.should_not be_nil
|
15
|
+
@hash.size.should == 192
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should allow to retrieve salt from stored hash" do
|
19
|
+
salt = Authtools::Password.get_salt(@hash)
|
20
|
+
salt.should_not be_nil
|
21
|
+
salt.size.should == 64
|
22
|
+
@hash.match(/#{salt}\Z/).should_not be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should allow to check if given hash was generated from specified password" do
|
26
|
+
Authtools::Password.check('secret', @hash).should == true
|
27
|
+
Authtools::Password.check('not secret', @hash).should == false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "Token" do
|
32
|
+
it "should be properly extended by Authtools::Common" do
|
33
|
+
Authtools::Token.should respond_to :salt
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should define shortcuts for each token size" do
|
37
|
+
Authtools::Token.should respond_to :tiny
|
38
|
+
Authtools::Token.should respond_to :short
|
39
|
+
Authtools::Token.should respond_to :medium
|
40
|
+
Authtools::Token.should respond_to :long
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should allow to generate 128bit random token" do
|
44
|
+
Authtools::Token.generate(:tiny).size.should == 32
|
45
|
+
Authtools::Token.tiny.size.should == 32
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should allow to generate 256bit random token" do
|
49
|
+
Authtools::Token.generate(:short).size.should == 64
|
50
|
+
Authtools::Token.short.size.should == 64
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should allow to generate 384bit random token" do
|
54
|
+
Authtools::Token.generate(:medium).size.should == 96
|
55
|
+
Authtools::Token.medium.size.should == 96
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should allow to generate 512bit random token" do
|
59
|
+
Authtools::Token.generate(:long).size.should == 128
|
60
|
+
Authtools::Token.long.size.should == 128
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should generate 256bit token by default" do
|
64
|
+
Authtools::Token.generate.size.should == 64
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "Common" do
|
69
|
+
include Authtools::Common
|
70
|
+
|
71
|
+
it "should provide method for generating pseudo-random salt" do
|
72
|
+
salt.should_not be_nil
|
73
|
+
salt.size.should == 64
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kris Kowalik
|
@@ -29,20 +29,21 @@ extensions: []
|
|
29
29
|
extra_rdoc_files:
|
30
30
|
- LICENSE
|
31
31
|
- README.rdoc
|
32
|
-
- TODO
|
33
32
|
files:
|
34
33
|
- .gitignore
|
35
34
|
- CHANGELOG
|
36
35
|
- LICENSE
|
37
36
|
- README.rdoc
|
38
37
|
- Rakefile
|
39
|
-
- TODO
|
40
38
|
- VERSION
|
41
39
|
- authtools.gemspec
|
42
40
|
- lib/authtools.rb
|
43
41
|
- lib/authtools/common.rb
|
44
42
|
- lib/authtools/password.rb
|
45
43
|
- lib/authtools/token.rb
|
44
|
+
- spec/authtools_spec.rb
|
45
|
+
- spec/spec.opts
|
46
|
+
- spec/spec_helper.rb
|
46
47
|
has_rdoc: true
|
47
48
|
homepage: http://github.com/kriss/authtools
|
48
49
|
licenses: []
|
@@ -73,5 +74,6 @@ rubygems_version: 1.3.6
|
|
73
74
|
signing_key:
|
74
75
|
specification_version: 3
|
75
76
|
summary: Usefull staff for tokens, passwords and authorization
|
76
|
-
test_files:
|
77
|
-
|
77
|
+
test_files:
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- spec/authtools_spec.rb
|