persistent-cache 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ module Persistent
14
14
  end
15
15
 
16
16
  def connect_to_database
17
- FileUtils.makedirs([@storage_root]) if not File.exists?(@storage_root)
17
+ FileUtils.makedirs([@storage_root]) if not File.exists?(@storage_root) or not File.directory?(@storage_root)
18
18
  end
19
19
 
20
20
  def save_key_value_pair(key, value, timestamp = nil)
@@ -34,12 +34,7 @@ module Persistent
34
34
  end
35
35
 
36
36
  def size
37
- count = Dir::glob("#{@storage_root}/**/").size
38
- # if the directory does not exist, count == 0, which is what we want
39
- return 0 if count == 0
40
- # if the directory does exist, but is empty, count == 1, namely the directory itself, and we want to return 0 (i.e. count - 1)
41
- # if the directory does exist and includes subdirectories, the directory itself is still counted as well, and we want to return count - 1
42
- return count - 1
37
+ count = Dir::glob("#{@storage_root}/**/#{CACHE_FILE}").size
43
38
  end
44
39
 
45
40
  def keys
@@ -122,6 +117,11 @@ module Persistent
122
117
 
123
118
  def validate_key(key)
124
119
  raise ArgumentError.new("Only string keys allowed") if not key.is_a?(String)
120
+ root_path = Pathname.new(File.absolute_path(@storage_root))
121
+ key_path = Pathname.new(File.absolute_path(compile_key_path(key)))
122
+ relative = key_path.relative_path_from(root_path).to_s
123
+ raise ArgumentError.new("key is outside of storage_root scope") if relative.start_with?("../")
124
+ raise ArgumentError.new("key is the same as storage_root") if relative == "."
125
125
  end
126
126
 
127
127
  def empty_key_value(key)
@@ -165,6 +165,5 @@ module Persistent
165
165
  output.write(value)
166
166
  output.flush
167
167
  end
168
-
169
168
  end
170
169
  end
@@ -1,5 +1,5 @@
1
1
  module Persistent
2
2
  class Cache
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -17,7 +17,6 @@ describe Persistent::StorageDirectory do
17
17
 
18
18
  context "when constructed" do
19
19
  it "should create the database if it does not exist" do
20
- #debugger
21
20
  result = File.exists?(@db_name)
22
21
  expect(result).to eq(true)
23
22
  end
@@ -85,6 +84,15 @@ describe Persistent::StorageDirectory do
85
84
  }.to raise_error ArgumentError
86
85
  end
87
86
 
87
+ it "should raise an ArgumentError if a key is requested that traverses above the storage root" do
88
+ expect {
89
+ @iut.lookup_key("/../../secure-stuff-i-should-not-have-access-to")
90
+ }.to raise_error(ArgumentError)
91
+ expect {
92
+ @iut.lookup_key(".")
93
+ }.to raise_error(ArgumentError)
94
+ end
95
+
88
96
  it "should raise an ArgumentError if the value is not a string" do
89
97
  expect {
90
98
  @iut.save_key_value_pair(@test_key, 1234)
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: persistent-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Wynand van Dyk
@@ -9,11 +10,12 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2015-04-24 00:00:00.000000000 Z
13
+ date: 2015-05-05 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rspec
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
20
  - - '='
19
21
  - !ruby/object:Gem::Version
@@ -21,6 +23,7 @@ dependencies:
21
23
  type: :development
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
28
  - - '='
26
29
  - !ruby/object:Gem::Version
@@ -28,6 +31,7 @@ dependencies:
28
31
  - !ruby/object:Gem::Dependency
29
32
  name: simplecov
30
33
  requirement: !ruby/object:Gem::Requirement
34
+ none: false
31
35
  requirements:
32
36
  - - ! '>='
33
37
  - !ruby/object:Gem::Version
@@ -35,6 +39,7 @@ dependencies:
35
39
  type: :development
36
40
  prerelease: false
37
41
  version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
38
43
  requirements:
39
44
  - - ! '>='
40
45
  - !ruby/object:Gem::Version
@@ -42,6 +47,7 @@ dependencies:
42
47
  - !ruby/object:Gem::Dependency
43
48
  name: simplecov-rcov
44
49
  requirement: !ruby/object:Gem::Requirement
50
+ none: false
45
51
  requirements:
46
52
  - - ! '>='
47
53
  - !ruby/object:Gem::Version
@@ -49,6 +55,7 @@ dependencies:
49
55
  type: :development
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
52
59
  requirements:
53
60
  - - ! '>='
54
61
  - !ruby/object:Gem::Version
@@ -56,6 +63,7 @@ dependencies:
56
63
  - !ruby/object:Gem::Dependency
57
64
  name: debugger
58
65
  requirement: !ruby/object:Gem::Requirement
66
+ none: false
59
67
  requirements:
60
68
  - - ! '>='
61
69
  - !ruby/object:Gem::Version
@@ -63,6 +71,7 @@ dependencies:
63
71
  type: :development
64
72
  prerelease: false
65
73
  version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
66
75
  requirements:
67
76
  - - ! '>='
68
77
  - !ruby/object:Gem::Version
@@ -70,6 +79,7 @@ dependencies:
70
79
  - !ruby/object:Gem::Dependency
71
80
  name: sqlite3
72
81
  requirement: !ruby/object:Gem::Requirement
82
+ none: false
73
83
  requirements:
74
84
  - - '='
75
85
  - !ruby/object:Gem::Version
@@ -77,6 +87,7 @@ dependencies:
77
87
  type: :runtime
78
88
  prerelease: false
79
89
  version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
80
91
  requirements:
81
92
  - - '='
82
93
  - !ruby/object:Gem::Version
@@ -84,6 +95,7 @@ dependencies:
84
95
  - !ruby/object:Gem::Dependency
85
96
  name: eh
86
97
  requirement: !ruby/object:Gem::Requirement
98
+ none: false
87
99
  requirements:
88
100
  - - ! '>='
89
101
  - !ruby/object:Gem::Version
@@ -91,6 +103,7 @@ dependencies:
91
103
  type: :runtime
92
104
  prerelease: false
93
105
  version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
94
107
  requirements:
95
108
  - - ! '>='
96
109
  - !ruby/object:Gem::Version
@@ -115,7 +128,6 @@ files:
115
128
  - lib/persistent-cache/storage/storage_ram.rb
116
129
  - lib/persistent-cache/storage/storage_sq_lite.rb
117
130
  - lib/persistent-cache/version.rb
118
- - multidb
119
131
  - persistent-cache.gemspec
120
132
  - spec/persistent-cache_spec.rb
121
133
  - spec/spec_helper.rb
@@ -124,26 +136,27 @@ files:
124
136
  - spec/storage/storage_sqlite_spec.rb
125
137
  homepage: ''
126
138
  licenses: []
127
- metadata: {}
128
139
  post_install_message:
129
140
  rdoc_options: []
130
141
  require_paths:
131
142
  - lib
132
143
  required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
133
145
  requirements:
134
146
  - - ! '>='
135
147
  - !ruby/object:Gem::Version
136
148
  version: '0'
137
149
  required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
138
151
  requirements:
139
152
  - - ! '>='
140
153
  - !ruby/object:Gem::Version
141
154
  version: '0'
142
155
  requirements: []
143
156
  rubyforge_project:
144
- rubygems_version: 2.2.1
157
+ rubygems_version: 1.8.28
145
158
  signing_key:
146
- specification_version: 4
159
+ specification_version: 3
147
160
  summary: Persistent Cache has a default freshness threshold of 179 days after which
148
161
  entries are no longer returned
149
162
  test_files:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OWY0N2Y0ZmU4YmE3ZDRhMTAwNDg4MmU2YmUyNDE1ZjZhZDgzZWJlNQ==
5
- data.tar.gz: !binary |-
6
- NjZiMjdhYWYyYWM4ZjY1YmFiOWJkNThhOTUzNjdjZjE1NTcxNWI3MA==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- YWRhODc0MGYwNjNjOGI3ZTg0NTEwMmM2NWI2OGQ3NDgxOWU2ZTIxNWVkY2Y0
10
- OThkOTAxYTljNDIxNTQ2NzA5ZTY0ZTg0MmRmOWJmMjRkMzM3ZGE4YTg3OWVi
11
- NDBlZjcyOGU1OGJjZDg2M2IzYmU5NDZlZmFkYzllY2FmMTk3YTc=
12
- data.tar.gz: !binary |-
13
- M2NkMjJkZWRmN2I1MWUyYWZlYzZhOTg1NTZlYjYyZWJkNmY2ODY1NjIxNzYx
14
- YzQyMTI0Y2JjOWFmMzkwMTEzZDFhMTg3ZGJmM2MxMjM4OWI3YTk1OGQyMDU5
15
- OTU1ZjgxZWUzODI0ZGMwNDQ4NzRkNWQyMWY4ZmY3NmVlN2I4Mzc=
data/multidb DELETED
Binary file