punk 0.1.4 → 0.2.0

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.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +9 -0
  3. data/.github/workflows/test.yml +26 -1
  4. data/.rdoc_options +23 -0
  5. data/.rgignore +1 -0
  6. data/.rspec +2 -0
  7. data/Gemfile +5 -6
  8. data/Gemfile.lock +16 -29
  9. data/README.md +1 -1
  10. data/VERSION +1 -1
  11. data/app/migrations/001_lets_punk.rb +3 -0
  12. data/app/routes/hello.rb +4 -0
  13. data/env/.gitignore +3 -0
  14. data/env/spec/test.sh +3 -0
  15. data/lib/punk/actions/.keep +0 -0
  16. data/lib/punk/actions/groups/list.rb +24 -0
  17. data/lib/punk/actions/sessions/clear.rb +21 -0
  18. data/lib/punk/actions/sessions/create.rb +64 -0
  19. data/lib/punk/actions/sessions/list.rb +18 -0
  20. data/lib/punk/actions/sessions/verify.rb +24 -0
  21. data/lib/punk/actions/tenants/list.rb +18 -0
  22. data/lib/punk/actions/users/list_group.rb +18 -0
  23. data/lib/punk/actions/users/list_tenant.rb +18 -0
  24. data/lib/punk/actions/users/show.rb +18 -0
  25. data/lib/punk/commands/list.rb +12 -6
  26. data/lib/punk/config/defaults.json +3 -0
  27. data/lib/punk/config/schema.json +3 -0
  28. data/lib/punk/core/app.rb +4 -6
  29. data/lib/punk/core/commander.rb +7 -4
  30. data/lib/punk/core/exec.rb +2 -0
  31. data/lib/punk/core/load.rb +0 -1
  32. data/lib/punk/framework/command.rb +5 -1
  33. data/lib/punk/framework/plugins/validation.rb +0 -14
  34. data/lib/punk/helpers/loggable.rb +1 -1
  35. data/lib/punk/migrations/001_punk.rb +103 -0
  36. data/lib/punk/models/.keep +0 -0
  37. data/lib/punk/models/group.rb +20 -0
  38. data/lib/punk/models/group_user_metadata.rb +17 -0
  39. data/lib/punk/models/identity.rb +29 -0
  40. data/lib/punk/models/session.rb +89 -0
  41. data/lib/punk/models/tenant.rb +19 -0
  42. data/lib/punk/models/tenant_user_metadata.rb +17 -0
  43. data/lib/punk/models/user.rb +31 -0
  44. data/lib/punk/routes/groups.rb +31 -0
  45. data/lib/punk/routes/plivo.rb +4 -0
  46. data/lib/punk/routes/sessions.rb +108 -0
  47. data/lib/punk/routes/swagger.rb +9 -0
  48. data/lib/punk/routes/tenants.rb +29 -0
  49. data/lib/punk/routes/users.rb +36 -0
  50. data/lib/punk/services/.keep +0 -0
  51. data/lib/punk/services/challenge_claim.rb +46 -0
  52. data/lib/punk/services/create_identities.rb +25 -0
  53. data/lib/punk/services/generate_swagger.rb +25 -0
  54. data/lib/punk/services/prove_claim.rb +29 -0
  55. data/lib/punk/services/secret.rb +9 -0
  56. data/lib/punk/templates/groups/list.jbuilder +7 -0
  57. data/lib/punk/templates/plivo.slim +16 -0
  58. data/lib/punk/templates/sessions/list.jbuilder +6 -0
  59. data/lib/punk/templates/sessions/pending.jbuilder +4 -0
  60. data/lib/punk/templates/tenants/list.jbuilder +7 -0
  61. data/lib/punk/templates/tenants/list.slim +8 -0
  62. data/lib/punk/templates/users/list.jbuilder +7 -0
  63. data/lib/punk/templates/users/list.rcsv +4 -0
  64. data/lib/punk/templates/users/show.jbuilder +5 -0
  65. data/lib/punk/views/groups/list.rb +22 -0
  66. data/lib/punk/views/plivo_store.rb +15 -0
  67. data/lib/punk/views/sessions/list.rb +22 -0
  68. data/lib/punk/views/sessions/pending.rb +28 -0
  69. data/lib/punk/views/tenants/list.rb +22 -0
  70. data/lib/punk/views/users/list.rb +22 -0
  71. data/lib/punk/views/users/show.rb +22 -0
  72. data/lib/punk/workers/.keep +0 -0
  73. data/lib/punk/workers/expire_sessions.rb +9 -0
  74. data/lib/punk/workers/geocode_session_worker.rb +48 -0
  75. data/lib/punk/workers/identify_session_worker.rb +45 -0
  76. data/lib/punk/workers/secret.rb +18 -0
  77. data/lib/punk/workers/send_email_worker.rb +51 -0
  78. data/lib/punk/workers/send_sms_worker.rb +40 -0
  79. data/punk.gemspec +140 -14
  80. data/schema.psql +345 -0
  81. data/spec/actions/groups/punk/list_groups_action_spec.rb +36 -0
  82. data/spec/actions/sessions/punk/clear_session_action_spec.rb +29 -0
  83. data/spec/actions/sessions/punk/create_session_action_spec.rb +33 -0
  84. data/spec/actions/sessions/punk/list_sessions_action_spec.rb +26 -0
  85. data/spec/actions/sessions/punk/verify_session_action_spec.rb +59 -0
  86. data/spec/actions/tenants/punk/list_tenants_action_spec.rb +25 -0
  87. data/spec/actions/users/punk/list_group_users_action_spec.rb +26 -0
  88. data/spec/actions/users/punk/list_tenant_users_action_spec.rb +26 -0
  89. data/spec/factories/group.rb +12 -0
  90. data/spec/factories/group_user_metadata.rb +10 -0
  91. data/spec/factories/identity.rb +19 -0
  92. data/spec/factories/session.rb +12 -0
  93. data/spec/factories/tenant.rb +10 -0
  94. data/spec/factories/tenant_user_metadata.rb +10 -0
  95. data/spec/factories/user.rb +12 -0
  96. data/spec/lib/commands/auth_spec.rb +11 -0
  97. data/spec/lib/commands/generate_spec.rb +7 -0
  98. data/spec/lib/commands/http_spec.rb +23 -0
  99. data/spec/lib/commands/list_spec.rb +7 -0
  100. data/spec/lib/commands/swagger_spec.rb +7 -0
  101. data/spec/lib/engine/punk_env_spec.rb +13 -0
  102. data/spec/lib/engine/punk_exec_spec.rb +9 -0
  103. data/spec/lib/engine/punk_init_spec.rb +9 -0
  104. data/spec/lib/engine/punk_store_spec.rb +10 -0
  105. data/spec/lib/punk.env +7 -0
  106. data/spec/models/punk/group_spec.rb +50 -0
  107. data/spec/models/punk/group_user_metadata_spec.rb +61 -0
  108. data/spec/models/punk/identity_spec.rb +61 -0
  109. data/spec/models/punk/session_spec.rb +156 -0
  110. data/spec/models/punk/tenant_spec.rb +51 -0
  111. data/spec/models/punk/tenant_user_metadata_spec.rb +61 -0
  112. data/spec/models/punk/user_spec.rb +115 -0
  113. data/spec/routes/groups/get_groups_spec.rb +33 -0
  114. data/spec/routes/plivo/get_plivo_spec.rb +11 -0
  115. data/spec/routes/sessions/delete_session_spec.rb +11 -0
  116. data/spec/routes/sessions/get_sessions_spec.rb +30 -0
  117. data/spec/routes/sessions/patch_session_spec.rb +11 -0
  118. data/spec/routes/sessions/post_session_spec.rb +11 -0
  119. data/spec/routes/swagger/get_swagger_spec.rb +12 -0
  120. data/spec/routes/tenants/get_tenants_spec.rb +31 -0
  121. data/spec/routes/users/get_users_spec.rb +60 -0
  122. data/spec/services/punk/challenge_claim_service_spec.rb +7 -0
  123. data/spec/services/punk/create_identities_service_spec.rb +14 -0
  124. data/spec/services/punk/generate_swagger_service_spec.rb +7 -0
  125. data/spec/services/punk/prove_claim_service_spec.rb +7 -0
  126. data/spec/services/punk/secret_service_spec.rb +7 -0
  127. data/spec/spec_helper.rb +122 -0
  128. data/spec/vcr_cassettes/PUNK_GeocodeSessionWorker/updates_the_session_data.yml +57 -0
  129. data/spec/vcr_cassettes/PUNK_IdentifySessionWorker/updates_the_session_data.yml +112 -0
  130. data/spec/views/punk/plivo_store_spec.rb +7 -0
  131. data/spec/views/sessions/punk/list_sessions_view_spec.rb +7 -0
  132. data/spec/views/sessions/punk/pending_session_view_spec.rb +7 -0
  133. data/spec/views/tenants/punk/list_tenants_view_spec.rb +7 -0
  134. data/spec/views/users/punk/list_groups_view_spec.rb +7 -0
  135. data/spec/views/users/punk/list_users_view_spec.rb +7 -0
  136. data/spec/workers/punk/expire_sessions_worker_spec.rb +31 -0
  137. data/spec/workers/punk/geocode_session_worker_spec.rb +14 -0
  138. data/spec/workers/punk/identify_session_worker_spec.rb +15 -0
  139. data/spec/workers/punk/secret_worker_spec.rb +20 -0
  140. data/spec/workers/punk/send_email_worker_spec.rb +46 -0
  141. data/spec/workers/punk/send_sms_worker_spec.rb +33 -0
  142. metadata +148 -11
  143. data/lib/punk/views/all.rb +0 -4
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.ipstack.com/42.221.129.61?access_key=8125be66761ffcad1604896a17d00ac4
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Tue, 12 Jan 2021 09:12:13 GMT
23
+ Content-Type:
24
+ - application/json; Charset=UTF-8
25
+ Transfer-Encoding:
26
+ - chunked
27
+ Connection:
28
+ - keep-alive
29
+ Set-Cookie:
30
+ - __cfduid=df0fa25d4e0073142f3e466cbb8e9237d1610442733; expires=Thu, 11-Feb-21
31
+ 09:12:13 GMT; path=/; domain=.ipstack.com; HttpOnly; SameSite=Lax
32
+ X-Apilayer-Transaction-Id:
33
+ - caef65a2-5cd1-4be2-9d01-a3f045f5e011
34
+ Access-Control-Allow-Methods:
35
+ - GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS
36
+ Access-Control-Allow-Origin:
37
+ - "*"
38
+ X-Request-Time:
39
+ - '0.014'
40
+ Cf-Cache-Status:
41
+ - DYNAMIC
42
+ Cf-Request-Id:
43
+ - '0797770e3300003e76e7ab3000000001'
44
+ Report-To:
45
+ - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=Uenx5X7lc5Ezh895Wc50n0Isr6maHO6FOA%2BRfJjJmgQiXBdHDhrhjBNxBsssKN178ozv9zvrsBtroUCIEdQIEf9QvpWMnfD3bVh1gLHHV44%3D"}],"group":"cf-nel","max_age":604800}'
46
+ Nel:
47
+ - '{"report_to":"cf-nel","max_age":604800}'
48
+ Server:
49
+ - cloudflare
50
+ Cf-Ray:
51
+ - 6105c129e8443e76-ADL
52
+ body:
53
+ encoding: ASCII-8BIT
54
+ string: '{"ip":"42.221.129.61","type":"ipv4","continent_code":"AS","continent_name":"Asia","country_code":"CN","country_name":"China","region_code":"BJ","region_name":"Beijing","city":"Beijing","zip":"100038","latitude":39.912288665771484,"longitude":116.3658676147461,"location":{"geoname_id":1816670,"capital":"Beijing","languages":[{"code":"zh","name":"Chinese","native":"\u4e2d\u6587"}],"country_flag":"http:\/\/assets.ipstack.com\/flags\/cn.svg","country_flag_emoji":"\ud83c\udde8\ud83c\uddf3","country_flag_emoji_unicode":"U+1F1E8
55
+ U+1F1F3","calling_code":"86","is_eu":false}}'
56
+ recorded_at: Thu, 22 Sep 2022 09:28:13 GMT
57
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,112 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.userstack.com/detect?access_key=a4b1af0fb201d34a6d5e457c6b7adb00&ua=Mozilla/5.0%20(Windows%20NT%20x.y%3B%20Win64%3B%20x64%3B%20rv:10.0)%20Gecko/20100101%20Firefox/10.0
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Userstack gem/0.1.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Tue, 12 Jan 2021 09:12:14 GMT
23
+ Content-Type:
24
+ - application/json; Charset=UTF-8
25
+ Transfer-Encoding:
26
+ - chunked
27
+ Connection:
28
+ - keep-alive
29
+ Set-Cookie:
30
+ - __cfduid=db0548b42a779266f4790ea8166bdd4581610442733; expires=Thu, 11-Feb-21
31
+ 09:12:13 GMT; path=/; domain=.userstack.com; HttpOnly; SameSite=Lax
32
+ X-Apilayer-Transaction-Id:
33
+ - 454d0588-d787-4d01-b289-5a0038a25ee7
34
+ Access-Control-Allow-Methods:
35
+ - GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS
36
+ Access-Control-Allow-Origin:
37
+ - "*"
38
+ X-Request-Time:
39
+ - '0.078'
40
+ Cf-Cache-Status:
41
+ - DYNAMIC
42
+ Cf-Request-Id:
43
+ - '079777114700003e638fb08000000001'
44
+ Report-To:
45
+ - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=pLrm5k%2Fi9dtcefUXSTR6PXZbtnMZKqUzyi02QEWLC47MbuX678rfUazHnI2eSEecDBP04Z058W04qlR%2FeqM7g1x6NblI0fMkzM4Prk76ikkanA%3D%3D"}],"group":"cf-nel","max_age":604800}'
46
+ Nel:
47
+ - '{"report_to":"cf-nel","max_age":604800}'
48
+ Server:
49
+ - cloudflare
50
+ Cf-Ray:
51
+ - 6105c12ed9223e63-ADL
52
+ body:
53
+ encoding: ASCII-8BIT
54
+ string: '{"ua":"Mozilla\/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko\/20100101
55
+ Firefox\/10.0","type":"browser","brand":null,"name":null,"url":"https:\/\/www.mozilla.org\/","os":{"name":"Windows","code":"windows","url":"https:\/\/en.wikipedia.org\/wiki\/Windows","family":"Windows","family_code":"windows","family_vendor":"Microsoft
56
+ Corporation.","icon":"https:\/\/assets.userstack.com\/icon\/os\/windows.png","icon_large":"https:\/\/assets.userstack.com\/icon\/os\/windows_big.png"},"device":{"is_mobile_device":false,"type":"desktop","brand":null,"brand_code":null,"brand_url":null,"name":null},"browser":{"name":"Firefox","version":"10.0","version_major":"10","engine":"Gecko"},"crawler":{"is_crawler":false,"category":null,"last_seen":null}}'
57
+ recorded_at: Thu, 22 Sep 2022 09:28:14 GMT
58
+ - request:
59
+ method: get
60
+ uri: http://api.ipstack.com/92.177.45.168?access_key=8125be66761ffcad1604896a17d00ac4
61
+ body:
62
+ encoding: US-ASCII
63
+ string: ''
64
+ headers:
65
+ Accept-Encoding:
66
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
67
+ Accept:
68
+ - "*/*"
69
+ User-Agent:
70
+ - Ruby
71
+ response:
72
+ status:
73
+ code: 200
74
+ message: OK
75
+ headers:
76
+ Date:
77
+ - Tue, 12 Jan 2021 09:12:15 GMT
78
+ Content-Type:
79
+ - application/json; Charset=UTF-8
80
+ Transfer-Encoding:
81
+ - chunked
82
+ Connection:
83
+ - keep-alive
84
+ Set-Cookie:
85
+ - __cfduid=d09629f587b5e96df54ed5c24f57106641610442734; expires=Thu, 11-Feb-21
86
+ 09:12:14 GMT; path=/; domain=.ipstack.com; HttpOnly; SameSite=Lax
87
+ X-Apilayer-Transaction-Id:
88
+ - ed39795d-84f4-4260-85c9-356205d21f34
89
+ Access-Control-Allow-Methods:
90
+ - GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS
91
+ Access-Control-Allow-Origin:
92
+ - "*"
93
+ X-Request-Time:
94
+ - '0.014'
95
+ Cf-Cache-Status:
96
+ - DYNAMIC
97
+ Cf-Request-Id:
98
+ - '07977713f000003e5edc09b000000001'
99
+ Report-To:
100
+ - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=zwkDF9e6nBBIRQ9DRnQhJakXNshZyHSuVB0GDGhrqPJBADBFWnsUL6pQU0eXUHnxouMS5Ec%2Fzd%2BJSe4NZXkogkQ1QCR1vil1gaEo2USlO%2Fs%3D"}],"group":"cf-nel","max_age":604800}'
101
+ Nel:
102
+ - '{"report_to":"cf-nel","max_age":604800}'
103
+ Server:
104
+ - cloudflare
105
+ Cf-Ray:
106
+ - 6105c1331d423e5e-ADL
107
+ body:
108
+ encoding: ASCII-8BIT
109
+ string: '{"ip":"92.177.45.168","type":"ipv4","continent_code":"EU","continent_name":"Europe","country_code":"ES","country_name":"Spain","region_code":"CT","region_name":"Catalonia","city":"Tarragona","zip":"43002","latitude":41.1220588684082,"longitude":1.249400019645691,"location":{"geoname_id":3108288,"capital":"Madrid","languages":[{"code":"es","name":"Spanish","native":"Espa\u00f1ol"},{"code":"eu","name":"Basque","native":"Euskara"},{"code":"ca","name":"Catalan","native":"Catal\u00e0"},{"code":"gl","name":"Galician","native":"Galego"},{"code":"oc","name":"Occitan","native":"Occitan"}],"country_flag":"http:\/\/assets.ipstack.com\/flags\/es.svg","country_flag_emoji":"\ud83c\uddea\ud83c\uddf8","country_flag_emoji_unicode":"U+1F1EA
110
+ U+1F1F8","calling_code":"34","is_eu":true}}'
111
+ recorded_at: Thu, 22 Sep 2022 09:28:15 GMT
112
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::PlivoStore do
4
+ context 'when no spec has been written' do
5
+ it 'shows a warning'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::ListSessionsView do
4
+ context 'when no spec has been written' do
5
+ it 'shows a warning'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::PendingSessionView do
4
+ context 'when no spec has been written' do
5
+ it 'shows a warning'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::ListTenantsView do
4
+ context 'when no spec has been written' do
5
+ it 'shows a warning'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::ListGroupsView do
4
+ context 'when no spec has been written' do
5
+ it 'shows a warning'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::ListUsersView do
4
+ context 'when no spec has been written' do
5
+ it 'shows a warning'
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::ExpireSessionsWorker do
4
+ before do
5
+ create(:session, state: :pending)
6
+ create(:session, state: :active)
7
+ end
8
+
9
+ it "does not expires new pending" do
10
+ expect(PUNK::Session.count).to eq(2)
11
+ described_class.perform_async
12
+ described_class.drain
13
+ expect(PUNK::Session.expired.count).to eq(0)
14
+ end
15
+
16
+ it "expires pending sessions after five minutes" do
17
+ expect(PUNK::Session.pending.count).to eq(1)
18
+ Timecop.travel(5.minutes.from_now)
19
+ described_class.perform_async
20
+ described_class.drain
21
+ expect(PUNK::Session.pending.count).to eq(0)
22
+ end
23
+
24
+ it "expires unused active sessions after one month" do
25
+ expect(PUNK::Session.active.count).to eq(1)
26
+ Timecop.travel(32.days.from_now)
27
+ described_class.perform_async
28
+ described_class.drain
29
+ expect(PUNK::Session.expired.count).to eq(2)
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::GeocodeSessionWorker, :vcr do
4
+ let(:remote_addr) { '42.221.129.61' }
5
+ let(:session) { create(:session, remote_addr: remote_addr) }
6
+
7
+ it 'updates the session data' do
8
+ expect(session.data).to eq({})
9
+ described_class.perform_async(session_id: session.id)
10
+ described_class.drain
11
+ session.reload
12
+ expect(session.data).not_to eq({})
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::IdentifySessionWorker, :vcr do
4
+ let(:user_agent) { 'Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0' }
5
+ let(:remote_addr) { '92.177.45.168' }
6
+ let(:session) { create(:session, user_agent: user_agent, remote_addr: remote_addr) }
7
+
8
+ it 'updates the session data' do
9
+ expect(session.data).to eq({})
10
+ described_class.perform_async(session_id: session.id)
11
+ described_class.drain
12
+ session.reload
13
+ expect(session.data.to_h).not_to eq({})
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::SecretWorker do
4
+ let(:name) { Faker::Alphanumeric.alpha }
5
+
6
+ it "is valid with valid attributes" do
7
+ expect { described_class.perform_async(name: name) }.to change(described_class.jobs, :size).by(1)
8
+ expect { described_class.drain }.not_to raise_error
9
+ end
10
+
11
+ it "is invalid without a name" do
12
+ expect { described_class.perform_async }.to change(described_class.jobs, :size).by(1)
13
+ expect { described_class.drain }.to raise_error(PUNK::BadRequest, "validation failed")
14
+ end
15
+
16
+ it "can be performed immediately" do
17
+ expect { described_class.perform_now(name: name) }.not_to raise_error
18
+ expect { described_class.perform_now }.to raise_error(PUNK::BadRequest, "validation failed")
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::SendEmailWorker do
4
+ let(:from) { Faker::Internet.email }
5
+ let(:to) { Faker::Internet.email }
6
+ let(:title) { Faker::Name.name }
7
+ let(:template) { Faker::Alphanumeric.alpha }
8
+
9
+ before do
10
+ require 'mailgun-ruby'
11
+ Mailgun::Client.deliveries.clear
12
+ end
13
+
14
+ it "is valid with valid attributes" do
15
+ expect { described_class.perform_async(from: from, to: to, subject: title, template: template) }.to change(described_class.jobs, :size).by(1)
16
+ expect { described_class.drain }.not_to raise_error
17
+ end
18
+
19
+ it "is invalid without a from address" do
20
+ expect { described_class.perform_async(to: to, subject: title, template: template) }.to change(described_class.jobs, :size).by(1)
21
+ expect { described_class.drain }.to raise_error(PUNK::BadRequest, "validation failed")
22
+ end
23
+
24
+ it "is invalid without a to address" do
25
+ expect { described_class.perform_async(from: from, subject: title, template: template) }.to change(described_class.jobs, :size).by(1)
26
+ expect { described_class.drain }.to raise_error(PUNK::BadRequest, "validation failed")
27
+ end
28
+
29
+ it "is invalid without a subject" do
30
+ expect { described_class.perform_async(from: from, to: to, template: template) }.to change(described_class.jobs, :size).by(1)
31
+ expect { described_class.drain }.to raise_error(PUNK::BadRequest, "validation failed")
32
+ end
33
+
34
+ it "is invalid without a template" do
35
+ expect { described_class.perform_async(from: from, to: to, subject: title) }.to change(described_class.jobs, :size).by(1)
36
+ expect { described_class.drain }.to raise_error(PUNK::BadRequest, "validation failed")
37
+ end
38
+
39
+ it "sends an email" do
40
+ described_class.perform_async(from: from, to: to, subject: title, template: template)
41
+ described_class.drain
42
+ email = Mailgun::Client.deliveries.first
43
+ expect(email[:from]).to eq(from)
44
+ expect(email[:subject]).to eq(title)
45
+ end
46
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe PUNK::SendSmsWorker do
4
+ let(:to) { generate(:phone) }
5
+ let(:body) { Faker::Lorem.sentence }
6
+
7
+ before do
8
+ PUNK.cache.delete(:plivo)
9
+ end
10
+
11
+ it "is valid with valid attributes" do
12
+ expect { described_class.perform_async(to: to, body: body) }.to change(described_class.jobs, :size).by(1)
13
+ expect { described_class.drain }.not_to raise_error
14
+ end
15
+
16
+ it "is invalid without a to number" do
17
+ expect { described_class.perform_async(body: body) }.to change(described_class.jobs, :size).by(1)
18
+ expect { described_class.drain }.to raise_error(PUNK::BadRequest, "validation failed")
19
+ end
20
+
21
+ it "is invalid without a message body" do
22
+ expect { described_class.perform_async(to: to) }.to change(described_class.jobs, :size).by(1)
23
+ expect { described_class.drain }.to raise_error(PUNK::BadRequest, "validation failed")
24
+ end
25
+
26
+ it "sends an sms" do
27
+ described_class.perform_async(to: to, body: body)
28
+ described_class.drain
29
+ sms = PUNK.cache.get(:plivo).first
30
+ expect(sms[:from]).to eq(PUNK.get.plivo.number)
31
+ expect(sms[:body]).to eq(body)
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: punk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lloyd Kranzky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-09 00:00:00.000000000 Z
11
+ date: 2021-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bootsnap
@@ -291,19 +291,19 @@ dependencies:
291
291
  - !ruby/object:Gem::Version
292
292
  version: '2.1'
293
293
  - !ruby/object:Gem::Dependency
294
- name: maxmind-db
294
+ name: ipstack
295
295
  requirement: !ruby/object:Gem::Requirement
296
296
  requirements:
297
297
  - - "~>"
298
298
  - !ruby/object:Gem::Version
299
- version: '1.1'
299
+ version: '0.1'
300
300
  type: :runtime
301
301
  prerelease: false
302
302
  version_requirements: !ruby/object:Gem::Requirement
303
303
  requirements:
304
304
  - - "~>"
305
305
  - !ruby/object:Gem::Version
306
- version: '1.1'
306
+ version: '0.1'
307
307
  - !ruby/object:Gem::Dependency
308
308
  name: rbnacl
309
309
  requirement: !ruby/object:Gem::Requirement
@@ -450,14 +450,14 @@ dependencies:
450
450
  requirements:
451
451
  - - "~>"
452
452
  - !ruby/object:Gem::Version
453
- version: '3.10'
453
+ version: '3.11'
454
454
  type: :runtime
455
455
  prerelease: false
456
456
  version_requirements: !ruby/object:Gem::Requirement
457
457
  requirements:
458
458
  - - "~>"
459
459
  - !ruby/object:Gem::Version
460
- version: '3.10'
460
+ version: '3.11'
461
461
  - !ruby/object:Gem::Dependency
462
462
  name: tilt-jbuilder
463
463
  requirement: !ruby/object:Gem::Requirement
@@ -515,19 +515,33 @@ dependencies:
515
515
  - !ruby/object:Gem::Version
516
516
  version: '6.1'
517
517
  - !ruby/object:Gem::Dependency
518
- name: sentry-raven
518
+ name: sentry-ruby
519
519
  requirement: !ruby/object:Gem::Requirement
520
520
  requirements:
521
521
  - - "~>"
522
522
  - !ruby/object:Gem::Version
523
- version: '3.1'
523
+ version: '4.1'
524
524
  type: :runtime
525
525
  prerelease: false
526
526
  version_requirements: !ruby/object:Gem::Requirement
527
527
  requirements:
528
528
  - - "~>"
529
529
  - !ruby/object:Gem::Version
530
- version: '3.1'
530
+ version: '4.1'
531
+ - !ruby/object:Gem::Dependency
532
+ name: sentry-sidekiq
533
+ requirement: !ruby/object:Gem::Requirement
534
+ requirements:
535
+ - - "~>"
536
+ - !ruby/object:Gem::Version
537
+ version: '4.1'
538
+ type: :runtime
539
+ prerelease: false
540
+ version_requirements: !ruby/object:Gem::Requirement
541
+ requirements:
542
+ - - "~>"
543
+ - !ruby/object:Gem::Version
544
+ version: '4.1'
531
545
  - !ruby/object:Gem::Dependency
532
546
  name: skylight
533
547
  requirement: !ruby/object:Gem::Requirement
@@ -664,8 +678,12 @@ extra_rdoc_files:
664
678
  - README.md
665
679
  files:
666
680
  - ".document"
681
+ - ".editorconfig"
667
682
  - ".github/workflows/ship.yml"
668
683
  - ".github/workflows/test.yml"
684
+ - ".rdoc_options"
685
+ - ".rgignore"
686
+ - ".rspec"
669
687
  - ".rubocop.yml"
670
688
  - Gemfile
671
689
  - Gemfile.lock
@@ -673,9 +691,23 @@ files:
673
691
  - README.md
674
692
  - Rakefile
675
693
  - VERSION
694
+ - app/migrations/001_lets_punk.rb
695
+ - app/routes/hello.rb
676
696
  - bin/punk
697
+ - env/.gitignore
698
+ - env/spec/test.sh
677
699
  - env/test.sh
678
700
  - lib/punk.rb
701
+ - lib/punk/actions/.keep
702
+ - lib/punk/actions/groups/list.rb
703
+ - lib/punk/actions/sessions/clear.rb
704
+ - lib/punk/actions/sessions/create.rb
705
+ - lib/punk/actions/sessions/list.rb
706
+ - lib/punk/actions/sessions/verify.rb
707
+ - lib/punk/actions/tenants/list.rb
708
+ - lib/punk/actions/users/list_group.rb
709
+ - lib/punk/actions/users/list_tenant.rb
710
+ - lib/punk/actions/users/show.rb
679
711
  - lib/punk/commands/auth.rb
680
712
  - lib/punk/commands/generate.rb
681
713
  - lib/punk/commands/http.rb
@@ -719,9 +751,30 @@ files:
719
751
  - lib/punk/helpers/renderable.rb
720
752
  - lib/punk/helpers/swagger.rb
721
753
  - lib/punk/helpers/validatable.rb
754
+ - lib/punk/migrations/001_punk.rb
755
+ - lib/punk/models/.keep
756
+ - lib/punk/models/group.rb
757
+ - lib/punk/models/group_user_metadata.rb
758
+ - lib/punk/models/identity.rb
759
+ - lib/punk/models/session.rb
760
+ - lib/punk/models/tenant.rb
761
+ - lib/punk/models/tenant_user_metadata.rb
762
+ - lib/punk/models/user.rb
722
763
  - lib/punk/plugins/all.rb
723
764
  - lib/punk/plugins/cors.rb
724
765
  - lib/punk/plugins/ssl.rb
766
+ - lib/punk/routes/groups.rb
767
+ - lib/punk/routes/plivo.rb
768
+ - lib/punk/routes/sessions.rb
769
+ - lib/punk/routes/swagger.rb
770
+ - lib/punk/routes/tenants.rb
771
+ - lib/punk/routes/users.rb
772
+ - lib/punk/services/.keep
773
+ - lib/punk/services/challenge_claim.rb
774
+ - lib/punk/services/create_identities.rb
775
+ - lib/punk/services/generate_swagger.rb
776
+ - lib/punk/services/prove_claim.rb
777
+ - lib/punk/services/secret.rb
725
778
  - lib/punk/startup/cache.rb
726
779
  - lib/punk/startup/database.rb
727
780
  - lib/punk/startup/environment.rb
@@ -731,14 +784,98 @@ files:
731
784
  - lib/punk/templates/fail.rcsv
732
785
  - lib/punk/templates/fail.slim
733
786
  - lib/punk/templates/fail.xml.slim
787
+ - lib/punk/templates/groups/list.jbuilder
734
788
  - lib/punk/templates/info.jbuilder
735
789
  - lib/punk/templates/info.rcsv
736
790
  - lib/punk/templates/info.slim
737
791
  - lib/punk/templates/info.xml.slim
738
- - lib/punk/views/all.rb
792
+ - lib/punk/templates/plivo.slim
793
+ - lib/punk/templates/sessions/list.jbuilder
794
+ - lib/punk/templates/sessions/pending.jbuilder
795
+ - lib/punk/templates/tenants/list.jbuilder
796
+ - lib/punk/templates/tenants/list.slim
797
+ - lib/punk/templates/users/list.jbuilder
798
+ - lib/punk/templates/users/list.rcsv
799
+ - lib/punk/templates/users/show.jbuilder
739
800
  - lib/punk/views/fail.rb
801
+ - lib/punk/views/groups/list.rb
740
802
  - lib/punk/views/info.rb
803
+ - lib/punk/views/plivo_store.rb
804
+ - lib/punk/views/sessions/list.rb
805
+ - lib/punk/views/sessions/pending.rb
806
+ - lib/punk/views/tenants/list.rb
807
+ - lib/punk/views/users/list.rb
808
+ - lib/punk/views/users/show.rb
809
+ - lib/punk/workers/.keep
810
+ - lib/punk/workers/expire_sessions.rb
811
+ - lib/punk/workers/geocode_session_worker.rb
812
+ - lib/punk/workers/identify_session_worker.rb
813
+ - lib/punk/workers/secret.rb
814
+ - lib/punk/workers/send_email_worker.rb
815
+ - lib/punk/workers/send_sms_worker.rb
741
816
  - punk.gemspec
817
+ - schema.psql
818
+ - spec/actions/groups/punk/list_groups_action_spec.rb
819
+ - spec/actions/sessions/punk/clear_session_action_spec.rb
820
+ - spec/actions/sessions/punk/create_session_action_spec.rb
821
+ - spec/actions/sessions/punk/list_sessions_action_spec.rb
822
+ - spec/actions/sessions/punk/verify_session_action_spec.rb
823
+ - spec/actions/tenants/punk/list_tenants_action_spec.rb
824
+ - spec/actions/users/punk/list_group_users_action_spec.rb
825
+ - spec/actions/users/punk/list_tenant_users_action_spec.rb
826
+ - spec/factories/group.rb
827
+ - spec/factories/group_user_metadata.rb
828
+ - spec/factories/identity.rb
829
+ - spec/factories/session.rb
830
+ - spec/factories/tenant.rb
831
+ - spec/factories/tenant_user_metadata.rb
832
+ - spec/factories/user.rb
833
+ - spec/lib/commands/auth_spec.rb
834
+ - spec/lib/commands/generate_spec.rb
835
+ - spec/lib/commands/http_spec.rb
836
+ - spec/lib/commands/list_spec.rb
837
+ - spec/lib/commands/swagger_spec.rb
838
+ - spec/lib/engine/punk_env_spec.rb
839
+ - spec/lib/engine/punk_exec_spec.rb
840
+ - spec/lib/engine/punk_init_spec.rb
841
+ - spec/lib/engine/punk_store_spec.rb
842
+ - spec/lib/punk.env
843
+ - spec/models/punk/group_spec.rb
844
+ - spec/models/punk/group_user_metadata_spec.rb
845
+ - spec/models/punk/identity_spec.rb
846
+ - spec/models/punk/session_spec.rb
847
+ - spec/models/punk/tenant_spec.rb
848
+ - spec/models/punk/tenant_user_metadata_spec.rb
849
+ - spec/models/punk/user_spec.rb
850
+ - spec/routes/groups/get_groups_spec.rb
851
+ - spec/routes/plivo/get_plivo_spec.rb
852
+ - spec/routes/sessions/delete_session_spec.rb
853
+ - spec/routes/sessions/get_sessions_spec.rb
854
+ - spec/routes/sessions/patch_session_spec.rb
855
+ - spec/routes/sessions/post_session_spec.rb
856
+ - spec/routes/swagger/get_swagger_spec.rb
857
+ - spec/routes/tenants/get_tenants_spec.rb
858
+ - spec/routes/users/get_users_spec.rb
859
+ - spec/services/punk/challenge_claim_service_spec.rb
860
+ - spec/services/punk/create_identities_service_spec.rb
861
+ - spec/services/punk/generate_swagger_service_spec.rb
862
+ - spec/services/punk/prove_claim_service_spec.rb
863
+ - spec/services/punk/secret_service_spec.rb
864
+ - spec/spec_helper.rb
865
+ - spec/vcr_cassettes/PUNK_GeocodeSessionWorker/updates_the_session_data.yml
866
+ - spec/vcr_cassettes/PUNK_IdentifySessionWorker/updates_the_session_data.yml
867
+ - spec/views/punk/plivo_store_spec.rb
868
+ - spec/views/sessions/punk/list_sessions_view_spec.rb
869
+ - spec/views/sessions/punk/pending_session_view_spec.rb
870
+ - spec/views/tenants/punk/list_tenants_view_spec.rb
871
+ - spec/views/users/punk/list_groups_view_spec.rb
872
+ - spec/views/users/punk/list_users_view_spec.rb
873
+ - spec/workers/punk/expire_sessions_worker_spec.rb
874
+ - spec/workers/punk/geocode_session_worker_spec.rb
875
+ - spec/workers/punk/identify_session_worker_spec.rb
876
+ - spec/workers/punk/secret_worker_spec.rb
877
+ - spec/workers/punk/send_email_worker_spec.rb
878
+ - spec/workers/punk/send_sms_worker_spec.rb
742
879
  homepage: https://github.com/kranzky/punk
743
880
  licenses:
744
881
  - Unlicense