cuba 3.9.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gems +5 -4
- data/README.md +1 -1
- data/cuba.gemspec +2 -2
- data/lib/cuba/safe/csrf.rb +1 -1
- data/lib/cuba.rb +26 -0
- data/test/accept.rb +46 -1
- data/test/cookie.rb +5 -5
- data/test/csrf.rb +2 -1
- data/test/integration.rb +2 -2
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7d1132f58ee467460030f12c618ab68ec947bb83d8b20df22588475d37e95994
|
4
|
+
data.tar.gz: 7e73fb3214fa781d9a5564d780d3a0a4e6e32ba1833ce55e286ab62b75002b04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 046baecf8b875441123af6279840efa324757e9579324e5accc5f39b5d5f1df01be38c07af2e08c164f2a55e611c7653282239bbc3fd558feb6290a658c46eb1
|
7
|
+
data.tar.gz: b2812bc154953daa7e84972d1380aaaf68612e3f7162389315932404614e625a0a002ab21ba13c76c77727694a6b4696810206927a7798c600cce0aff70fa3c2
|
data/.gems
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
cutest -v 1.2.
|
2
|
-
tilt -v 2.0.
|
3
|
-
rack
|
4
|
-
rack -v 2.0.
|
1
|
+
cutest -v 1.2.3
|
2
|
+
tilt -v 2.0.10
|
3
|
+
rack -v 3.0.2
|
4
|
+
rack-test -v 2.0.2
|
5
|
+
rack-session -v 0.3.0
|
data/README.md
CHANGED
@@ -761,7 +761,7 @@ Contributing
|
|
761
761
|
------------
|
762
762
|
|
763
763
|
A good first step is to meet us on IRC and discuss ideas. If that's
|
764
|
-
not possible, you can create an issue
|
764
|
+
not possible, you can create an issue explaining the proposed change
|
765
765
|
and a use case. We pay a lot of attention to use cases, because our
|
766
766
|
goal is to keep the code base simple. In many cases, the result of
|
767
767
|
a conversation will be the creation of another tool, instead of the
|
data/cuba.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cuba"
|
3
|
-
s.version = "
|
3
|
+
s.version = "4.0.0"
|
4
4
|
s.summary = "Microframework for web applications."
|
5
5
|
s.description = "Cuba is a microframework for web applications."
|
6
6
|
s.authors = ["Michel Martens"]
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
|
11
11
|
s.files = `git ls-files`.split("\n")
|
12
12
|
|
13
|
-
s.add_dependency "rack", ">=
|
13
|
+
s.add_dependency "rack", ">= 3.0.0"
|
14
14
|
s.add_development_dependency "cutest"
|
15
15
|
s.add_development_dependency "rack-test"
|
16
16
|
s.add_development_dependency "tilt"
|
data/lib/cuba/safe/csrf.rb
CHANGED
data/lib/cuba.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
require "delegate"
|
1
2
|
require "rack"
|
3
|
+
require "rack/session"
|
2
4
|
|
3
5
|
class Cuba
|
4
6
|
SLASH = "/".freeze
|
@@ -10,6 +12,12 @@ class Cuba
|
|
10
12
|
class Response
|
11
13
|
LOCATION = "Location".freeze
|
12
14
|
|
15
|
+
module ContentType
|
16
|
+
HTML = "text/html".freeze # :nodoc:
|
17
|
+
TEXT = "text/plain".freeze # :nodoc:
|
18
|
+
JSON = "application/json".freeze # :nodoc:
|
19
|
+
end
|
20
|
+
|
13
21
|
attr_accessor :status
|
14
22
|
|
15
23
|
attr :body
|
@@ -38,6 +46,24 @@ class Cuba
|
|
38
46
|
@body << s
|
39
47
|
end
|
40
48
|
|
49
|
+
# Write response body as text/plain
|
50
|
+
def text(str)
|
51
|
+
@headers[Rack::CONTENT_TYPE] = ContentType::TEXT
|
52
|
+
write(str)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Write response body as text/html
|
56
|
+
def html(str)
|
57
|
+
@headers[Rack::CONTENT_TYPE] = ContentType::HTML
|
58
|
+
write(str)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Write response body as application/json
|
62
|
+
def json(str)
|
63
|
+
@headers[Rack::CONTENT_TYPE] = ContentType::JSON
|
64
|
+
write(str)
|
65
|
+
end
|
66
|
+
|
41
67
|
def redirect(path, status = 302)
|
42
68
|
@headers[LOCATION] = path
|
43
69
|
@status = status
|
data/test/accept.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path("helper", File.dirname(__FILE__))
|
|
3
3
|
test "accept mimetypes" do
|
4
4
|
Cuba.define do
|
5
5
|
on accept("application/xml") do
|
6
|
-
res.write res["
|
6
|
+
res.write res["content-type"]
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -30,3 +30,48 @@ test "tests don't fail when you don't specify an accept type" do
|
|
30
30
|
|
31
31
|
assert_response body, ["Default action"]
|
32
32
|
end
|
33
|
+
|
34
|
+
test "accept HTML mimetype" do
|
35
|
+
Cuba.define do
|
36
|
+
on accept("text/html") do
|
37
|
+
res.write Cuba::Response::ContentType::HTML
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
env = { "HTTP_ACCEPT" => "text/html",
|
42
|
+
"SCRIPT_NAME" => "/", "PATH_INFO" => "/post" }
|
43
|
+
|
44
|
+
_, _, body = Cuba.call(env)
|
45
|
+
|
46
|
+
assert_response body, ["text/html"]
|
47
|
+
end
|
48
|
+
|
49
|
+
test "accept TEXT mimetype" do
|
50
|
+
Cuba.define do
|
51
|
+
on accept("text/plain") do
|
52
|
+
res.write Cuba::Response::ContentType::TEXT
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
env = { "HTTP_ACCEPT" => "text/plain",
|
57
|
+
"SCRIPT_NAME" => "/", "PATH_INFO" => "/post" }
|
58
|
+
|
59
|
+
_, _, body = Cuba.call(env)
|
60
|
+
|
61
|
+
assert_response body, ["text/plain"]
|
62
|
+
end
|
63
|
+
|
64
|
+
test "accept JSON mimetype" do
|
65
|
+
Cuba.define do
|
66
|
+
on accept("application/json") do
|
67
|
+
res.write Cuba::Response::ContentType::JSON
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
env = { "HTTP_ACCEPT" => "application/json",
|
72
|
+
"SCRIPT_NAME" => "/", "PATH_INFO" => "/get" }
|
73
|
+
|
74
|
+
_, _, body = Cuba.call(env)
|
75
|
+
|
76
|
+
assert_response body, ["application/json"]
|
77
|
+
end
|
data/test/cookie.rb
CHANGED
@@ -11,9 +11,9 @@ test "set cookie" do
|
|
11
11
|
|
12
12
|
env = { "SCRIPT_NAME" => "/", "PATH_INFO" => "/" }
|
13
13
|
|
14
|
-
|
14
|
+
_, headers, body = Cuba.call(env)
|
15
15
|
|
16
|
-
|
16
|
+
assert_equal ["foo=bar", "bar=baz"], headers["set-cookie"]
|
17
17
|
end
|
18
18
|
|
19
19
|
test "delete cookie" do
|
@@ -27,8 +27,8 @@ test "delete cookie" do
|
|
27
27
|
|
28
28
|
env = { "SCRIPT_NAME" => "/", "PATH_INFO" => "/" }
|
29
29
|
|
30
|
-
|
30
|
+
_, headers, body = Cuba.call(env)
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
assert_equal ["foo=bar", "foo=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 GMT"],
|
33
|
+
headers["set-cookie"]
|
34
34
|
end
|
data/test/csrf.rb
CHANGED
@@ -13,7 +13,8 @@ scope do
|
|
13
13
|
setup do
|
14
14
|
Cuba.reset!
|
15
15
|
|
16
|
-
Cuba.use(Rack::Session::Cookie,
|
16
|
+
Cuba.use(Rack::Session::Cookie,
|
17
|
+
secret: "R6zSBQWz0VGVSwvT8THurhJwaVqzpnsH27J5FoI58pxoIciDQYvE4opVvDTLMyfjj7c5inIc6PDNaQWvArMvK3")
|
17
18
|
Cuba.plugin(Cuba::Safe::CSRF)
|
18
19
|
end
|
19
20
|
|
data/test/integration.rb
CHANGED
@@ -78,7 +78,7 @@ test "reset and use" do
|
|
78
78
|
status, headers, resp = Cuba.call(env)
|
79
79
|
|
80
80
|
assert_equal 200, status
|
81
|
-
assert "text/html; charset=utf-8" == headers["
|
81
|
+
assert "text/html; charset=utf-8" == headers["content-type"]
|
82
82
|
assert_response resp, ["2nd Default"]
|
83
83
|
|
84
84
|
assert "1" == env["m.first"]
|
@@ -109,6 +109,6 @@ test "custom response" do
|
|
109
109
|
status, headers, resp = Cuba.call(env)
|
110
110
|
|
111
111
|
assert 200 == status
|
112
|
-
assert "text/html; charset=utf-8" == headers["
|
112
|
+
assert "text/html; charset=utf-8" == headers["content-type"]
|
113
113
|
assert_response resp, ["Default"]
|
114
114
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: cutest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,8 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: '0'
|
154
154
|
requirements: []
|
155
|
-
|
156
|
-
rubygems_version: 2.6.11
|
155
|
+
rubygems_version: 3.0.3.1
|
157
156
|
signing_key:
|
158
157
|
specification_version: 4
|
159
158
|
summary: Microframework for web applications.
|