gov_fake_notify 1.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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +15 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +87 -0
- data/LICENSE.txt +21 -0
- data/README.md +271 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/gov_fake_notify +5 -0
- data/gov_fake_notify.gemspec +40 -0
- data/lib/gov_fake_notify/attachment_store.rb +48 -0
- data/lib/gov_fake_notify/cli/root.rb +53 -0
- data/lib/gov_fake_notify/cli.rb +3 -0
- data/lib/gov_fake_notify/commands/create_template_command.rb +35 -0
- data/lib/gov_fake_notify/commands/fetch_all_messages_status_command.rb +45 -0
- data/lib/gov_fake_notify/commands/fetch_file_command.rb +41 -0
- data/lib/gov_fake_notify/commands/fetch_message_status_command.rb +44 -0
- data/lib/gov_fake_notify/commands/fetch_templates_command.rb +43 -0
- data/lib/gov_fake_notify/commands/send_email_command.rb +153 -0
- data/lib/gov_fake_notify/config.rb +42 -0
- data/lib/gov_fake_notify/control_app.rb +31 -0
- data/lib/gov_fake_notify/current_service.rb +22 -0
- data/lib/gov_fake_notify/files_app.rb +41 -0
- data/lib/gov_fake_notify/iodine.rb +9 -0
- data/lib/gov_fake_notify/notifications_app.rb +58 -0
- data/lib/gov_fake_notify/root_app.rb +23 -0
- data/lib/gov_fake_notify/store.rb +27 -0
- data/lib/gov_fake_notify/templates_app.rb +32 -0
- data/lib/gov_fake_notify/version.rb +5 -0
- data/lib/gov_fake_notify.rb +72 -0
- data/lib/views/files/confirm.html.erb +118 -0
- data/lib/views/files/download.html.erb +119 -0
- data/lib/views/govuk/file.html.erb +3 -0
- data/lib/views/govuk/horizontal_line.html.erb +1 -0
- data/lib/views/govuk/paragraph.html.erb +1 -0
- data/lib/views/govuk/show.html.erb +19 -0
- data/lib/views/layouts/govuk.html.erb +64 -0
- metadata +219 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6d0b4a0c314fb0765dc52ded119d9de4c8116e102bac5700ab25397568b4fb23
|
|
4
|
+
data.tar.gz: eb26beb1c5413d77473206756baeec9fdd98bd57b2d4b0f77c1b61ff9a7664ad
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1cba914fabbf22c453f016048d460aa37b0b5fdccec28a616deefdef8c34b1deec1343dfb8a24477cbf36b59737762045d3960055406779ee9a2a5722a6bce93
|
|
7
|
+
data.tar.gz: d3d58b3c3e47e3fc8bec35948195a19c1bf3fcb4fb3d465baf6c2c131e09bdb19a84e18421078560d110020a835ac9821dd9ed6e9e4e8ff3877c8ce28d12557d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# This configuration was generated by
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
3
|
+
# on 2021-09-17 05:44:47 UTC using RuboCop version 1.21.0.
|
|
4
|
+
# The point is for the user to remove these configuration records
|
|
5
|
+
# one by one as the offenses are removed from the code base.
|
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
8
|
+
|
|
9
|
+
# Offense count: 2
|
|
10
|
+
# Configuration parameters: AllowedConstants.
|
|
11
|
+
Style/Documentation:
|
|
12
|
+
Exclude:
|
|
13
|
+
- 'spec/**/*'
|
|
14
|
+
- 'test/**/*'
|
|
15
|
+
- 'lib/gov_fake_notify.rb'
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.7.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
gov_fake_notify (1.1.1)
|
|
5
|
+
activemodel (>= 5.2.3)
|
|
6
|
+
iodine (~> 0.7)
|
|
7
|
+
jwt (~> 2.2, >= 2.2.3)
|
|
8
|
+
mail (~> 2.7, >= 2.7.1)
|
|
9
|
+
roda (~> 3.48)
|
|
10
|
+
thor (~> 1.1)
|
|
11
|
+
tilt (~> 2.0, >= 2.0.10)
|
|
12
|
+
|
|
13
|
+
GEM
|
|
14
|
+
remote: https://rubygems.org/
|
|
15
|
+
specs:
|
|
16
|
+
activemodel (6.1.4.1)
|
|
17
|
+
activesupport (= 6.1.4.1)
|
|
18
|
+
activesupport (6.1.4.1)
|
|
19
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
20
|
+
i18n (>= 1.6, < 2)
|
|
21
|
+
minitest (>= 5.1)
|
|
22
|
+
tzinfo (~> 2.0)
|
|
23
|
+
zeitwerk (~> 2.3)
|
|
24
|
+
ast (2.4.2)
|
|
25
|
+
concurrent-ruby (1.1.9)
|
|
26
|
+
diff-lcs (1.4.4)
|
|
27
|
+
i18n (1.8.10)
|
|
28
|
+
concurrent-ruby (~> 1.0)
|
|
29
|
+
iodine (0.7.44)
|
|
30
|
+
jwt (2.2.3)
|
|
31
|
+
mail (2.7.1)
|
|
32
|
+
mini_mime (>= 0.1.1)
|
|
33
|
+
mini_mime (1.1.1)
|
|
34
|
+
minitest (5.14.4)
|
|
35
|
+
parallel (1.21.0)
|
|
36
|
+
parser (3.0.2.0)
|
|
37
|
+
ast (~> 2.4.1)
|
|
38
|
+
rack (2.2.3)
|
|
39
|
+
rainbow (3.0.0)
|
|
40
|
+
rake (12.3.3)
|
|
41
|
+
regexp_parser (2.1.1)
|
|
42
|
+
rexml (3.2.5)
|
|
43
|
+
roda (3.48.0)
|
|
44
|
+
rack
|
|
45
|
+
rspec (3.10.0)
|
|
46
|
+
rspec-core (~> 3.10.0)
|
|
47
|
+
rspec-expectations (~> 3.10.0)
|
|
48
|
+
rspec-mocks (~> 3.10.0)
|
|
49
|
+
rspec-core (3.10.1)
|
|
50
|
+
rspec-support (~> 3.10.0)
|
|
51
|
+
rspec-expectations (3.10.1)
|
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
53
|
+
rspec-support (~> 3.10.0)
|
|
54
|
+
rspec-mocks (3.10.2)
|
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
56
|
+
rspec-support (~> 3.10.0)
|
|
57
|
+
rspec-support (3.10.2)
|
|
58
|
+
rubocop (1.21.0)
|
|
59
|
+
parallel (~> 1.10)
|
|
60
|
+
parser (>= 3.0.0.0)
|
|
61
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
62
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
63
|
+
rexml
|
|
64
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
|
65
|
+
ruby-progressbar (~> 1.7)
|
|
66
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
67
|
+
rubocop-ast (1.11.0)
|
|
68
|
+
parser (>= 3.0.1.1)
|
|
69
|
+
ruby-progressbar (1.11.0)
|
|
70
|
+
thor (1.1.0)
|
|
71
|
+
tilt (2.0.10)
|
|
72
|
+
tzinfo (2.0.4)
|
|
73
|
+
concurrent-ruby (~> 1.0)
|
|
74
|
+
unicode-display_width (2.1.0)
|
|
75
|
+
zeitwerk (2.4.2)
|
|
76
|
+
|
|
77
|
+
PLATFORMS
|
|
78
|
+
ruby
|
|
79
|
+
|
|
80
|
+
DEPENDENCIES
|
|
81
|
+
gov_fake_notify!
|
|
82
|
+
rake (~> 12.0)
|
|
83
|
+
rspec (~> 3.0)
|
|
84
|
+
rubocop (~> 1.21)
|
|
85
|
+
|
|
86
|
+
BUNDLED WITH
|
|
87
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 garytaylor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# GovFakeNotify
|
|
2
|
+
|
|
3
|
+
This gem provides a standalone tool which emulates the real govuk notify service. It is intended for test and development environments only.
|
|
4
|
+
|
|
5
|
+
IMPORTANT: Whilst this tool can send real emails via SMTP, this is intended for use during development and test only - ideally using something
|
|
6
|
+
like 'mailhog' instead of a real SMTP server.
|
|
7
|
+
|
|
8
|
+
If you have set it up with a real SMTP server, please ensure that the service is NOT exposed to the internet.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Add this line to your application's Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem 'gov_fake_notify'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
And then execute:
|
|
19
|
+
|
|
20
|
+
$ bundle install
|
|
21
|
+
|
|
22
|
+
Or install it yourself as:
|
|
23
|
+
|
|
24
|
+
$ gem install gov_fake_notify
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Command Line Usage
|
|
29
|
+
|
|
30
|
+
If the gem is being used as part of a full stack test suite (i.e. the emails are being sent in a different process to the tests), it can be used as
|
|
31
|
+
a command line tool like this
|
|
32
|
+
|
|
33
|
+
gov_fake_notify start -c ./config.json
|
|
34
|
+
|
|
35
|
+
which will start the server using the config file provided (see configuration below)
|
|
36
|
+
|
|
37
|
+
#### Test Suite Configuration
|
|
38
|
+
|
|
39
|
+
There are 2 ways of validating emails using this gem - either allow the gem to send real emails to a fake smtp server such as mailhog
|
|
40
|
+
OR dont send emails at all and use the 'notifications-ruby-client' to read from the API provided by this gem to see what emails would
|
|
41
|
+
have been sent.
|
|
42
|
+
|
|
43
|
+
Please see the configuration section below to see how to switch modes etc..
|
|
44
|
+
|
|
45
|
+
### In Process Usage
|
|
46
|
+
|
|
47
|
+
if the gem is being used as part of a test suite where the code under test is in the same process as the tests, it can be used alongside 'webmock'
|
|
48
|
+
as follows :-
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
#### In a spec/support/*.rb file OR in rails_helper.rb etc..
|
|
52
|
+
|
|
53
|
+
This is a partial example from the employment tribunals test suite
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
require 'gov_fake_notify'
|
|
57
|
+
RSpec.configure do |c|
|
|
58
|
+
c.before(:each) do
|
|
59
|
+
GovFakeNotify.reset!
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
GovFakeNotify.config do |c|
|
|
63
|
+
c.delivery_method = 'test'
|
|
64
|
+
c.include_templates = [
|
|
65
|
+
{
|
|
66
|
+
id: 'a55e0b84-8d65-4bf4-93a7-e974e0d8d48d', # Note - does not need to be exact id that is used in govuk notify UNLESS
|
|
67
|
+
name: 'et1-confirmation-email-v1-en', # your system has hard coded id's or referenced by environment variables etc..
|
|
68
|
+
subject: 'Employment tribunal: claim submitted',
|
|
69
|
+
message: <<~EOS
|
|
70
|
+
Claim number: ((claim.reference))
|
|
71
|
+
|
|
72
|
+
((primary_claimant.first_name)) ((primary_claimant.last_name))
|
|
73
|
+
|
|
74
|
+
Thank you for submitting your claim to an employment tribunal.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
WHAT HAPPENS NEXT
|
|
79
|
+
|
|
80
|
+
We'll contact you once we have sent your claim to the respondent and explain what happens next.
|
|
81
|
+
At present, this is taking us an average of 25 days.
|
|
82
|
+
Once we have sent them your claim, the respondent has 28 days to reply.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
SUBMISSION DETAILS
|
|
87
|
+
|
|
88
|
+
Claim submitted: ((submitted_date))
|
|
89
|
+
Tribunal office: ((office.name))
|
|
90
|
+
Contact: ((office.email)), ((office.telephone))
|
|
91
|
+
|
|
92
|
+
Your feedback helps us improve this service:
|
|
93
|
+
https://www.gov.uk/done/employment-tribunals-make-a-claim
|
|
94
|
+
|
|
95
|
+
Contact us: http://www.justice.gov.uk/contacts/hmcts/tribunals/employment
|
|
96
|
+
EOS
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
c.include_api_keys = [
|
|
101
|
+
{
|
|
102
|
+
service_name: 'Employment Tribunals',
|
|
103
|
+
service_email: 'employmenttribunals@email.com',
|
|
104
|
+
key: 'fake-key-7fc24bc8-1938-1827-bed3-fb237f9cd5e7-c34b3015-02a1-4e01-b922-1ea21f331d4d' # Your application under test's key -
|
|
105
|
+
# the keys must match.
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
end
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Configuration
|
|
112
|
+
|
|
113
|
+
Configuration can be done using the command line, a config file, environment variables or directly (in process only).
|
|
114
|
+
Note that the configuration can include an API key - do not be tempted to use the same value as the production environment
|
|
115
|
+
as the chances are it will end up in github which is publically accessible.
|
|
116
|
+
|
|
117
|
+
The following configuration entries are available
|
|
118
|
+
|
|
119
|
+
port
|
|
120
|
+
smtp_address
|
|
121
|
+
smtp_port
|
|
122
|
+
smtp_user_name
|
|
123
|
+
smtp_password
|
|
124
|
+
smtp_authentication
|
|
125
|
+
smtp_enable_starttls_auto
|
|
126
|
+
base_url
|
|
127
|
+
database_file
|
|
128
|
+
attachments_path
|
|
129
|
+
delivery_method
|
|
130
|
+
include_templates (config file or direct config only)
|
|
131
|
+
include_api_keys (config file or direct config only)
|
|
132
|
+
|
|
133
|
+
To configure via the command line - use the 'dash' version of the variable - for example
|
|
134
|
+
|
|
135
|
+
--smtp-port instead of smtp_port
|
|
136
|
+
|
|
137
|
+
To configure in the yaml file use the actual variable name
|
|
138
|
+
|
|
139
|
+
### An example yaml config file (from employment tribunals config)
|
|
140
|
+
|
|
141
|
+
```yaml
|
|
142
|
+
---
|
|
143
|
+
port: 8081
|
|
144
|
+
delivery_method: test
|
|
145
|
+
include_templates:
|
|
146
|
+
- id: a55e0b84-8d65-4bf4-93a7-e974e0d8d48d
|
|
147
|
+
name: et1-confirmation-email-v1-en
|
|
148
|
+
subject: "Employment tribunal: claim submitted"
|
|
149
|
+
message: |
|
|
150
|
+
Claim number: ((claim.reference))
|
|
151
|
+
|
|
152
|
+
((primary_claimant.first_name)) ((primary_claimant.last_name))
|
|
153
|
+
|
|
154
|
+
Thank you for submitting your claim to an employment tribunal.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
WHAT HAPPENS NEXT
|
|
159
|
+
|
|
160
|
+
We'll contact you once we have sent your claim to the respondent and explain what happens next.
|
|
161
|
+
At present, this is taking us an average of 25 days.
|
|
162
|
+
Once we have sent them your claim, the respondent has 28 days to reply.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
SUBMISSION DETAILS
|
|
167
|
+
|
|
168
|
+
Claim submitted: ((submitted_date))
|
|
169
|
+
Tribunal office: ((office.name))
|
|
170
|
+
Contact: ((office.email)), ((office.telephone))
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
Please use the link below to download a copy of your claim.
|
|
175
|
+
((link_to_pdf))
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
Additional Information File
|
|
180
|
+
|
|
181
|
+
((link_to_additional_info))
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
Group Claim File
|
|
186
|
+
|
|
187
|
+
((link_to_claimants_file))
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
Your feedback helps us improve this service:
|
|
194
|
+
https://www.gov.uk/done/employment-tribunals-make-a-claim
|
|
195
|
+
|
|
196
|
+
Help us keep track. Complete our diversity monitoring questionnaire.
|
|
197
|
+
https://employmenttribunals.service.gov.uk/en/apply/diversity
|
|
198
|
+
|
|
199
|
+
Contact us: http://www.justice.gov.uk/contacts/hmcts/tribunals/employment
|
|
200
|
+
- id: 97a117f1-727d-4631-bbc6-b2bc98d30a0f
|
|
201
|
+
name: et1-confirmation-email-v1-cy
|
|
202
|
+
subject: "Tribiwnlys Cyflogaeth: hawliad wedi’i gyflwyno"
|
|
203
|
+
message: |
|
|
204
|
+
Eich rhif hawliad: ((claim.reference))
|
|
205
|
+
|
|
206
|
+
((primary_claimant.first_name)) ((primary_claimant.last_name))
|
|
207
|
+
Diolch am gyflwyno eich hawliad i dribiwnlys cyflogaeth.
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
BETH SY'N DIGWYDD NESAF
|
|
211
|
+
|
|
212
|
+
Byddwn yn cysylltu â chi unwaith y byddwn wedi anfon eich hawliad at yr atebydd i egluro beth fydd yn digwydd nesaf. Ar hyn o bryd, mae’n cymryd oddeutu 25 diwrnod.
|
|
213
|
+
Unwaith y byddwn wedi anfon eich hawliad atynt, mae gan yr atebydd 28 diwrnod i ymateb.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
MANYLION CYFLWYNO
|
|
218
|
+
|
|
219
|
+
Hawliad wedi'i gyflwyno: Cyflwynwyd ar ((submitted_date))
|
|
220
|
+
Swyddfa tribiwnlys: Cymru, Tribiwnlys Cyflogaeth
|
|
221
|
+
Cyswllt: ((office.email)), 0300 303 0654
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
Defnyddiwch y ddolen isod i lawrlwytho copi o’ch hawliad.
|
|
226
|
+
((link_to_pdf))
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
Ffeil Gwybodaeth Ychwanegol
|
|
231
|
+
|
|
232
|
+
((link_to_additional_info))
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
Hawliad Grŵp
|
|
237
|
+
|
|
238
|
+
((link_to_claimants_file))
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
Mae eich adborth yn ein helpu i wella'r gwasanaeth hwn:
|
|
243
|
+
https://www.gov.uk/done/employment-tribunals-make-a-claim
|
|
244
|
+
|
|
245
|
+
Helpwch ni i gadw cofnodion cywir . Llenwch ein holiadur monitro amrywiaeth.
|
|
246
|
+
https://employmenttribunals.service.gov.uk/en/apply/diversity
|
|
247
|
+
|
|
248
|
+
Cysylltu â ni: http://www.justice.gov.uk/contacts/hmcts/tribunals/employment
|
|
249
|
+
include_api_keys:
|
|
250
|
+
- service_name: Employment Tribunals
|
|
251
|
+
service_email: employmenttribunals@email.com
|
|
252
|
+
key: fake-key-7fc24bc8-1938-1827-bed3-fb237f9cd5e7-c34b3015-02a1-4e01-b922-1ea21f331d4d
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
## Development
|
|
259
|
+
|
|
260
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
261
|
+
|
|
262
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
263
|
+
|
|
264
|
+
## Contributing
|
|
265
|
+
|
|
266
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gov_fake_notify.
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
## License
|
|
270
|
+
|
|
271
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'gov_fake_notify'
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require 'irb'
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/gov_fake_notify
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/gov_fake_notify/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'gov_fake_notify'
|
|
7
|
+
spec.version = GovFakeNotify::VERSION
|
|
8
|
+
spec.authors = ['garytaylor']
|
|
9
|
+
spec.email = ['gary.taylor@hismessages.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'A fake govuk notify service'
|
|
12
|
+
spec.description = 'A fake govuk notify service that sends emails via smtp for ease of testing'
|
|
13
|
+
spec.homepage = 'https://github.com/hmcts/gov_fake_notify'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/hmcts/gov_fake_notify'
|
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/hmcts/gov_fake_notify/changelog.md'
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = 'exe'
|
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ['lib']
|
|
29
|
+
|
|
30
|
+
spec.add_dependency 'activemodel', '>= 5.2.3'
|
|
31
|
+
spec.add_dependency 'iodine', '~> 0.7'
|
|
32
|
+
spec.add_dependency 'jwt', '~> 2.2', '>= 2.2.3'
|
|
33
|
+
spec.add_dependency 'mail', '~> 2.7', '>= 2.7.1'
|
|
34
|
+
spec.add_dependency 'roda', '~> 3.48'
|
|
35
|
+
spec.add_dependency 'tilt', '~> 2.0', '>= 2.0.10'
|
|
36
|
+
|
|
37
|
+
spec.add_dependency 'thor', '~> 1.1'
|
|
38
|
+
|
|
39
|
+
spec.add_development_dependency 'rubocop', '~> 1.21'
|
|
40
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'singleton'
|
|
4
|
+
require 'pstore'
|
|
5
|
+
require 'securerandom'
|
|
6
|
+
module GovFakeNotify
|
|
7
|
+
# A central store for storing all state in the app - uses a basic PStore
|
|
8
|
+
class AttachmentStore
|
|
9
|
+
include Singleton
|
|
10
|
+
|
|
11
|
+
#
|
|
12
|
+
# Given a hash containing the data that comes from the client side 'prepare_upload' method,
|
|
13
|
+
# this method stores the data in a file and returns the same hash but with the base64 data
|
|
14
|
+
# replaced with a file path where the data is stored.
|
|
15
|
+
#
|
|
16
|
+
# @param [Hash] file_data The data as prepared by 'prepare_upload'
|
|
17
|
+
# @option file_data [String] :file The base64 encoded file
|
|
18
|
+
# @option file_data [Boolean] :is_csv Indicates if the file is csv or not
|
|
19
|
+
#
|
|
20
|
+
# @return [Hash] A copy of the file_data param but with the contents of file replaced
|
|
21
|
+
# with the path of where the file is stored.
|
|
22
|
+
def store(file_data)
|
|
23
|
+
file_path = File.join(attachments_path, SecureRandom.uuid)
|
|
24
|
+
File.open(file_path, 'wb') do |file|
|
|
25
|
+
file.write(Base64.decode64(file_data['file']))
|
|
26
|
+
end
|
|
27
|
+
file_data.merge('file' => file_path)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
# Fetch a file from the store
|
|
32
|
+
#
|
|
33
|
+
# @param [String] id The id of the file - which happens to be the filename
|
|
34
|
+
# @return [Hash, Nil] A hash containing 'file' (the file path) OR nil if not found
|
|
35
|
+
def fetch(id)
|
|
36
|
+
file_path = File.join(attachments_path, id.gsub(/[^a-zA-Z0-9\-]/, ''))
|
|
37
|
+
File.exist?(file_path) ? { 'file' => file_path } : nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
attr_reader :attachments_path
|
|
43
|
+
|
|
44
|
+
def initialize(attachments_path: GovFakeNotify.config.attachments_path)
|
|
45
|
+
@attachments_path = attachments_path
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
require 'gov_fake_notify/iodine'
|
|
5
|
+
require 'uri'
|
|
6
|
+
require 'net/http'
|
|
7
|
+
require 'yaml'
|
|
8
|
+
module GovFakeNotify
|
|
9
|
+
module Cli
|
|
10
|
+
# Root of all commands
|
|
11
|
+
class Root < Thor
|
|
12
|
+
desc 'start', 'Run fake notify'
|
|
13
|
+
method_option :port, type: :numeric, aliases: '-p', description: 'The port number for the web server (defaults to 8080)'
|
|
14
|
+
method_option :config, type: :string, aliases: '-c', description: 'Configuration specified in a yaml file'
|
|
15
|
+
method_option :smtp_address, type: :string
|
|
16
|
+
method_option :smtp_port, type: :numeric
|
|
17
|
+
method_option :smtp_user_name, type: :string
|
|
18
|
+
method_option :smtp_password, type: :string
|
|
19
|
+
method_option :smtp_authentication, type: :string
|
|
20
|
+
method_option :smtp_enable_starttls_auto, type: :string
|
|
21
|
+
method_option :base_url, type: :string
|
|
22
|
+
method_option :database_file, type: :string
|
|
23
|
+
method_option :attachments_path, type: :string
|
|
24
|
+
method_option :delivery_method, type: :string
|
|
25
|
+
|
|
26
|
+
def start
|
|
27
|
+
if options.config
|
|
28
|
+
GovFakeNotify.config do |c|
|
|
29
|
+
c.from(YAML.parse(File.read(options.config)).to_ruby.merge(options.slice(*(options.keys - ['config']))))
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
Rack::Server.start app: GovFakeNotify::RootApp, Port: GovFakeNotify.config.port, server: 'iodine'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
desc 'create-template', 'Create a template'
|
|
36
|
+
method_option :template_id, type: :string, required: true
|
|
37
|
+
method_option :path, type: :string, required: true
|
|
38
|
+
method_option :name, type: :string, required: true
|
|
39
|
+
method_option :subject, type: :string, required: true
|
|
40
|
+
def create_template
|
|
41
|
+
data = {
|
|
42
|
+
id: options.template_id,
|
|
43
|
+
message: File.read(options.path),
|
|
44
|
+
name: options.name,
|
|
45
|
+
subject: options.subject
|
|
46
|
+
}
|
|
47
|
+
res = Net::HTTP.post(URI("#{GovFakeNotify.config.base_url}/control/templates"), JSON.generate(data),
|
|
48
|
+
{ 'Content-Type' => 'application/json', 'Accept' => 'application/json' })
|
|
49
|
+
puts res.body
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'gov_fake_notify/store'
|
|
4
|
+
module GovFakeNotify
|
|
5
|
+
# A service used internally to create a new template from the API / command line
|
|
6
|
+
class CreateTemplateCommand
|
|
7
|
+
def self.call(params)
|
|
8
|
+
# do nothing yet
|
|
9
|
+
new(params).call
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(params, store: Store.instance)
|
|
13
|
+
@params = params
|
|
14
|
+
@store = store
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def call
|
|
18
|
+
store.transaction { store["template-#{params['id']}"] = params }
|
|
19
|
+
|
|
20
|
+
self
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def success?
|
|
24
|
+
true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def to_json(*_args)
|
|
28
|
+
JSON.generate({ success: true })
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
attr_reader :params, :store
|
|
34
|
+
end
|
|
35
|
+
end
|