cache_rules 0.1.1
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/.gitignore +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +47 -0
- data/LICENSE +340 -0
- data/NOTICE +26 -0
- data/README.md +145 -0
- data/Rakefile +14 -0
- data/cache_rules.gemspec +34 -0
- data/lib/actions.rb +40 -0
- data/lib/cache_rules.rb +188 -0
- data/lib/formatting.rb +161 -0
- data/lib/helpers.rb +326 -0
- data/lib/validations.rb +111 -0
- data/test/helper.rb +18 -0
- data/test/test_cache_rules.rb +253 -0
- data/test/test_formatting.rb +135 -0
- data/test/test_helpers.rb +396 -0
- data/test/test_tables.rb +75 -0
- data/test/test_validations.rb +206 -0
- metadata +132 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
class TestValidations < MiniTest::Test
|
|
2
|
+
|
|
3
|
+
def setup
|
|
4
|
+
cache_control = {"max-stale"=>{"token"=>9999999, "quoted_string"=>nil},"only-if-cached"=>{"token"=>nil, "quoted_string"=>nil}}
|
|
5
|
+
if_modified = {"httpdate"=>"Thu, 01 Jan 2015 07:03:42 GMT", "timestamp"=>1420095822}
|
|
6
|
+
date = {"httpdate"=>"Fri, 02 Jan 2015 11:03:45 GMT", "timestamp"=>1420196625}
|
|
7
|
+
next_date = {"httpdate"=>"Sat, 03 Jan 2037 07:03:45 GMT", "timestamp"=>2114579025}
|
|
8
|
+
if_modified_new = {"httpdate"=>"Sun, 04 Jan 2015 09:03:45 GMT", "timestamp"=>1420362225}
|
|
9
|
+
cache_min_fresh = {"min-fresh"=>{"token"=>9999999, "quoted_string"=>nil},"only-if-cached"=>{"token"=>nil, "quoted_string"=>nil}}
|
|
10
|
+
|
|
11
|
+
@headers = {
|
|
12
|
+
:request => {
|
|
13
|
+
"If-Modified-Since" => if_modified,
|
|
14
|
+
"Cache-Control" => cache_control,
|
|
15
|
+
"If-None-Match" => ["\"myetag\"", "\"validEtag\""]
|
|
16
|
+
},
|
|
17
|
+
:cached => {
|
|
18
|
+
"Date" => date,
|
|
19
|
+
"Cache-Control" => {
|
|
20
|
+
"public" => {"token"=>nil, "quoted_string"=>nil},
|
|
21
|
+
"max-stale" => {"token"=>"1000", "quoted_string"=>nil}
|
|
22
|
+
},
|
|
23
|
+
"Last-Modified" => {"httpdate"=>"Thu, 01 Jan 2015 07:03:42 GMT", "timestamp"=>1420095822},
|
|
24
|
+
"ETag" => "\"validEtag\"",
|
|
25
|
+
"X-Cache-Req-Date" => date,
|
|
26
|
+
"X-Cache-Res-Date" => date
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
@headers_noetag = {
|
|
30
|
+
:request => {
|
|
31
|
+
"If-None-Match" => ["\"myetag\""]
|
|
32
|
+
},
|
|
33
|
+
:cached => {
|
|
34
|
+
"Date" => date,
|
|
35
|
+
"Cache-Control" => {
|
|
36
|
+
"public" => {"token"=>nil, "quoted_string"=>nil},
|
|
37
|
+
"no-cache" => {"token"=>nil, "quoted_string"=>"Cookie"},
|
|
38
|
+
"proxy-revalidate" => {"token"=>nil, "quoted_string"=>nil}
|
|
39
|
+
},
|
|
40
|
+
"ETag" => "\"validEtag\"",
|
|
41
|
+
"X-Cache-Req-Date" => date,
|
|
42
|
+
"X-Cache-Res-Date" => date
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
@no_headers = {
|
|
46
|
+
:request => {},
|
|
47
|
+
:cached => {}
|
|
48
|
+
}
|
|
49
|
+
@headers_nothing = {
|
|
50
|
+
:request => {"If-None-Match" => ["\"myetag\""] },
|
|
51
|
+
:cached => {
|
|
52
|
+
"Date" => next_date,
|
|
53
|
+
"X-Cache-Req-Date" => next_date,
|
|
54
|
+
"X-Cache-Res-Date" => next_date,
|
|
55
|
+
"Cache-Control" => {
|
|
56
|
+
"must-revalidate" => {"token"=>nil, "quoted_string"=>nil}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
@cached_rule2 = {
|
|
61
|
+
:request => {
|
|
62
|
+
"If-Modified-Since" => if_modified_new,
|
|
63
|
+
"Cache-Control" => cache_min_fresh
|
|
64
|
+
},
|
|
65
|
+
:cached => {
|
|
66
|
+
"Date" => next_date,
|
|
67
|
+
"X-Cache-Req-Date" => next_date,
|
|
68
|
+
"X-Cache-Res-Date" => next_date
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_cached
|
|
74
|
+
one = CacheRules.validate_cached? @headers
|
|
75
|
+
zero = CacheRules.validate_cached? @no_headers
|
|
76
|
+
|
|
77
|
+
assert_equal one, 1
|
|
78
|
+
assert_equal zero, 0
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_precond_match
|
|
82
|
+
guard = CacheRules.validate_precond_match? @no_headers
|
|
83
|
+
etag_one = CacheRules.validate_precond_match? @headers
|
|
84
|
+
etag_zero = CacheRules.validate_precond_match? @headers_noetag
|
|
85
|
+
mod_true = CacheRules.validate_precond_match? @cached_rule2
|
|
86
|
+
mod_false = CacheRules.validate_precond_match? @headers_nothing
|
|
87
|
+
|
|
88
|
+
assert_equal guard, 0
|
|
89
|
+
assert_equal etag_one, 1
|
|
90
|
+
assert_equal etag_zero, 0
|
|
91
|
+
assert_equal mod_true, 1
|
|
92
|
+
assert_equal mod_false, 0
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_expired
|
|
96
|
+
guard = CacheRules.validate_expired? @no_headers
|
|
97
|
+
stale = CacheRules.validate_expired? @headers
|
|
98
|
+
fresh = CacheRules.validate_expired? @headers_nothing
|
|
99
|
+
|
|
100
|
+
assert_equal guard, 0
|
|
101
|
+
assert_equal stale, 1
|
|
102
|
+
assert_equal fresh, 0
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_only_if_cached
|
|
106
|
+
one = CacheRules.validate_only_if_cached? @headers
|
|
107
|
+
zero = CacheRules.validate_only_if_cached? @headers_noetag
|
|
108
|
+
|
|
109
|
+
assert_equal one, 1
|
|
110
|
+
assert_equal zero, 0
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_allow_stale
|
|
114
|
+
guard1 = CacheRules.validate_allow_stale? @no_headers
|
|
115
|
+
guard2 = CacheRules.validate_allow_stale? @headers_noetag
|
|
116
|
+
max_stale = CacheRules.validate_allow_stale? @headers
|
|
117
|
+
min_fresh = CacheRules.validate_allow_stale? @cached_rule2
|
|
118
|
+
nothing = CacheRules.validate_allow_stale? @headers_nothing
|
|
119
|
+
|
|
120
|
+
assert_equal guard1, 0
|
|
121
|
+
assert_equal guard2, 0
|
|
122
|
+
assert_equal max_stale, 1
|
|
123
|
+
assert_equal min_fresh, 1
|
|
124
|
+
assert_equal nothing, 0
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_must_revalidate
|
|
128
|
+
guard = CacheRules.validate_must_revalidate? @no_headers
|
|
129
|
+
must_revalidate = CacheRules.validate_must_revalidate? @headers_nothing
|
|
130
|
+
proxy_revalidate= CacheRules.validate_must_revalidate? @headers_noetag
|
|
131
|
+
nothing = CacheRules.validate_must_revalidate? @headers
|
|
132
|
+
|
|
133
|
+
assert_equal guard, 1
|
|
134
|
+
assert_equal must_revalidate, 1
|
|
135
|
+
assert_equal proxy_revalidate, 1
|
|
136
|
+
assert_equal nothing, 0
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def test_no_cache
|
|
140
|
+
headers1 = {
|
|
141
|
+
:request => {'Cache-Control' => {'no-cache'=>{'token'=>nil}}},
|
|
142
|
+
:cached => {'Cache-Control' => {}}
|
|
143
|
+
}
|
|
144
|
+
headers2 = {
|
|
145
|
+
:request => {},
|
|
146
|
+
:cached => {'Cache-Control' => {'no-cache'=>{'quoted_string'=>"Cookie"}}}
|
|
147
|
+
}
|
|
148
|
+
headers2_nil = {
|
|
149
|
+
:request => {},
|
|
150
|
+
:cached => {'Cache-Control' => {'no-cache'=>{'quoted_string'=>nil}}}
|
|
151
|
+
}
|
|
152
|
+
headers3 = {
|
|
153
|
+
:request => {},
|
|
154
|
+
:cached => {'Cache-Control' => {'s-maxage'=>{'token'=>"0"}}}
|
|
155
|
+
}
|
|
156
|
+
headers4 = {
|
|
157
|
+
:request => {},
|
|
158
|
+
:cached => {'Cache-Control' => {'max-age'=>{'token'=>0}}}
|
|
159
|
+
}
|
|
160
|
+
headers5 = {
|
|
161
|
+
:request => {'Pragma' => {'no-cache'=>{'token'=>nil}}},
|
|
162
|
+
:cached => {'Cache-Control' => {}}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
guard = CacheRules.validate_no_cache? @no_headers
|
|
166
|
+
no_cache1 = CacheRules.validate_no_cache? headers1
|
|
167
|
+
no_cache2 = CacheRules.validate_no_cache? headers2
|
|
168
|
+
no_cache3 = CacheRules.validate_no_cache? headers2_nil
|
|
169
|
+
s_maxage = CacheRules.validate_no_cache? headers3
|
|
170
|
+
maxage = CacheRules.validate_no_cache? headers4
|
|
171
|
+
pragma = CacheRules.validate_no_cache? headers5
|
|
172
|
+
nothing = CacheRules.validate_no_cache? @headers
|
|
173
|
+
|
|
174
|
+
assert_equal guard, 1
|
|
175
|
+
assert_equal no_cache1, 1
|
|
176
|
+
assert_equal no_cache2, 1
|
|
177
|
+
assert_equal no_cache3, 1
|
|
178
|
+
assert_equal s_maxage, 1
|
|
179
|
+
assert_equal maxage, 1
|
|
180
|
+
assert_equal pragma, 1
|
|
181
|
+
assert_equal nothing, 0
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def test_is_error
|
|
185
|
+
not_error1 = CacheRules.validate_is_error?({:response => {'Status'=>499}})
|
|
186
|
+
not_error2 = CacheRules.validate_is_error?({:response => {'Status'=>600}})
|
|
187
|
+
is_error1 = CacheRules.validate_is_error?({:response => {'Status'=>500}})
|
|
188
|
+
is_error2 = CacheRules.validate_is_error?({:response => {'Status'=>550}})
|
|
189
|
+
is_error3 = CacheRules.validate_is_error?({:response => {'Status'=>599}})
|
|
190
|
+
|
|
191
|
+
assert_equal not_error1, 0
|
|
192
|
+
assert_equal not_error2, 0
|
|
193
|
+
assert_equal is_error1, 1
|
|
194
|
+
assert_equal is_error2, 1
|
|
195
|
+
assert_equal is_error3, 1
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def test_validator_match
|
|
199
|
+
match = CacheRules.validate_validator_match?({:request => {'If-None-Match'=>["\"myetag\""]}, :response => {'ETag'=>"\"myetag\""}})
|
|
200
|
+
nomatch = CacheRules.validate_validator_match?({:request => {'If-None-Match'=>["\"myetag\""]}, :response => {}})
|
|
201
|
+
|
|
202
|
+
assert_equal match, 1
|
|
203
|
+
assert_equal nomatch, 0
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cache_rules
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Alexander Williams
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2015-01-31 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: fakeweb
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '1.3'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '1.3'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: minitest
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ~>
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: 5.5.0
|
|
38
|
+
type: :development
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ~>
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 5.5.0
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: minitest-reporters
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ~>
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 1.0.0
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ~>
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 1.0.0
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: simplecov
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
description: CacheRules validates requests and responses for cached HTTP data based
|
|
79
|
+
on RFCs 7230-7235. The goal is to faciliate implementation of well-behaved caching
|
|
80
|
+
solutions which adhere to RFC standards.
|
|
81
|
+
email: !binary |-
|
|
82
|
+
YXdpbGxpYW1zQGFsZXh3aWxsaWFtcy5jYQ==
|
|
83
|
+
executables: []
|
|
84
|
+
extensions: []
|
|
85
|
+
extra_rdoc_files: []
|
|
86
|
+
files:
|
|
87
|
+
- .gitignore
|
|
88
|
+
- .travis.yml
|
|
89
|
+
- Gemfile
|
|
90
|
+
- Gemfile.lock
|
|
91
|
+
- LICENSE
|
|
92
|
+
- NOTICE
|
|
93
|
+
- README.md
|
|
94
|
+
- Rakefile
|
|
95
|
+
- cache_rules.gemspec
|
|
96
|
+
- lib/actions.rb
|
|
97
|
+
- lib/cache_rules.rb
|
|
98
|
+
- lib/formatting.rb
|
|
99
|
+
- lib/helpers.rb
|
|
100
|
+
- lib/validations.rb
|
|
101
|
+
- test/helper.rb
|
|
102
|
+
- test/test_cache_rules.rb
|
|
103
|
+
- test/test_formatting.rb
|
|
104
|
+
- test/test_helpers.rb
|
|
105
|
+
- test/test_tables.rb
|
|
106
|
+
- test/test_validations.rb
|
|
107
|
+
homepage: https://unscramble.co.jp
|
|
108
|
+
licenses: []
|
|
109
|
+
post_install_message: C.R.E.A.M.
|
|
110
|
+
rdoc_options: []
|
|
111
|
+
require_paths:
|
|
112
|
+
- lib
|
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
|
+
none: false
|
|
115
|
+
requirements:
|
|
116
|
+
- - ~>
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: '1.9'
|
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
|
+
none: false
|
|
121
|
+
requirements:
|
|
122
|
+
- - ! '>='
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
requirements: []
|
|
126
|
+
rubyforge_project:
|
|
127
|
+
rubygems_version: 1.8.23
|
|
128
|
+
signing_key:
|
|
129
|
+
specification_version: 3
|
|
130
|
+
summary: CacheRules validates requests and responses for cached HTTP data based on
|
|
131
|
+
RFCs 7230-7235
|
|
132
|
+
test_files: []
|