webspicy 0.20.12 → 0.20.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a280bcc156de5e615f010269f8d3dcdca0263b5d5141e3dc7ae3f15e4cdb3af8
4
- data.tar.gz: 1d37b10be638894707bfe31ee52f159ffbf68ddd24c0097383d4588a380fb627
3
+ metadata.gz: db9ccb05ac501d744769feebb3bb41d5775727fbf11b2507cd3d2aee6d0b6f10
4
+ data.tar.gz: 5b314097454003e48edd6e72a94e05f439709478586ac0eefb1a31eed1192d37
5
5
  SHA512:
6
- metadata.gz: ec5e2fddb49307367af9e46115b81ac6b7d7cdbb971efec0cc03c4fdd9be9ee92fd35fba1430e7e708552f77456019927210132f3951c3ed0f7beb78e93b9bf1
7
- data.tar.gz: 1ae63f53ee9e5f826dd8c7f7739f4814895e7000c75149b80fd1faa6378e23270970f846f634c2c28808b814b63a15b60c53a285d139985b857f3e07d01e497d
6
+ metadata.gz: 40dcc1ae84b4bd1146412435663e2d2198c53dc15cc858b5e88370656d6bf612b056b542cb7efef71b69dec395bbb0a36766b731f053c84b1f760c66e02ff942
7
+ data.tar.gz: 29744550467db7bd83ad6e102e8296fe4df99911f2b29c77af66488ef37320bbfecf8a37258e931cde4bd7b3a02715b733125e3fbefa73cbe13e72fd3bba511b
@@ -9,13 +9,32 @@ module Webspicy
9
9
  attr_reader :data
10
10
 
11
11
  def from
12
- @from ||= data["from"]["email"]
12
+ @from ||= data['from']['name'] ?
13
+ "#{data['from']['name']} <#{data['from']['email']}>" :
14
+ data['from']['email']
13
15
  end
14
16
 
15
17
  def to
16
18
  @to ||= data["personalizations"]
17
19
  .select{|h| h.key? "to" }
18
20
  .map{|(h)| h["to"] }
21
+ .flatten
22
+ .map{|(h)| h["email"] }
23
+ end
24
+
25
+ def cc
26
+ @cc ||= data["personalizations"]
27
+ .select{|h| h.key? "cc" }
28
+ .map{|(h)| h["cc"] }
29
+ .flatten
30
+ .map{|(h)| h["email"] }
31
+ end
32
+
33
+ def bcc
34
+ @bcc ||= data["personalizations"]
35
+ .select{|h| h.key? "bcc" }
36
+ .map{|(h)| h["bcc"] }
37
+ .flatten
19
38
  .map{|(h)| h["email"] }
20
39
  end
21
40
 
@@ -23,6 +42,13 @@ module Webspicy
23
42
  @subject ||= data["subject"]
24
43
  end
25
44
 
45
+ def headers
46
+ @headers ||= data["headers"].reduce(OpenStruct.new){|acc, (key, value)|
47
+ acc[key.downcase] = value
48
+ acc
49
+ }
50
+ end
51
+
26
52
  end # class Email
27
53
  end # class Fakesendgrid
28
54
  end # class Tester
@@ -1,3 +1,5 @@
1
+ require 'mail'
2
+
1
3
  module Webspicy
2
4
  class Tester
3
5
  class Fakeses
@@ -9,23 +11,43 @@ module Webspicy
9
11
  attr_reader :data
10
12
 
11
13
  def from
12
- data["body"]["Source"]
14
+ email.from[0]
13
15
  end
14
16
 
15
- def to
17
+ def recipients
16
18
  data["body"]
17
19
  .each_pair
18
20
  .select{|(k,v)|
19
21
  k =~ /Destinations.member/
20
22
  }
21
- .map{|(k,v)| v }
23
+ .map{|(k,v)| v.strip }
24
+ end
25
+
26
+ def to
27
+ email.to || []
22
28
  end
23
29
 
24
30
  def subject
25
- rx = /^Subject:\s*(.*)$/
26
- raw_data
27
- .each_line
28
- .find{|l| l =~ rx }[rx, 1]
31
+ email.subject
32
+ end
33
+
34
+ def cc
35
+ email.cc || []
36
+ end
37
+
38
+ def bcc
39
+ recipients - cc - to
40
+ end
41
+
42
+ def headers
43
+ @headers ||= email.header.reduce(OpenStruct.new){|acc, h|
44
+ acc[h.name.downcase] = h.unparsed_value
45
+ acc
46
+ }
47
+ end
48
+
49
+ def email
50
+ @email ||= Mail.read_from_string(raw_data)
29
51
  end
30
52
 
31
53
  def raw_data
@@ -16,9 +16,13 @@ module Webspicy
16
16
  end
17
17
 
18
18
  def to
19
- @to ||= data["headerLines"]
20
- .select{|h| h["key"] == "to" }
21
- .map{|h| h["line"][/To:\s*(.*)$/, 1] }
19
+ @to ||= data["to"]["value"]
20
+ .map{|h| h["address"] }
21
+ end
22
+
23
+ def cc
24
+ @cc ||= data["cc"]["value"]
25
+ .map{|h| h["address"] }
22
26
  end
23
27
 
24
28
  def reply_to
@@ -34,6 +38,14 @@ module Webspicy
34
38
  .first
35
39
  end
36
40
 
41
+ def headers
42
+ @headers ||= data["headerLines"]
43
+ .reduce(OpenStruct.new){|acc, h|
44
+ acc[h["key"].downcase] = h["line"].split(': ')[1..].join(': ')
45
+ acc
46
+ }
47
+ end
48
+
37
49
  end # class Email
38
50
  end # class Fakesmtp
39
51
  end # class Tester
@@ -2,7 +2,7 @@ module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 20
5
- TINY = 12
5
+ TINY = 17
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
@@ -9,15 +9,28 @@ module Webspicy
9
9
  {
10
10
  "datetime": "2021-06-02T15:29:27.161Z",
11
11
  "from": {
12
- "email": "info@mydomain.be",
13
- "name": "Foo Bar"
12
+ "email": "noreply@webspicy.io",
13
+ "name": "Webspicy"
14
14
  },
15
15
  "subject": "Hello World",
16
16
  "personalizations": [
17
17
  {
18
18
  "to": [
19
19
  {
20
- "email": "support@mydomain.fr"
20
+ "email": "someone@world.com"
21
+ },
22
+ {
23
+ "email": "someoneelse@world.com"
24
+ }
25
+ ],
26
+ "cc": [
27
+ {
28
+ "email": "a-cc-recipient@world.com"
29
+ }
30
+ ],
31
+ "bcc": [
32
+ {
33
+ "email": "a-bcc-recipient@world.com"
21
34
  }
22
35
  ]
23
36
  }
@@ -31,7 +44,10 @@ module Webspicy
31
44
  "value": "test <b>test</b> test",
32
45
  "type": "text/html"
33
46
  }
34
- ]
47
+ ],
48
+ "headers": {
49
+ "x-header-key": "personalised-header-value"
50
+ }
35
51
  }
36
52
  J
37
53
 
@@ -40,9 +56,12 @@ module Webspicy
40
56
  }
41
57
 
42
58
  it 'works as expected' do
43
- expect(subject.from).to eql("info@mydomain.be")
44
- expect(subject.to).to eql(["support@mydomain.fr"])
59
+ expect(subject.from).to eql("Webspicy <noreply@webspicy.io>")
60
+ expect(subject.to).to eql(["someone@world.com", "someoneelse@world.com"])
61
+ expect(subject.cc).to eql(["a-cc-recipient@world.com"])
62
+ expect(subject.bcc).to eql(["a-bcc-recipient@world.com"])
45
63
  expect(subject.subject).to eql("Hello World")
64
+ expect(subject.headers['x-header-key']).to eql('personalised-header-value')
46
65
  end
47
66
 
48
67
  end
@@ -6,9 +6,28 @@ module Webspicy
6
6
  describe Email do
7
7
 
8
8
  DATA = Base64.encode64 <<~J
9
- From: Webspicy <noreply@webspicy.io>
10
- To: someone@world.com
11
- Subject: Hey world, hello!
9
+ Content-Type: multipart/alternative;
10
+ boundary="--_NmP-d246fd025a6652c9-Part_1"
11
+ From: Webspicy <noreply@webspicy.io>
12
+ To: someone@world.com, someoneelse@world.com
13
+ CC: a-cc-recipient@world.com
14
+ Subject: Hey world, hello!
15
+ X-Ses-Configuration-Set: SesConfigurationSet
16
+ Message-ID: <2421bae3-9c42-7988-23b4-b1f6168130c9@webspicy.io>
17
+ Date: Thu, 24 Jun 2021 13:45:16 +0000
18
+ MIME-Version: 1.0
19
+
20
+ ----_NmP-d246fd025a6652c9-Part_1
21
+ Content-Type: text/plain; charset=utf-8
22
+ Content-Transfer-Encoding: 7bit
23
+
24
+ Hello world, in a text version
25
+ ----_NmP-d246fd025a6652c9-Part_1
26
+ Content-Type: text/html; charset=utf-8
27
+ Content-Transfer-Encoding: 7bit
28
+
29
+ Hello world, in an html version
30
+ ----_NmP-d246fd025a6652c9-Part_1--
12
31
  J
13
32
 
14
33
  DATA = JSON.parse <<~J
@@ -17,6 +36,9 @@ module Webspicy
17
36
  "body": {
18
37
  "Source": "noreply@webspicy.io",
19
38
  "Destinations.member.1": "someone@world.com",
39
+ "Destinations.member.2": "someoneelse@world.com",
40
+ "Destinations.member.3": "a-cc-recipient@world.com",
41
+ "Destinations.member.4": "a-bcc-recipient@world.com",
20
42
  "RawMessage.Data": "#{DATA.gsub /\n/, ''}",
21
43
  "Action": "SendRawEmail",
22
44
  "Version": "2010-12-01"
@@ -30,8 +52,15 @@ module Webspicy
30
52
 
31
53
  it 'works as expected' do
32
54
  expect(subject.from).to eql("noreply@webspicy.io")
33
- expect(subject.to).to eql(["someone@world.com"])
55
+ expect(subject.to).to eql(["someone@world.com", "someoneelse@world.com"])
56
+ expect(subject.cc).to eql(["a-cc-recipient@world.com"])
57
+ expect(subject.bcc).to eql(["a-bcc-recipient@world.com"])
34
58
  expect(subject.subject).to eql("Hey world, hello!")
59
+ expect(subject.headers[:from]).to eql("Webspicy <noreply@webspicy.io>")
60
+ expect(subject.headers[:cc]).to eql("a-cc-recipient@world.com")
61
+ expect(subject.headers["message-id"]).to eql("<2421bae3-9c42-7988-23b4-b1f6168130c9@webspicy.io>")
62
+ expect(subject.headers["mime-version"]).to eql("1.0")
63
+ expect(subject.headers["x-ses-configuration-set"]).to eql("SesConfigurationSet")
35
64
  end
36
65
 
37
66
  end
@@ -15,15 +15,19 @@ module Webspicy
15
15
  },
16
16
  {
17
17
  "key": "from",
18
- "line": "From: info@mydomain.be"
18
+ "line": "From: Webspicy <noreply@webspicy.io>"
19
19
  },
20
20
  {
21
21
  "key": "reply-to",
22
- "line": "Reply-To: test@email.be"
22
+ "line": "Reply-To: noreply@webspicy.io"
23
23
  },
24
24
  {
25
25
  "key": "to",
26
- "line": "To: support@mydomain.fr"
26
+ "line": "To: someone@world.com, someoneelse@world.com"
27
+ },
28
+ {
29
+ "key": "cc",
30
+ "line": "Cc: a-cc-recipient@world.com"
27
31
  },
28
32
  {
29
33
  "key": "message-id",
@@ -46,12 +50,14 @@ module Webspicy
46
50
  "to": {
47
51
  "value": [
48
52
  {
49
- "address": "support@mydomain.fr",
53
+ "address": "someone@world.com",
54
+ "name": ""
55
+ },
56
+ {
57
+ "address": "someoneelse@world.com",
50
58
  "name": ""
51
59
  }
52
- ],
53
- "html": "<span class=\\"mp_address_group\\"><a href=\\"mailto:support@mydomain.fr\\" class=\\"mp_address_email\\">support@mydomain.fr</a></span>",
54
- "text": "support@mydomain.fr"
60
+ ]
55
61
  },
56
62
  "from": {
57
63
  "value": [
@@ -59,20 +65,24 @@ module Webspicy
59
65
  "address": "info@mydomain.be",
60
66
  "name": ""
61
67
  }
62
- ],
63
- "html": "<span class=\\"mp_address_group\\"><a href=\\"mailto:info@mydomain.be\\" class=\\"mp_address_email\\">info@mydomain.be</a></span>",
64
- "text": "info@mydomain.be"
68
+ ]
65
69
  },
66
70
  "messageId": "<607edfd56836e_1b0492af@1d3356d02030.mail>",
67
71
  "replyTo": {
68
72
  "value": [
69
73
  {
70
- "address": "test@email.be",
74
+ "address": "noreply@webspicy.io",
75
+ "name": ""
76
+ }
77
+ ]
78
+ },
79
+ "cc": {
80
+ "value": [
81
+ {
82
+ "address": "a-cc-recipient@world.com",
71
83
  "name": ""
72
84
  }
73
- ],
74
- "html": "<span class=\\"mp_address_group\\"><a href=\\"mailto:test@email.be\\" class=\\"mp_address_email\\">test@email.be</a></span>",
75
- "text": "test@email.be"
85
+ ]
76
86
  }
77
87
  }
78
88
  J
@@ -82,9 +92,14 @@ module Webspicy
82
92
  }
83
93
 
84
94
  it 'works as expected' do
85
- expect(subject.from).to eql("info@mydomain.be")
86
- expect(subject.to).to eql(["support@mydomain.fr"])
95
+ expect(subject.from).to eql("Webspicy <noreply@webspicy.io>")
96
+ expect(subject.to).to eql(["someone@world.com", "someoneelse@world.com"])
97
+ expect(subject.cc).to eql(["a-cc-recipient@world.com"])
87
98
  expect(subject.subject).to eql("Hello World")
99
+ expect(subject.headers[:cc]).to eql("a-cc-recipient@world.com")
100
+ expect(subject.headers[:date]).to eql("Tue, 20 Apr 2021 14:06:13 +0000")
101
+ expect(subject.headers['message-id']).to eql("<607edfd56836e_1b0492af@1d3356d02030.mail>")
102
+ expect(subject.headers['mime-version']).to eql("1.0")
88
103
  end
89
104
 
90
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webspicy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.12
4
+ version: 0.20.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-09 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -212,6 +212,20 @@ dependencies:
212
212
  - - "~>"
213
213
  - !ruby/object:Gem::Version
214
214
  version: '1.0'
215
+ - !ruby/object:Gem::Dependency
216
+ name: mail
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - "~>"
220
+ - !ruby/object:Gem::Version
221
+ version: '2.7'
222
+ type: :runtime
223
+ prerelease: false
224
+ version_requirements: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - "~>"
227
+ - !ruby/object:Gem::Version
228
+ version: '2.7'
215
229
  description: Webspicy helps testing web services as software operation black boxes
216
230
  email: blambeau@gmail.com
217
231
  executables: