locomotivecms_steam 1.5.0.beta3 → 1.5.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -4
  3. data/Gemfile.lock +3 -6
  4. data/README.md +33 -0
  5. data/Rakefile +8 -3
  6. data/docker-compose.yml +15 -0
  7. data/lib/locomotive/steam/entities/content_type.rb +7 -2
  8. data/lib/locomotive/steam/liquid/drops/section_content_proxy.rb +4 -0
  9. data/lib/locomotive/steam/liquid/filters/translate.rb +2 -0
  10. data/lib/locomotive/steam/liquid/tags/link_to.rb +8 -1
  11. data/lib/locomotive/steam/liquid/tags/model_form.rb +7 -1
  12. data/lib/locomotive/steam/middlewares/auth.rb +10 -17
  13. data/lib/locomotive/steam/middlewares/concerns/auth_helpers.rb +30 -0
  14. data/lib/locomotive/steam/middlewares/concerns/helpers.rb +13 -3
  15. data/lib/locomotive/steam/middlewares/concerns/liquid_context.rb +1 -1
  16. data/lib/locomotive/steam/middlewares/concerns/recaptcha.rb +30 -0
  17. data/lib/locomotive/steam/middlewares/default_env.rb +5 -3
  18. data/lib/locomotive/steam/middlewares/entry_submission.rb +4 -1
  19. data/lib/locomotive/steam/middlewares/impersonated_entry.rb +73 -0
  20. data/lib/locomotive/steam/middlewares/locale.rb +14 -9
  21. data/lib/locomotive/steam/models/associations/belongs_to.rb +6 -0
  22. data/lib/locomotive/steam/server.rb +1 -0
  23. data/lib/locomotive/steam/services.rb +9 -1
  24. data/lib/locomotive/steam/services/action_service.rb +3 -3
  25. data/lib/locomotive/steam/services/auth_service.rb +1 -1
  26. data/lib/locomotive/steam/services/content_entry_service.rb +11 -1
  27. data/lib/locomotive/steam/services/cookie_service.rb +25 -0
  28. data/lib/locomotive/steam/services/page_finder_service.rb +12 -0
  29. data/lib/locomotive/steam/services/recaptcha_service.rb +33 -0
  30. data/lib/locomotive/steam/services/translator_service.rb +12 -13
  31. data/lib/locomotive/steam/version.rb +1 -1
  32. data/spec/integration/liquid/filters/translate_spec.rb +7 -0
  33. data/spec/integration/repositories/content_entry_repository_spec.rb +4 -0
  34. data/spec/integration/server/auth_spec.rb +8 -1
  35. data/spec/integration/services/content_entry_service_spec.rb +11 -0
  36. data/spec/support/helpers.rb +1 -1
  37. data/spec/unit/liquid/drops/section_content_proxy_spec.rb +8 -0
  38. data/spec/unit/liquid/tags/action_spec.rb +2 -1
  39. data/spec/unit/liquid/tags/global_section_spec.rb +2 -1
  40. data/spec/unit/liquid/tags/link_to_spec.rb +7 -0
  41. data/spec/unit/liquid/tags/model_form_spec.rb +7 -0
  42. data/spec/unit/liquid/tags/section_spec.rb +2 -1
  43. data/spec/unit/liquid/tags/snippet_spec.rb +2 -1
  44. data/spec/unit/middlewares/auth_spec.rb +1 -0
  45. data/spec/unit/middlewares/entry_submission_spec.rb +64 -20
  46. data/spec/unit/middlewares/helpers_spec.rb +5 -1
  47. data/spec/unit/middlewares/impersonated_entry_spec.rb +80 -0
  48. data/spec/unit/middlewares/locale_spec.rb +57 -36
  49. data/spec/unit/middlewares/section_spec.rb +6 -5
  50. data/spec/unit/middlewares/site_spec.rb +13 -0
  51. data/spec/unit/services/action_service_spec.rb +17 -11
  52. data/spec/unit/services/auth_service_spec.rb +7 -1
  53. data/spec/unit/services/content_entry_service_spec.rb +25 -4
  54. data/spec/unit/services/cookie_service_spec.rb +38 -0
  55. data/spec/unit/services/page_finder_service_spec.rb +69 -0
  56. data/spec/unit/services/recaptcha_service_spec.rb +71 -0
  57. data/spec/unit/services/translator_service_spec.rb +11 -1
  58. metadata +16 -2
@@ -161,12 +161,18 @@ describe Locomotive::Steam::AuthService do
161
161
  end
162
162
 
163
163
 
164
- it "returns :wrong_credentials if the password is empty" do
164
+ it "returns :wrong_credentials if the password is nil" do
165
165
  entry = instance_double('Account', password: nil)
166
166
  expect(entries).to receive(:all).with('accounts', { 'email' => 'john@doe.net' }).and_return([entry])
167
167
  is_expected.to eq :wrong_credentials
168
168
  end
169
169
 
170
+ it "returns :wrong_credentials if the password is blank" do
171
+ entry = instance_double('Account', password: '')
172
+ expect(entries).to receive(:all).with('accounts', { 'email' => 'john@doe.net' }).and_return([entry])
173
+ is_expected.to eq :wrong_credentials
174
+ end
175
+
170
176
  it "returns both :signed_in and the entry if the password matches the entry's password" do
171
177
  entry = build_account('easyone')
172
178
  expect(entries).to receive(:all).with('accounts', { 'email' => 'john@doe.net' }).and_return([entry])
@@ -17,7 +17,8 @@ describe Locomotive::Steam::ContentEntryService do
17
17
  let(:first_validation) { false }
18
18
  let(:errors) { [:title] }
19
19
  let(:type) { instance_double('Comments') }
20
- let(:entry) { instance_double('Entry', title: 'Hello world', content_type: type, valid?: first_validation, errors: errors, attributes: { title: 'Hello world' }, localized_attributes: []) }
20
+ let(:entry_id) { nil }
21
+ let(:entry) { instance_double('Entry', _id: entry_id, title: 'Hello world', content_type: type, valid?: first_validation, errors: errors, attributes: { title: 'Hello world' }, localized_attributes: []) }
21
22
 
22
23
  before do
23
24
  allow(type_repository).to receive(:by_slug).and_return(type)
@@ -47,12 +48,32 @@ describe Locomotive::Steam::ContentEntryService do
47
48
  let(:unique_fields) { { title: instance_double('Field', name: 'title') } }
48
49
 
49
50
  before do
50
- allow(entry_repository).to receive(:exists?).with(title: 'Hello world').and_return(true)
51
51
  expect(entry.errors).to receive(:add).with(:title, :taken).and_return(true)
52
52
  end
53
53
 
54
- it { is_expected.to eq false }
55
- it { subject; expect(entry.errors).to eq([:title]) }
54
+ context 'the entry has never been persisted before' do
55
+
56
+ before do
57
+ allow(entry_repository).to receive(:exists?).with(title: 'Hello world', :'_id.ne' => nil).and_return(true)
58
+ end
59
+
60
+ it { is_expected.to eq false }
61
+ it { subject; expect(entry.errors).to eq([:title]) }
62
+
63
+ end
64
+
65
+ context 'the entry has already been persisted' do
66
+
67
+ let(:entry_id) { 42 }
68
+
69
+ before do
70
+ allow(entry_repository).to receive(:exists?).with(title: 'Hello world', :'_id.ne' => 42).and_return(true)
71
+ end
72
+
73
+ it { is_expected.to eq false }
74
+ it { subject; expect(entry.errors).to eq([:title]) }
75
+
76
+ end
56
77
 
57
78
  end
58
79
 
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::CookieService do
4
+
5
+ let(:steam_cookies) { {} }
6
+ let(:request_cookies) { {} }
7
+ let(:request) { instance_double('Request', env: { 'steam.cookies' => steam_cookies }, cookies: request_cookies) }
8
+ let(:cookie) { {'value' => 'bar2'} }
9
+ let(:service) { described_class.new(request) }
10
+
11
+ describe '#get cookies from request' do
12
+
13
+ let(:request_cookies) { {'foo' => 'bar'} }
14
+ subject { service.get('foo') }
15
+
16
+ context 'from request' do
17
+ it { is_expected.to eq 'bar' }
18
+ end
19
+
20
+ context 'from response' do
21
+ let(:steam_cookies) { {'foo' => {'value' => 'bar2'}} }
22
+ it { is_expected.to eq 'bar2' }
23
+ end
24
+
25
+ end
26
+
27
+ describe '#set cookies from response' do
28
+
29
+ subject { service.set('foo', cookie) }
30
+
31
+ it 'set the cookies into steam' do
32
+ is_expected.to eq cookie
33
+ expect(steam_cookies).to eq({'foo' => cookie})
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::PageFinderService do
4
+
5
+ let(:site) { instance_double('Site', default_locale: :en) }
6
+ let(:repository) { instance_double('PageRepository', site: site, locale: :en)}
7
+ let(:service) { described_class.new(repository) }
8
+
9
+ describe '#find_by_id' do
10
+
11
+ let(:id) { 42 }
12
+ let(:page) { instance_double('Page', title: 'My page', localized_attributes: []) }
13
+
14
+ subject { service.find_by_id(id) }
15
+
16
+ it 'calls the repository to get the page and decorate it' do
17
+ expect(repository).to receive(:find).with(42).and_return(page)
18
+ expect(subject.title).to eq 'My page'
19
+ end
20
+
21
+ end
22
+
23
+ describe '#match' do
24
+
25
+ let(:path) { '/something' }
26
+ let(:pages) { [instance_double('Page 1', title: 'Page #1', fullpath: 'something', position: 2, localized_attributes: []) ] }
27
+
28
+ before { allow(repository).to receive(:matching_fullpath).and_return(pages) }
29
+
30
+ subject { service.match(path) }
31
+
32
+ it { expect(subject.map(&:title)).to eq(['Page #1']) }
33
+
34
+ context '2 pages at the root of the site' do
35
+
36
+ let(:pages) { [
37
+ instance_double('Page 1', title: 'Page #1', fullpath: 'something', position: 2, localized_attributes: []),
38
+ instance_double('Page 2', title: 'Page #2', fullpath: 'content_type_template', position: 1, localized_attributes: [])
39
+ ] }
40
+
41
+ it { expect(subject.map(&:title)).to eq(['Page #2', 'Page #1']) }
42
+
43
+ end
44
+
45
+ context '2 pages in the same folder' do
46
+
47
+ let(:pages) { [
48
+ instance_double('Page 1', title: 'Page #1', fullpath: 'folder/something', position: 2, localized_attributes: []),
49
+ instance_double('Page 2', title: 'Page #2', fullpath: 'folder/content_type_template', position: 1, localized_attributes: [])
50
+ ] }
51
+
52
+ it { expect(subject.map(&:title)).to eq(['Page #2', 'Page #1']) }
53
+
54
+ end
55
+
56
+ context '2 pages in different folder' do
57
+
58
+ let(:pages) { [
59
+ instance_double('Page 1', title: 'Page #1', fullpath: 'folder/something', position: 2, localized_attributes: []),
60
+ instance_double('Page 2', title: 'Page #2', fullpath: 'anotherfolder/content_type_template', position: 1, localized_attributes: [])
61
+ ] }
62
+
63
+ it { expect(subject.map(&:title)).to eq(['Page #1', 'Page #2']) }
64
+
65
+ end
66
+
67
+ end
68
+ end
69
+
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::RecaptchaService do
4
+
5
+ let(:api_url) { nil }
6
+ let(:secret) { 'asecretkey' }
7
+ let(:site) { instance_double('Site', metafields: { google: { recaptcha_api_url: api_url, recaptcha_secret: secret } }) }
8
+ let(:request) { instance_double('Request', ip: '127.0.0.1') }
9
+ let(:service) { described_class.new(site, request) }
10
+
11
+ describe '#verify' do
12
+
13
+ let(:code) { nil }
14
+
15
+ subject { service.verify(code) }
16
+
17
+ it { is_expected.to eq false }
18
+
19
+ context 'the code is not nil' do
20
+
21
+ let(:code) { '42' }
22
+ let(:success) { false }
23
+
24
+ before do
25
+ expect(HTTParty).to receive(:get).with('https://www.google.com/recaptcha/api/siteverify', {
26
+ query: {
27
+ secret: 'asecretkey',
28
+ response: '42',
29
+ remoteip: '127.0.0.1'
30
+ }
31
+ }).and_return(instance_double('Response', parsed_response: { 'success' => success }))
32
+ end
33
+
34
+ context 'the code is verified' do
35
+
36
+ let(:success) { true }
37
+ it { is_expected.to eq true }
38
+
39
+ end
40
+
41
+ context 'the code is not verified' do
42
+
43
+ let(:success) { false }
44
+ it { is_expected.to eq false }
45
+
46
+ end
47
+
48
+ end
49
+
50
+ context 'using a different API url' do
51
+
52
+ let(:code) { '42' }
53
+ let(:api_url) { 'https://recaptcha.net/api' }
54
+
55
+ before do
56
+ expect(HTTParty).to receive(:get).with('https://recaptcha.net/api', {
57
+ query: {
58
+ secret: 'asecretkey',
59
+ response: '42',
60
+ remoteip: '127.0.0.1'
61
+ }
62
+ }).and_return(instance_double('Response', parsed_response: { 'success' => true }))
63
+ end
64
+
65
+ it { is_expected.to eq true }
66
+
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -8,13 +8,14 @@ describe Locomotive::Steam::TranslatorService do
8
8
 
9
9
  describe '#translate' do
10
10
 
11
+ let(:key) { 'example_test' }
11
12
  let(:input) { 'example_test' }
12
13
  let(:locale) { nil }
13
14
  let(:scope) { nil }
14
15
  let(:interpolation) { {} }
15
16
 
16
17
  before do
17
- allow(repository).to receive(:group_by_key).and_return({ 'example_test' => translation })
18
+ allow(repository).to receive(:group_by_key).and_return({ key => translation })
18
19
  end
19
20
 
20
21
  subject { service.translate(input, interpolation.merge('locale' => locale, 'scope' => scope)) }
@@ -50,6 +51,15 @@ describe Locomotive::Steam::TranslatorService do
50
51
 
51
52
  it { is_expected.to eq 'French' }
52
53
 
54
+ context 'the translation has been overwritten for the site' do
55
+
56
+ let(:key) { 'locomotive_locales_fr' }
57
+ let(:translation) { { 'en' => 'Français' } }
58
+
59
+ it { is_expected.to eq 'Français' }
60
+
61
+ end
62
+
53
63
  end
54
64
 
55
65
  describe 'interpolation' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotivecms_steam
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0.beta3
4
+ version: 1.5.0.rc0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-03-06 00:00:00.000000000 Z
14
+ date: 2019-04-25 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -451,6 +451,7 @@ files:
451
451
  - config/locales/pl.yml
452
452
  - config/locales/pt-BR.yml
453
453
  - config/locales/ru.yml
454
+ - docker-compose.yml
454
455
  - lib/locomotive/steam.rb
455
456
  - lib/locomotive/steam/adapters/concerns/key.rb
456
457
  - lib/locomotive/steam/adapters/filesystem.rb
@@ -565,13 +566,16 @@ files:
565
566
  - lib/locomotive/steam/liquid/template.rb
566
567
  - lib/locomotive/steam/middlewares.rb
567
568
  - lib/locomotive/steam/middlewares/auth.rb
569
+ - lib/locomotive/steam/middlewares/concerns/auth_helpers.rb
568
570
  - lib/locomotive/steam/middlewares/concerns/helpers.rb
569
571
  - lib/locomotive/steam/middlewares/concerns/liquid_context.rb
572
+ - lib/locomotive/steam/middlewares/concerns/recaptcha.rb
570
573
  - lib/locomotive/steam/middlewares/default_env.rb
571
574
  - lib/locomotive/steam/middlewares/dynamic_assets.rb
572
575
  - lib/locomotive/steam/middlewares/encoded_link_redirection.rb
573
576
  - lib/locomotive/steam/middlewares/entry_submission.rb
574
577
  - lib/locomotive/steam/middlewares/favicon.rb
578
+ - lib/locomotive/steam/middlewares/impersonated_entry.rb
575
579
  - lib/locomotive/steam/middlewares/locale.rb
576
580
  - lib/locomotive/steam/middlewares/locale_redirection.rb
577
581
  - lib/locomotive/steam/middlewares/logging.rb
@@ -622,6 +626,7 @@ files:
622
626
  - lib/locomotive/steam/services/auth_service.rb
623
627
  - lib/locomotive/steam/services/concerns/decorator.rb
624
628
  - lib/locomotive/steam/services/content_entry_service.rb
629
+ - lib/locomotive/steam/services/cookie_service.rb
625
630
  - lib/locomotive/steam/services/csrf_protection_service.rb
626
631
  - lib/locomotive/steam/services/editable_element_service.rb
627
632
  - lib/locomotive/steam/services/email_service.rb
@@ -634,6 +639,7 @@ files:
634
639
  - lib/locomotive/steam/services/page_finder_service.rb
635
640
  - lib/locomotive/steam/services/page_redirection_service.rb
636
641
  - lib/locomotive/steam/services/parent_finder_service.rb
642
+ - lib/locomotive/steam/services/recaptcha_service.rb
637
643
  - lib/locomotive/steam/services/section_finder_service.rb
638
644
  - lib/locomotive/steam/services/site_finder_service.rb
639
645
  - lib/locomotive/steam/services/snippet_finder_service.rb
@@ -881,6 +887,7 @@ files:
881
887
  - spec/unit/middlewares/encoded_link_redirection_spec.rb
882
888
  - spec/unit/middlewares/entry_submission_spec.rb
883
889
  - spec/unit/middlewares/helpers_spec.rb
890
+ - spec/unit/middlewares/impersonated_entry_spec.rb
884
891
  - spec/unit/middlewares/locale_redirection_spec.rb
885
892
  - spec/unit/middlewares/locale_spec.rb
886
893
  - spec/unit/middlewares/page_spec.rb
@@ -911,13 +918,16 @@ files:
911
918
  - spec/unit/services/asset_host_service_spec.rb
912
919
  - spec/unit/services/auth_service_spec.rb
913
920
  - spec/unit/services/content_entry_service_spec.rb
921
+ - spec/unit/services/cookie_service_spec.rb
914
922
  - spec/unit/services/email_service_spec.rb
915
923
  - spec/unit/services/entry_submission_service_spec.rb
916
924
  - spec/unit/services/external_api_service_spec.rb
917
925
  - spec/unit/services/image_resizer_service_spec.rb
918
926
  - spec/unit/services/markdown_service_spec.rb
927
+ - spec/unit/services/page_finder_service_spec.rb
919
928
  - spec/unit/services/page_redirection_service_spec.rb
920
929
  - spec/unit/services/parent_finder_service_spec.rb
930
+ - spec/unit/services/recaptcha_service_spec.rb
921
931
  - spec/unit/services/section_finder_service_spec.rb
922
932
  - spec/unit/services/textile_service_spec.rb
923
933
  - spec/unit/services/translator_service_spec.rb
@@ -1185,6 +1195,7 @@ test_files:
1185
1195
  - spec/unit/middlewares/encoded_link_redirection_spec.rb
1186
1196
  - spec/unit/middlewares/entry_submission_spec.rb
1187
1197
  - spec/unit/middlewares/helpers_spec.rb
1198
+ - spec/unit/middlewares/impersonated_entry_spec.rb
1188
1199
  - spec/unit/middlewares/locale_redirection_spec.rb
1189
1200
  - spec/unit/middlewares/locale_spec.rb
1190
1201
  - spec/unit/middlewares/page_spec.rb
@@ -1215,13 +1226,16 @@ test_files:
1215
1226
  - spec/unit/services/asset_host_service_spec.rb
1216
1227
  - spec/unit/services/auth_service_spec.rb
1217
1228
  - spec/unit/services/content_entry_service_spec.rb
1229
+ - spec/unit/services/cookie_service_spec.rb
1218
1230
  - spec/unit/services/email_service_spec.rb
1219
1231
  - spec/unit/services/entry_submission_service_spec.rb
1220
1232
  - spec/unit/services/external_api_service_spec.rb
1221
1233
  - spec/unit/services/image_resizer_service_spec.rb
1222
1234
  - spec/unit/services/markdown_service_spec.rb
1235
+ - spec/unit/services/page_finder_service_spec.rb
1223
1236
  - spec/unit/services/page_redirection_service_spec.rb
1224
1237
  - spec/unit/services/parent_finder_service_spec.rb
1238
+ - spec/unit/services/recaptcha_service_spec.rb
1225
1239
  - spec/unit/services/section_finder_service_spec.rb
1226
1240
  - spec/unit/services/textile_service_spec.rb
1227
1241
  - spec/unit/services/translator_service_spec.rb