r509-validity-redis 0.4.1 → 0.4.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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +17 -14
- data/doc/Kernel.html +3 -3
- data/doc/R509.html +2 -2
- data/doc/R509/Validity.html +2 -2
- data/doc/R509/Validity/Redis.html +3 -3
- data/doc/R509/Validity/Redis/Checker.html +17 -17
- data/doc/R509/Validity/Redis/Writer.html +25 -25
- data/doc/_index.html +2 -2
- data/doc/file.README.html +18 -15
- data/doc/index.html +18 -15
- data/doc/top-level-namespace.html +2 -2
- data/lib/r509/validity/redis.rb +6 -6
- data/lib/r509/validity/redis/checker.rb +22 -22
- data/lib/r509/validity/redis/version.rb +4 -4
- data/lib/r509/validity/redis/writer.rb +34 -34
- data/spec/checker_spec.rb +60 -60
- data/spec/spec_helper.rb +2 -4
- data/spec/writer_spec.rb +113 -113
- metadata +74 -39
- metadata.gz.sig +0 -0
@@ -1,30 +1,30 @@
|
|
1
1
|
require "r509"
|
2
2
|
|
3
3
|
module R509::Validity::Redis
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
class Checker < R509::Validity::Checker
|
5
|
+
def initialize(redis)
|
6
|
+
raise ArgumentError.new("Redis must be provided") if redis.nil?
|
7
|
+
@redis = redis
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# @return [R509::Validity::Status]
|
11
|
+
def check(issuer,serial)
|
12
|
+
raise ArgumentError.new("Serial and issuer must be provided") if serial.to_s.empty? or issuer.to_s.empty?
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
hash = @redis.hgetall("cert:#{issuer}:#{serial}")
|
15
|
+
if not hash.nil? and hash.has_key?("status")
|
16
|
+
R509::Validity::Status.new(
|
17
|
+
:status => hash["status"].to_i,
|
18
|
+
:revocation_time => hash["revocation_time"].to_i || nil,
|
19
|
+
:revocation_reason => hash["revocation_reason"].to_i || 0
|
20
|
+
)
|
21
|
+
else
|
22
|
+
R509::Validity::Status.new(:status => R509::Validity::UNKNOWN)
|
23
|
+
end
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
26
|
+
def is_available?
|
27
|
+
(@redis.ping == "PONG")? true : false
|
29
28
|
end
|
29
|
+
end
|
30
30
|
end
|
@@ -1,43 +1,43 @@
|
|
1
1
|
require "r509"
|
2
2
|
|
3
3
|
module R509::Validity::Redis
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
class Writer < R509::Validity::Writer
|
5
|
+
def initialize(redis)
|
6
|
+
raise ArgumentError.new("Redis must be provided") if redis.nil?
|
7
|
+
@redis = redis
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
def issue(issuer, serial)
|
11
|
+
raise ArgumentError.new("Serial and issuer must be provided") if serial.to_s.empty? or issuer.to_s.empty?
|
12
|
+
cert = @redis.hgetall("cert:#{issuer}:#{serial}")
|
13
|
+
if cert.nil? or not cert.has_key?("status")
|
14
|
+
@redis.hmset("cert:#{issuer}:#{serial}", "status", 0)
|
15
|
+
else
|
16
|
+
raise R509::R509Error.new("Serial #{serial} for issuer #{issuer} is already present")
|
17
|
+
end
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
def revoke(issuer, serial, revocation_time=Time.now.to_i, reason=0)
|
21
|
+
raise ArgumentError.new("Serial and issuer must be provided") if serial.to_s.empty? or issuer.to_s.empty?
|
22
|
+
@redis.hmset("cert:#{issuer}:#{serial}",
|
23
|
+
"status", 1,
|
24
|
+
"revocation_time", revocation_time || Time.now.to_i,
|
25
|
+
"revocation_reason", reason || 0
|
26
|
+
)
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
def unrevoke(issuer, serial)
|
30
|
+
raise ArgumentError.new("Serial and issuer must be provided") if serial.to_s.empty? or issuer.to_s.empty?
|
31
|
+
cert = @redis.hgetall("cert:#{issuer}:#{serial}")
|
32
|
+
if cert.nil? or not cert.has_key?("status")
|
33
|
+
raise R509::R509Error.new("Serial #{serial} for issuer #{issuer} is not present")
|
34
|
+
else
|
35
|
+
@redis.hmset("cert:#{issuer}:#{serial}", "status", 0)
|
36
|
+
end
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
39
|
+
def is_available?
|
40
|
+
(@redis.ping == "PONG")? true : false
|
42
41
|
end
|
42
|
+
end
|
43
43
|
end
|
data/spec/checker_spec.rb
CHANGED
@@ -1,68 +1,68 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe R509::Validity::Redis::Checker do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
4
|
+
context "constructor" do
|
5
|
+
it "when redis is nil" do
|
6
|
+
expect { R509::Validity::Redis::Checker.new(nil) }.to raise_error(ArgumentError, "Redis must be provided")
|
8
7
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
8
|
+
end
|
9
|
+
context "check" do
|
10
|
+
it "throws an exception when issuer is nil/empty string" do
|
11
|
+
redis = double("redis")
|
12
|
+
checker = R509::Validity::Redis::Checker.new(redis)
|
13
|
+
expect { checker.check(nil,123) }.to raise_error(ArgumentError, "Serial and issuer must be provided")
|
14
|
+
end
|
15
|
+
it "throws an exception when serial is nil/empty string" do
|
16
|
+
redis = double("redis")
|
17
|
+
checker = R509::Validity::Redis::Checker.new(redis)
|
18
|
+
expect { checker.check("abcdef",nil) }.to raise_error(ArgumentError, "Serial and issuer must be provided")
|
19
|
+
end
|
20
|
+
it "gets unknown when serial is not found (returns {})" do
|
21
|
+
redis = double("redis")
|
22
|
+
checker = R509::Validity::Redis::Checker.new(redis)
|
23
|
+
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return({})
|
24
|
+
status = checker.check("abcdef",123)
|
25
|
+
status.status.should == R509::Validity::UNKNOWN
|
26
|
+
end
|
27
|
+
it "gets unknown when serial is not found (returns nil)" do
|
28
|
+
redis = double("redis")
|
29
|
+
checker = R509::Validity::Redis::Checker.new(redis)
|
30
|
+
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return(nil)
|
31
|
+
status = checker.check("abcdef",123)
|
32
|
+
status.status.should == R509::Validity::UNKNOWN
|
33
|
+
end
|
34
|
+
it "gets valid" do
|
35
|
+
redis = double("redis")
|
36
|
+
checker = R509::Validity::Redis::Checker.new(redis)
|
37
|
+
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return({"status" => "0" })
|
38
|
+
status = checker.check("abcdef",123)
|
39
|
+
status.status.should == R509::Validity::VALID
|
40
|
+
status.revocation_time.should == 0
|
41
|
+
status.revocation_reason.should == 0
|
42
|
+
end
|
43
|
+
it "gets revoked with revocation time and reason" do
|
44
|
+
redis = double("redis")
|
45
|
+
checker = R509::Validity::Redis::Checker.new(redis)
|
46
|
+
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return({"status" => "1", "revocation_time" => "789", "revocation_reason" => "5" })
|
47
|
+
status = checker.check("abcdef",123)
|
48
|
+
status.status.should == R509::Validity::REVOKED
|
49
|
+
status.revocation_time.should == 789
|
50
|
+
status.revocation_reason.should == 5
|
51
|
+
end
|
52
|
+
end
|
53
|
+
context "is available" do
|
54
|
+
it "returns true if redis is available" do
|
55
|
+
redis = double("redis")
|
56
|
+
redis.should_receive(:ping).and_return("PONG")
|
57
|
+
checker = R509::Validity::Redis::Checker.new(redis)
|
58
|
+
checker.is_available?.should == true
|
52
59
|
end
|
53
|
-
context "is available" do
|
54
|
-
it "returns true if redis is available" do
|
55
|
-
redis = double("redis")
|
56
|
-
redis.should_receive(:ping).and_return("PONG")
|
57
|
-
checker = R509::Validity::Redis::Checker.new(redis)
|
58
|
-
checker.is_available?.should == true
|
59
|
-
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
61
|
+
it "raises error if redis is unavailable" do
|
62
|
+
redis = double("redis")
|
63
|
+
redis.should_receive(:ping).and_return(StandardError)
|
64
|
+
checker = R509::Validity::Redis::Checker.new(redis)
|
65
|
+
checker.is_available?.should == false
|
67
66
|
end
|
67
|
+
end
|
68
68
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/writer_spec.rb
CHANGED
@@ -1,127 +1,127 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe R509::Validity::Redis::Writer do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
4
|
+
context "constructor" do
|
5
|
+
it "when redis is nil" do
|
6
|
+
expect { R509::Validity::Redis::Writer.new(nil) }.to raise_error(ArgumentError, "Redis must be provided")
|
8
7
|
end
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
it "when serial is nil/empty string" do
|
17
|
-
redis = double("redis")
|
18
|
-
writer = R509::Validity::Redis::Writer.new(redis)
|
19
|
-
expect { writer.issue("abcdef",nil) }.to raise_error(ArgumentError, "Serial and issuer must be provided")
|
20
|
-
end
|
21
|
-
it "when serial/issuer is provided (check returns nil)" do
|
22
|
-
redis = double("redis")
|
23
|
-
writer = R509::Validity::Redis::Writer.new(redis)
|
24
|
-
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return(nil)
|
25
|
-
redis.should_receive(:hmset).with("cert:abcdef:123", "status", 0)
|
26
|
-
writer.issue("abcdef",123)
|
27
|
-
end
|
28
|
-
it "when serial/issuer is provided (check returns {})" do
|
29
|
-
redis = double("redis")
|
30
|
-
writer = R509::Validity::Redis::Writer.new(redis)
|
31
|
-
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return({})
|
32
|
-
redis.should_receive(:hmset).with("cert:abcdef:123", "status", 0)
|
33
|
-
writer.issue("abcdef",123)
|
34
|
-
end
|
35
|
-
it "when serial/issuer is already present" do
|
36
|
-
redis = double("redis")
|
37
|
-
writer = R509::Validity::Redis::Writer.new(redis)
|
38
|
-
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return({"status"=>0})
|
39
|
-
expect { writer.issue("abcdef",123) }.to raise_error(R509::R509Error, "Serial 123 for issuer abcdef is already present")
|
40
|
-
end
|
10
|
+
context "issue" do
|
11
|
+
it "when issuer is nil/empty string" do
|
12
|
+
redis = double("redis")
|
13
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
14
|
+
expect { writer.issue(nil,123) }.to raise_error(ArgumentError, "Serial and issuer must be provided")
|
41
15
|
end
|
16
|
+
it "when serial is nil/empty string" do
|
17
|
+
redis = double("redis")
|
18
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
19
|
+
expect { writer.issue("abcdef",nil) }.to raise_error(ArgumentError, "Serial and issuer must be provided")
|
20
|
+
end
|
21
|
+
it "when serial/issuer is provided (check returns nil)" do
|
22
|
+
redis = double("redis")
|
23
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
24
|
+
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return(nil)
|
25
|
+
redis.should_receive(:hmset).with("cert:abcdef:123", "status", 0)
|
26
|
+
writer.issue("abcdef",123)
|
27
|
+
end
|
28
|
+
it "when serial/issuer is provided (check returns {})" do
|
29
|
+
redis = double("redis")
|
30
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
31
|
+
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return({})
|
32
|
+
redis.should_receive(:hmset).with("cert:abcdef:123", "status", 0)
|
33
|
+
writer.issue("abcdef",123)
|
34
|
+
end
|
35
|
+
it "when serial/issuer is already present" do
|
36
|
+
redis = double("redis")
|
37
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
38
|
+
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return({"status"=>0})
|
39
|
+
expect { writer.issue("abcdef",123) }.to raise_error(R509::R509Error, "Serial 123 for issuer abcdef is already present")
|
40
|
+
end
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
it "when time is provided, but not reason" do
|
67
|
-
redis = double("redis")
|
68
|
-
writer = R509::Validity::Redis::Writer.new(redis)
|
69
|
-
redis.should_receive(:hmset).with("cert:abcdef:123", "status", 1, "revocation_time", 100, "revocation_reason", 0)
|
70
|
-
writer.revoke("abcdef",123, 100)
|
71
|
-
end
|
72
|
-
it "when time and reason are provided" do
|
73
|
-
redis = double("redis")
|
74
|
-
writer = R509::Validity::Redis::Writer.new(redis)
|
75
|
-
redis.should_receive(:hmset).with("cert:abcdef:123", "status", 1, "revocation_time", 100, "revocation_reason", 2)
|
76
|
-
writer.revoke("abcdef",123, 100, 2)
|
77
|
-
end
|
43
|
+
context "revoke" do
|
44
|
+
it "when issuer is nil/empty string" do
|
45
|
+
redis = double("redis")
|
46
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
47
|
+
expect { writer.revoke(nil,123) }.to raise_error(ArgumentError, "Serial and issuer must be provided")
|
48
|
+
end
|
49
|
+
it "when serial is nil/empty string" do
|
50
|
+
redis = double("redis")
|
51
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
52
|
+
expect { writer.revoke("abcdef",nil) }.to raise_error(ArgumentError, "Serial and issuer must be provided")
|
53
|
+
end
|
54
|
+
it "when time and reason aren't provided" do
|
55
|
+
redis = double("redis")
|
56
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
57
|
+
redis.should_receive(:hmset).with("cert:abcdef:123", "status", 1, "revocation_time", Time.now.to_i, "revocation_reason", 0)
|
58
|
+
writer.revoke("abcdef",123)
|
59
|
+
end
|
60
|
+
it "when time and reason are nil" do
|
61
|
+
redis = double("redis")
|
62
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
63
|
+
redis.should_receive(:hmset).with("cert:abcdef:123", "status", 1, "revocation_time", Time.now.to_i, "revocation_reason", 0)
|
64
|
+
writer.revoke("abcdef",123, nil, nil)
|
78
65
|
end
|
66
|
+
it "when time is provided, but not reason" do
|
67
|
+
redis = double("redis")
|
68
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
69
|
+
redis.should_receive(:hmset).with("cert:abcdef:123", "status", 1, "revocation_time", 100, "revocation_reason", 0)
|
70
|
+
writer.revoke("abcdef",123, 100)
|
71
|
+
end
|
72
|
+
it "when time and reason are provided" do
|
73
|
+
redis = double("redis")
|
74
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
75
|
+
redis.should_receive(:hmset).with("cert:abcdef:123", "status", 1, "revocation_time", 100, "revocation_reason", 2)
|
76
|
+
writer.revoke("abcdef",123, 100, 2)
|
77
|
+
end
|
78
|
+
end
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
it "when cert record doesn't exist (nil)" do
|
99
|
-
redis = double("redis")
|
100
|
-
writer = R509::Validity::Redis::Writer.new(redis)
|
101
|
-
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return(nil)
|
102
|
-
expect { writer.unrevoke("abcdef",123) }.to raise_error(R509::R509Error, "Serial 123 for issuer abcdef is not present")
|
103
|
-
end
|
104
|
-
it "when cert record doesn't exist ({})" do
|
105
|
-
redis = double("redis")
|
106
|
-
writer = R509::Validity::Redis::Writer.new(redis)
|
107
|
-
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return({})
|
108
|
-
expect { writer.unrevoke("abcdef",123) }.to raise_error(R509::R509Error, "Serial 123 for issuer abcdef is not present")
|
109
|
-
end
|
80
|
+
context "unrevoke" do
|
81
|
+
it "when issuer is nil/empty string" do
|
82
|
+
redis = double("redis")
|
83
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
84
|
+
expect { writer.unrevoke(nil,123) }.to raise_error(ArgumentError, "Serial and issuer must be provided")
|
85
|
+
end
|
86
|
+
it "when serial is nil/empty string" do
|
87
|
+
redis = double("redis")
|
88
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
89
|
+
expect { writer.unrevoke("abcdef",nil) }.to raise_error(ArgumentError, "Serial and issuer must be provided")
|
90
|
+
end
|
91
|
+
it "when serial/issuer is provided" do
|
92
|
+
redis = double("redis")
|
93
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
94
|
+
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return({"status" => 1})
|
95
|
+
redis.should_receive(:hmset).with("cert:abcdef:123", "status", 0)
|
96
|
+
writer.unrevoke("abcdef",123)
|
110
97
|
end
|
98
|
+
it "when cert record doesn't exist (nil)" do
|
99
|
+
redis = double("redis")
|
100
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
101
|
+
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return(nil)
|
102
|
+
expect { writer.unrevoke("abcdef",123) }.to raise_error(R509::R509Error, "Serial 123 for issuer abcdef is not present")
|
103
|
+
end
|
104
|
+
it "when cert record doesn't exist ({})" do
|
105
|
+
redis = double("redis")
|
106
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
107
|
+
redis.should_receive(:hgetall).with("cert:abcdef:123").and_return({})
|
108
|
+
expect { writer.unrevoke("abcdef",123) }.to raise_error(R509::R509Error, "Serial 123 for issuer abcdef is not present")
|
109
|
+
end
|
110
|
+
end
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
112
|
+
context "is available" do
|
113
|
+
it "returns true if redis is available" do
|
114
|
+
redis = double("redis")
|
115
|
+
redis.should_receive(:ping).and_return("PONG")
|
116
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
117
|
+
writer.is_available?.should == true
|
118
|
+
end
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
120
|
+
it "raises error if redis is unavailable" do
|
121
|
+
redis = double("redis")
|
122
|
+
redis.should_receive(:ping).and_return(StandardError)
|
123
|
+
writer = R509::Validity::Redis::Writer.new(redis)
|
124
|
+
writer.is_available?.should == false
|
126
125
|
end
|
126
|
+
end
|
127
127
|
end
|