r509-validity-redis 0.3
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/README.md +30 -0
- data/Rakefile +36 -0
- data/doc/Kernel.html +174 -0
- data/doc/R509/Validity/Redis/Checker.html +409 -0
- data/doc/R509/Validity/Redis/Writer.html +556 -0
- data/doc/R509/Validity/Redis.html +129 -0
- data/doc/R509/Validity.html +115 -0
- data/doc/R509.html +115 -0
- data/doc/_index.html +175 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +328 -0
- data/doc/file.README.html +107 -0
- data/doc/file_list.html +55 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +107 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +124 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/r509/validity/redis/checker.rb +30 -0
- data/lib/r509/validity/redis/version.rb +7 -0
- data/lib/r509/validity/redis/writer.rb +43 -0
- data/lib/r509/validity/redis.rb +15 -0
- data/spec/checker_spec.rb +68 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/writer_spec.rb +127 -0
- metadata +144 -0
@@ -0,0 +1,124 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<base id="base_target" target="_parent" />
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
<script type="text/javascript" charset="utf-8">
|
22
|
+
if (window.top.frames.main) {
|
23
|
+
document.getElementById('base_target').target = 'main';
|
24
|
+
document.body.className = 'frames';
|
25
|
+
}
|
26
|
+
</script>
|
27
|
+
<div id="content">
|
28
|
+
<h1 id="full_list_header">Method List</h1>
|
29
|
+
<div id="nav">
|
30
|
+
|
31
|
+
<span><a target="_self" href="class_list.html">
|
32
|
+
Classes
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="method_list.html">
|
36
|
+
Methods
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
<span><a target="_self" href="file_list.html">
|
40
|
+
Files
|
41
|
+
</a></span>
|
42
|
+
|
43
|
+
</div>
|
44
|
+
<div id="search">Search: <input type="text" /></div>
|
45
|
+
|
46
|
+
<ul id="full_list" class="method">
|
47
|
+
|
48
|
+
|
49
|
+
<li class="r1 ">
|
50
|
+
<span class='object_link'><a href="R509/Validity/Redis/Checker.html#check-instance_method" title="R509::Validity::Redis::Checker#check (method)">#check</a></span>
|
51
|
+
|
52
|
+
<small>R509::Validity::Redis::Checker</small>
|
53
|
+
|
54
|
+
</li>
|
55
|
+
|
56
|
+
|
57
|
+
<li class="r2 ">
|
58
|
+
<span class='object_link'><a href="R509/Validity/Redis/Writer.html#initialize-instance_method" title="R509::Validity::Redis::Writer#initialize (method)">#initialize</a></span>
|
59
|
+
|
60
|
+
<small>R509::Validity::Redis::Writer</small>
|
61
|
+
|
62
|
+
</li>
|
63
|
+
|
64
|
+
|
65
|
+
<li class="r1 ">
|
66
|
+
<span class='object_link'><a href="R509/Validity/Redis/Checker.html#initialize-instance_method" title="R509::Validity::Redis::Checker#initialize (method)">#initialize</a></span>
|
67
|
+
|
68
|
+
<small>R509::Validity::Redis::Checker</small>
|
69
|
+
|
70
|
+
</li>
|
71
|
+
|
72
|
+
|
73
|
+
<li class="r2 ">
|
74
|
+
<span class='object_link'><a href="R509/Validity/Redis/Checker.html#is_available%3F-instance_method" title="R509::Validity::Redis::Checker#is_available? (method)">#is_available?</a></span>
|
75
|
+
|
76
|
+
<small>R509::Validity::Redis::Checker</small>
|
77
|
+
|
78
|
+
</li>
|
79
|
+
|
80
|
+
|
81
|
+
<li class="r1 ">
|
82
|
+
<span class='object_link'><a href="R509/Validity/Redis/Writer.html#is_available%3F-instance_method" title="R509::Validity::Redis::Writer#is_available? (method)">#is_available?</a></span>
|
83
|
+
|
84
|
+
<small>R509::Validity::Redis::Writer</small>
|
85
|
+
|
86
|
+
</li>
|
87
|
+
|
88
|
+
|
89
|
+
<li class="r2 ">
|
90
|
+
<span class='object_link'><a href="R509/Validity/Redis/Writer.html#issue-instance_method" title="R509::Validity::Redis::Writer#issue (method)">#issue</a></span>
|
91
|
+
|
92
|
+
<small>R509::Validity::Redis::Writer</small>
|
93
|
+
|
94
|
+
</li>
|
95
|
+
|
96
|
+
|
97
|
+
<li class="r1 ">
|
98
|
+
<span class='object_link'><a href="Kernel.html#require_relative-instance_method" title="Kernel#require_relative (method)">#require_relative</a></span>
|
99
|
+
|
100
|
+
<small>Kernel</small>
|
101
|
+
|
102
|
+
</li>
|
103
|
+
|
104
|
+
|
105
|
+
<li class="r2 ">
|
106
|
+
<span class='object_link'><a href="R509/Validity/Redis/Writer.html#revoke-instance_method" title="R509::Validity::Redis::Writer#revoke (method)">#revoke</a></span>
|
107
|
+
|
108
|
+
<small>R509::Validity::Redis::Writer</small>
|
109
|
+
|
110
|
+
</li>
|
111
|
+
|
112
|
+
|
113
|
+
<li class="r1 ">
|
114
|
+
<span class='object_link'><a href="R509/Validity/Redis/Writer.html#unrevoke-instance_method" title="R509::Validity::Redis::Writer#unrevoke (method)">#unrevoke</a></span>
|
115
|
+
|
116
|
+
<small>R509::Validity::Redis::Writer</small>
|
117
|
+
|
118
|
+
</li>
|
119
|
+
|
120
|
+
|
121
|
+
</ul>
|
122
|
+
</div>
|
123
|
+
</body>
|
124
|
+
</html>
|
@@ -0,0 +1,112 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Top Level Namespace
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.2.1
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!" + escape(window.location.href);
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index</a> »
|
35
|
+
|
36
|
+
|
37
|
+
<span class="title">Top Level Namespace</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Top Level Namespace
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
</dl>
|
82
|
+
<div class="clear"></div>
|
83
|
+
|
84
|
+
<h2>Defined Under Namespace</h2>
|
85
|
+
<p class="children">
|
86
|
+
|
87
|
+
|
88
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Kernel.html" title="Kernel (module)">Kernel</a></span>, <span class='object_link'><a href="R509.html" title="R509 (module)">R509</a></span>
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
</p>
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
</div>
|
104
|
+
|
105
|
+
<div id="footer">
|
106
|
+
Generated on Mon Oct 15 10:51:03 2012 by
|
107
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
|
+
0.8.2.1 (ruby-1.9.3).
|
109
|
+
</div>
|
110
|
+
|
111
|
+
</body>
|
112
|
+
</html>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "r509"
|
2
|
+
|
3
|
+
module R509::Validity::Redis
|
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
|
+
|
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
|
+
|
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
|
+
|
26
|
+
def is_available?
|
27
|
+
(@redis.ping == "PONG")? true : false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "r509"
|
2
|
+
|
3
|
+
module R509::Validity::Redis
|
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
|
+
|
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
|
+
|
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
|
+
|
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
|
+
|
39
|
+
def is_available?
|
40
|
+
(@redis.ping == "PONG")? true : false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'r509'
|
2
|
+
|
3
|
+
unless Kernel.respond_to?(:require_relative)
|
4
|
+
module Kernel
|
5
|
+
def require_relative(path)
|
6
|
+
require File.join(File.dirname(caller[0]), path.to_str)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module R509::Validity::Redis
|
12
|
+
require_relative('redis/checker.rb')
|
13
|
+
require_relative('redis/writer.rb')
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe R509::Validity::Redis::Checker do
|
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")
|
7
|
+
end
|
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
|
59
|
+
end
|
60
|
+
|
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
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
if (RUBY_VERSION.split('.')[1].to_i > 8)
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
end
|
5
|
+
|
6
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
7
|
+
$:.unshift File.expand_path("../", __FILE__)
|
8
|
+
require 'rubygems'
|
9
|
+
#require 'fixtures'
|
10
|
+
require 'rspec'
|
11
|
+
require 'r509/validity/redis'
|
data/spec/writer_spec.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe R509::Validity::Redis::Writer do
|
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")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
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")
|
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
|
+
|
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)
|
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
|
+
|
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)
|
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
|
+
|
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
|
+
|
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
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|