utopia 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -3
  3. data/README.md +142 -11
  4. data/benchmarks/string_vs_symbol.rb +12 -0
  5. data/lib/utopia/command.rb +16 -13
  6. data/lib/utopia/content.rb +1 -5
  7. data/lib/utopia/content/node.rb +9 -4
  8. data/lib/utopia/{extensions/rack.rb → content/response.rb} +33 -30
  9. data/lib/utopia/content/tag.rb +14 -17
  10. data/lib/utopia/content/transaction.rb +19 -17
  11. data/lib/utopia/controller.rb +29 -8
  12. data/lib/utopia/controller/actions.rb +148 -0
  13. data/lib/utopia/controller/base.rb +9 -49
  14. data/lib/utopia/controller/respond.rb +1 -1
  15. data/lib/utopia/controller/rewrite.rb +9 -1
  16. data/lib/utopia/controller/variables.rb +1 -0
  17. data/lib/utopia/localization.rb +4 -1
  18. data/lib/utopia/middleware.rb +0 -2
  19. data/lib/utopia/path.rb +9 -0
  20. data/lib/utopia/path/matcher.rb +0 -1
  21. data/lib/utopia/redirection.rb +3 -2
  22. data/lib/utopia/session.rb +119 -2
  23. data/lib/utopia/session/lazy_hash.rb +1 -3
  24. data/lib/utopia/setup.rb +73 -0
  25. data/lib/utopia/static.rb +9 -2
  26. data/lib/utopia/version.rb +1 -1
  27. data/setup/examples/wiki/controller.rb +41 -0
  28. data/setup/examples/wiki/edit.xnode +15 -0
  29. data/setup/examples/wiki/index.xnode +10 -0
  30. data/setup/examples/wiki/welcome/content.md +3 -0
  31. data/setup/server/config/environment.yaml +1 -0
  32. data/setup/server/git/hooks/post-receive +4 -5
  33. data/setup/site/Gemfile +5 -0
  34. data/setup/site/config.ru +2 -1
  35. data/setup/site/config/environment.rb +5 -17
  36. data/setup/site/pages/_page.xnode +4 -2
  37. data/setup/site/pages/links.yaml +1 -1
  38. data/setup/site/pages/welcome/index.xnode +33 -15
  39. data/setup/site/public/_static/site.css +72 -4
  40. data/setup/site/tasks/utopia.rake +8 -0
  41. data/spec/utopia/{rack_spec.rb → content/response_spec.rb} +12 -19
  42. data/spec/utopia/content_spec.rb +2 -3
  43. data/spec/utopia/controller/{action_spec.rb → actions_spec.rb} +18 -32
  44. data/spec/utopia/controller/middleware_spec.rb +10 -10
  45. data/spec/utopia/controller/middleware_spec/controller/controller.rb +3 -3
  46. data/spec/utopia/controller/middleware_spec/controller/nested/controller.rb +1 -1
  47. data/spec/utopia/controller/middleware_spec/redirect/controller.rb +1 -1
  48. data/spec/utopia/controller/respond_spec.rb +3 -2
  49. data/spec/utopia/controller/respond_spec/api/controller.rb +2 -2
  50. data/spec/utopia/controller/respond_spec/errors/controller.rb +1 -1
  51. data/spec/utopia/controller/rewrite_spec.rb +1 -1
  52. data/spec/utopia/controller/sequence_spec.rb +12 -16
  53. data/spec/utopia/exceptions/handler_spec/controller.rb +2 -2
  54. data/spec/utopia/performance_spec/config.ru +1 -0
  55. data/spec/utopia/session_spec.rb +34 -1
  56. data/spec/utopia/session_spec.ru +3 -3
  57. data/spec/utopia/setup_spec.rb +2 -2
  58. data/utopia.gemspec +2 -2
  59. metadata +18 -12
  60. data/lib/utopia/controller/action.rb +0 -116
  61. data/lib/utopia/session/encrypted_cookie.rb +0 -118
@@ -1,118 +0,0 @@
1
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'openssl'
22
- require 'digest/sha2'
23
-
24
- require_relative 'lazy_hash'
25
- require_relative '../session'
26
-
27
- module Utopia
28
- module Session
29
- # Stores all session data client side using a private symmetric encrpytion key.
30
- class EncryptedCookie
31
- def initialize(app, **options)
32
- @app = app
33
- @cookie_name = options.delete(:cookie_name) || (RACK_SESSION + ".encrypted")
34
-
35
- @secret = options.delete(:secret)
36
-
37
- @options = {
38
- :domain => nil,
39
- :path => "/",
40
- :expires_after => nil
41
- }.merge(options)
42
- end
43
-
44
- def call(env)
45
- session_hash = prepare_session(env)
46
-
47
- status, headers, body = @app.call(env)
48
-
49
- if session_hash.changed?
50
- commit(session_hash.values, headers)
51
- end
52
-
53
- return [status, headers, body]
54
- end
55
-
56
- protected
57
-
58
- def prepare_session(env)
59
- env[RACK_SESSION] = LazyHash.new do
60
- self.load_session_values(env)
61
- end
62
- end
63
-
64
- # Load session
65
- def load_session_values(env)
66
- values = {}
67
-
68
- request = Rack::Request.new(env)
69
- data = request.cookies[@cookie_name]
70
-
71
- if data
72
- values = decrypt(data) rescue values
73
- end
74
-
75
- return values
76
- end
77
-
78
- def commit(values, headers)
79
- data = encrypt(values)
80
-
81
- cookie = {:value => data}
82
-
83
- cookie[:expires] = Time.now + @options[:expires_after] unless @options[:expires_after].nil?
84
-
85
- Rack::Utils.set_cookie_header!(headers, @cookie_name, cookie.merge(@options))
86
- end
87
-
88
- def encrypt(hash)
89
- c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
90
- c.encrypt
91
-
92
- # your pass is what is used to encrypt/decrypt
93
- c.key = @secret
94
- c.iv = iv = c.random_iv
95
-
96
- e = c.update(Marshal.dump(hash))
97
- e << c.final
98
-
99
- return [iv, e].pack("m16m*")
100
- end
101
-
102
- def decrypt(data)
103
- iv, e = data.unpack("m16m*")
104
-
105
- c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
106
- c.decrypt
107
-
108
- c.key = @secret
109
- c.iv = iv
110
-
111
- d = c.update(e)
112
- d << c.final
113
-
114
- return Marshal.load(d)
115
- end
116
- end
117
- end
118
- end