talktome 1.1.0 → 1.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a01f2b1e8706384a106f6418060f2d17a87c4d76e415e5cdd3235714c40339de
4
- data.tar.gz: 87032bc365971d322428d0245cc9d1eced6644d19f8253eacd6f061ec891e684
3
+ metadata.gz: 3921c37bcb667aedfa4119ab30f430b16cc05dfc9c1bd8d2607775f81fde5ad6
4
+ data.tar.gz: c374bc0d83fd26cf0f079fec2abf214ce5ffb387dd04a07ab2dbb04e4f610683
5
5
  SHA512:
6
- metadata.gz: 6484f97e7455db0484cd296be7ea5184f333897cdb953fac3d9ffe98dbcbdb7299779db00683bdfaf0ee970d223bb9f58e140a26732dea5543d700c621cfddc6
7
- data.tar.gz: be7f825012c0bdaa44b10939c3a29be70f9249a65b5156de065dbf6cfee7ae44e97aa5fb15ab9963e18947c889a332829b2497d696a0a9619689f48d44a027bf
6
+ metadata.gz: 1fa9f53a14b13bc8cc5b76a74ea2e61bf0eb25185f41e3c2f787748f77ea79f05f5ccb94988c5fbcbea7e1fc1a24d490456f34bde6edd26b113618c6396f6782
7
+ data.tar.gz: 33cb01d9ab2908673b8a20b196bc9d9070dc1ec76cdc7dfc506677004640f0e562dac5771db16b582672fbd426de0337a2c06941889ce80b31257a226dafc9d6
data/README.md CHANGED
@@ -97,12 +97,16 @@ TALKTOME_EMAIL_DEFAULT_TO default To: to use for email sending
97
97
  TALKTOME_EMAIL_SUBJECT Set the subject of the default "contact us" email
98
98
  TALKTOME_EMAIL_FOOTER Set the footer of the default "contact us" email
99
99
 
100
+ TALKTOME_LAYOUTS_FOLDER Set the folder to use for messaging layouts
101
+
100
102
  TALKTOME_SMTP_ADDRESS host address for smtp sending
101
103
  TALKTOME_SMTP_PORT port of smtp server to use
102
104
  TALKTOME_SMTP_DOMAIN sending domain
103
105
  TALKTOME_SMTP_USER user for smtp authentication
104
106
  TALKTOME_SMTP_PASSWORD password for smtp authentication
105
107
  TALKTOME_SMTP_STARTTLS_AUTO true or false (see ruby Mail library)
108
+
109
+ TALKTOME_BEARER_SECRET secret for the webapi, to let send emails to anyone
106
110
  ```
107
111
 
108
112
  ## Hacking Talktome
data/lib/talktome.rb CHANGED
@@ -26,7 +26,7 @@ module Talktome
26
26
  def set_env(which, value, &bl)
27
27
  old, ENV[which] = ENV[which], value
28
28
  bl.call.tap{
29
- ENV[which] = old unless old.nil?
29
+ ENV[which] = old
30
30
  }
31
31
  end
32
32
  module_function :set_env
@@ -78,6 +78,10 @@ module Talktome
78
78
  }
79
79
  }
80
80
 
81
+ if layouts_folder = ENV['TALKTOME_LAYOUTS_FOLDER']
82
+ options[:layouts] = Path(layouts_folder)
83
+ end
84
+
81
85
  options
82
86
  end
83
87
  module_function :auto_options
data/lib/talktome/app.rb CHANGED
@@ -18,6 +18,7 @@ module Talktome
18
18
  @import finitio/data
19
19
  Email = String(s | s =~ /^[^@]+@[^@]+$/ )
20
20
  {
21
+ to :? Email
21
22
  reply_to :? Email
22
23
  ... : .Object
23
24
  }
@@ -31,7 +32,8 @@ module Talktome
31
32
  subject = Talktome.env('TALKTOME_EMAIL_SUBJECT', 'Someone wants to reach you!')
32
33
  footer = Talktome.env('TALKTOME_EMAIL_FOOTER', "Truly yours,\n
33
34
  Sent by [Enspirit.be](https://enspirit.be/), contact us if you need help with any IT task.")
34
- TALKTOME.talktome(action, {}, info.merge(allvars: as_array, subject: subject, footer: footer), [:email]){|email|
35
+ user = load_user_from_info!
36
+ TALKTOME.talktome(action, user, info.merge(allvars: as_array, subject: subject, footer: footer), [:email]){|email|
35
37
  email.reply_to = info[:reply_to] if info.has_key?(:reply_to)
36
38
  }
37
39
  [ 200, { "Content-Type" => "text/plain"}, ["Ok"] ]
@@ -52,8 +54,19 @@ module Talktome
52
54
  }
53
55
  end
54
56
 
55
- def fail!(message)
56
- [ 400, { "Content-Type" => "text/plain"}, [message] ]
57
+ def load_user_from_info!
58
+ if to = info[:to]
59
+ secret = Talktome.env('TALKTOME_BEARER_SECRET')
60
+ fail!("Missing secret", 400) unless secret
61
+ fail!("Invalid secret", 401) unless "Bearer #{secret}" == env["HTTP_AUTHORIZATION"]
62
+ { email: info[:to] }
63
+ else
64
+ {}
65
+ end
66
+ end
67
+
68
+ def fail!(message, status = 400)
69
+ halt([ status, { "Content-Type" => "text/plain"}, [message] ])
57
70
  end
58
71
 
59
72
  def not_a_robot!(info)
@@ -33,7 +33,7 @@ module Talktome
33
33
  end
34
34
 
35
35
  def templater(strategy)
36
- return nil unless tpl_folder = options[:templates]
36
+ return nil unless tpl_folder = options[:layouts] || options[:templates]
37
37
  ->(message, src, ctype) {
38
38
  if (file = tpl_folder/"#{strategy}.#{ctype}").file?
39
39
  data = { metadata: message.metadata, yield: src }
@@ -2,7 +2,7 @@ module Talktome
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 2
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
data/spec/app/test_app.rb CHANGED
@@ -46,6 +46,22 @@ module Talktome
46
46
  end
47
47
  end
48
48
 
49
+ it 'allows to use a token authentification to bypass default security measures, for e.g. passing the :to' do
50
+ Talktome.set_env('TALKTOME_BEARER_SECRET', "Some secret") do
51
+ header 'Authorization', 'Bearer Some secret'
52
+ post "/contact-us/", {
53
+ to: 'hello@visitor.com',
54
+ reply_to: 'hello@visitor.com',
55
+ message: 'Hello from visitor',
56
+ key: 'value',
57
+ }.to_json, { "CONTENT_TYPE" => "application/json" }
58
+ expect(last_response).to be_ok
59
+ expect(Mail::TestMailer.deliveries.length).to eql(1)
60
+ expect(Mail::TestMailer.deliveries.first.to).to eql(["hello@visitor.com"])
61
+ expect(Mail::TestMailer.deliveries.first.from).to eql(["from@talktome.com"])
62
+ end
63
+ end
64
+
49
65
  it 'detects invalid emails' do
50
66
  post "/contact-us/", {
51
67
  reply_to: 'helloatvisitor.com',
@@ -71,6 +87,48 @@ module Talktome
71
87
  expect(Mail::TestMailer.deliveries.length).to eql(0)
72
88
  end
73
89
 
90
+ it 'forbids usage of :to unless a secret is provided' do
91
+ post "/contact-us/", {
92
+ to: 'hello@visitor.com',
93
+ reply_to: 'hello@visitor.com',
94
+ message: 'Hello from visitor',
95
+ key: 'value',
96
+ }.to_json, { "CONTENT_TYPE" => "application/json" }
97
+ expect(last_response.status).to eql(400)
98
+ expect(Mail::TestMailer.deliveries.length).to eql(0)
99
+ end
100
+
101
+ it 'does not allow setting the :to without a valid AUTH token' do
102
+ Talktome.set_env('TALKTOME_BEARER_SECRET', "Invalid secret") do
103
+ post "/contact-us/", {
104
+ to: 'hello@visitor.com',
105
+ reply_to: 'hello@visitor.com',
106
+ message: 'Hello from visitor',
107
+ key: 'value',
108
+ }.to_json, { "CONTENT_TYPE" => "application/json" }
109
+ expect(last_response.status).to eql(401)
110
+ expect(Mail::TestMailer.deliveries.length).to eql(0)
111
+ end
112
+ end
113
+
114
+ it 'requires a valid Email for :to' do
115
+ post "/contact-us/", {
116
+ to: nil,
117
+ reply_to: 'hello@visitor.com',
118
+ message: 'Hello from visitor',
119
+ key: 'value',
120
+ }.to_json, { "CONTENT_TYPE" => "application/json" }
121
+ expect(last_response.status).to eql(400)
122
+
123
+ post "/contact-us/", {
124
+ to: "notavalidemail",
125
+ reply_to: 'hello@visitor.com',
126
+ message: 'Hello from visitor',
127
+ key: 'value',
128
+ }.to_json, { "CONTENT_TYPE" => "application/json" }
129
+ expect(last_response.status).to eql(400)
130
+ end
131
+
74
132
  end
75
133
 
76
134
  context 'POST /contact-us/, regarding the Reply-To' do
@@ -29,7 +29,7 @@ module Talktome
29
29
  strategy.clear!
30
30
  }
31
31
 
32
- context "without templates" do
32
+ context "without layouts" do
33
33
  let(:options) {
34
34
  {}
35
35
  }
@@ -41,10 +41,10 @@ module Talktome
41
41
  end
42
42
  end
43
43
 
44
- context "with templates" do
44
+ context "with layouts under the :layouts option key" do
45
45
  let(:options) {
46
46
  {
47
- templates: Path.dir/"../fixtures/templates"
47
+ layouts: Path.dir/"../fixtures/layouts"
48
48
  }
49
49
  }
50
50
 
@@ -63,6 +63,19 @@ module Talktome
63
63
  end
64
64
  end
65
65
 
66
+ context "with layouts under the :templates option key (backward compatibility)" do
67
+ let(:options) {
68
+ {
69
+ templates: Path.dir/"../fixtures/layouts"
70
+ }
71
+ }
72
+
73
+ it 'sends email when requested' do
74
+ client.talktome("welcome", user, tpldata, [:email])
75
+ expect(strategy.last.message.to_html).to eql("<html><title>Hello Test user</title><body><h1>Hello Test user</h1>\n\n<p>Welcome to this email example!</p>\n\n<h3>Test user</h3>\n</body></html>\n")
76
+ end
77
+ end
78
+
66
79
  end
67
80
  end
68
81
  end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talktome
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-30 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -138,16 +138,22 @@ dependencies:
138
138
  name: finitio
139
139
  requirement: !ruby/object:Gem::Requirement
140
140
  requirements:
141
- - - "~>"
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: 0.10.0
144
+ - - "<"
142
145
  - !ruby/object:Gem::Version
143
- version: 0.8.0
146
+ version: 0.11.0
144
147
  type: :runtime
145
148
  prerelease: false
146
149
  version_requirements: !ruby/object:Gem::Requirement
147
150
  requirements:
148
- - - "~>"
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: 0.10.0
154
+ - - "<"
149
155
  - !ruby/object:Gem::Version
150
- version: 0.8.0
156
+ version: 0.11.0
151
157
  - !ruby/object:Gem::Dependency
152
158
  name: rack-robustness
153
159
  requirement: !ruby/object:Gem::Requirement
@@ -185,7 +191,7 @@ files:
185
191
  - lib/talktome/version.rb
186
192
  - spec/app/test_app.rb
187
193
  - spec/client/test_local.rb
188
- - spec/fixtures/templates/email.html
194
+ - spec/fixtures/layouts/email.html
189
195
  - spec/fixtures/welcome/email.md
190
196
  - spec/fixtures/welcome/footer.mustache
191
197
  - spec/message/test_initialize.rb
@@ -199,7 +205,7 @@ homepage: http://github.com/enspirit/talktome
199
205
  licenses:
200
206
  - MIT
201
207
  metadata: {}
202
- post_install_message:
208
+ post_install_message:
203
209
  rdoc_options: []
204
210
  require_paths:
205
211
  - lib
@@ -214,8 +220,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
220
  - !ruby/object:Gem::Version
215
221
  version: '0'
216
222
  requirements: []
217
- rubygems_version: 3.1.2
218
- signing_key:
223
+ rubygems_version: 3.2.15
224
+ signing_key:
219
225
  specification_version: 4
220
226
  summary: Talktome helps you talk to users by email, messaging, sms, etc.
221
227
  test_files: []