minty 1.0.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 (58) hide show
  1. checksums.yaml +7 -0
  2. data/.bundle/config +4 -0
  3. data/.devcontainer/Dockerfile +19 -0
  4. data/.devcontainer/devcontainer.json +37 -0
  5. data/.env.example +2 -0
  6. data/.gemrelease +2 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +33 -0
  8. data/.github/dependabot.yml +10 -0
  9. data/.github/stale.yml +20 -0
  10. data/.gitignore +18 -0
  11. data/.rspec +3 -0
  12. data/.rubocop.yml +9 -0
  13. data/CODE_OF_CONDUCT.md +3 -0
  14. data/DEPLOYMENT.md +61 -0
  15. data/DEVELOPMENT.md +35 -0
  16. data/Dockerfile +5 -0
  17. data/EXAMPLES.md +195 -0
  18. data/Gemfile +21 -0
  19. data/Gemfile.lock +250 -0
  20. data/Guardfile +39 -0
  21. data/LICENSE +21 -0
  22. data/Makefile +5 -0
  23. data/README.md +88 -0
  24. data/RUBYGEM.md +9 -0
  25. data/Rakefile +33 -0
  26. data/codecov.yml +22 -0
  27. data/lib/minty/algorithm.rb +7 -0
  28. data/lib/minty/api/authentication_endpoints.rb +30 -0
  29. data/lib/minty/api/v2.rb +8 -0
  30. data/lib/minty/client.rb +7 -0
  31. data/lib/minty/exception.rb +50 -0
  32. data/lib/minty/mixins/api_token_struct.rb +4 -0
  33. data/lib/minty/mixins/headers.rb +19 -0
  34. data/lib/minty/mixins/httpproxy.rb +125 -0
  35. data/lib/minty/mixins/initializer.rb +38 -0
  36. data/lib/minty/mixins/validation.rb +113 -0
  37. data/lib/minty/mixins.rb +23 -0
  38. data/lib/minty/version.rb +5 -0
  39. data/lib/minty.rb +11 -0
  40. data/lib/minty_client.rb +4 -0
  41. data/minty.gemspec +39 -0
  42. data/publish_rubygem.sh +10 -0
  43. data/spec/integration/lib/minty/api/api_authentication_spec.rb +122 -0
  44. data/spec/integration/lib/minty/minty_client_spec.rb +92 -0
  45. data/spec/lib/minty/client_spec.rb +223 -0
  46. data/spec/lib/minty/mixins/httpproxy_spec.rb +658 -0
  47. data/spec/lib/minty/mixins/initializer_spec.rb +121 -0
  48. data/spec/lib/minty/mixins/token_management_spec.rb +129 -0
  49. data/spec/lib/minty/mixins/validation_spec.rb +559 -0
  50. data/spec/spec_helper.rb +75 -0
  51. data/spec/support/credentials.rb +14 -0
  52. data/spec/support/dummy_class.rb +20 -0
  53. data/spec/support/dummy_class_for_proxy.rb +6 -0
  54. data/spec/support/dummy_class_for_restclient.rb +4 -0
  55. data/spec/support/dummy_class_for_tokens.rb +18 -0
  56. data/spec/support/import_users.json +13 -0
  57. data/spec/support/stub_response.rb +3 -0
  58. metadata +366 -0
@@ -0,0 +1,223 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Minty::Client do
6
+ shared_examples_for 'v2 API client' do
7
+ it { should be_a Minty::Api::V2 }
8
+ it { should be_a Minty::Api::V2::Blacklists }
9
+ it { should be_a Minty::Api::V2::Clients }
10
+ it { should be_a Minty::Api::V2::ClientGrants }
11
+ it { should be_a Minty::Api::V2::Connections }
12
+ it { should be_a Minty::Api::V2::DeviceCredentials }
13
+ it { should be_a Minty::Api::V2::Emails }
14
+ it { should be_a Minty::Api::V2::Jobs }
15
+ it { should be_a Minty::Api::V2::Logs }
16
+ it { should be_a Minty::Api::V2::ResourceServers }
17
+ it { should be_a Minty::Api::V2::Rules }
18
+ it { should be_a Minty::Api::V2::Stats }
19
+ it { should be_a Minty::Api::V2::Tenants }
20
+ it { should be_a Minty::Api::V2::Tickets }
21
+ it { should be_a Minty::Api::V2::UserBlocks }
22
+ it { should be_a Minty::Api::V2::Users }
23
+ it { should be_a Minty::Api::V2::UsersByEmail }
24
+ end
25
+
26
+ shared_examples_for 'Authentication API client' do
27
+ it { should be_a Minty::Api::AuthenticationEndpoints }
28
+ end
29
+
30
+ let(:domain) { 'samples.minty.page' }
31
+ let(:client_id) { '__test_client_id__' }
32
+ let(:client_secret) { '__test_client_secret__' }
33
+ let(:access_token) { '__test_access_token__' }
34
+ let(:organization) { '__test_organization__' }
35
+
36
+ describe 'V2 client with token' do
37
+ before :each do
38
+ expect_any_instance_of(Minty::Api::AuthenticationEndpoints)
39
+ .not_to receive(:obtain_access_token)
40
+ end
41
+
42
+ context 'and namespace' do
43
+ let(:subject) do
44
+ Minty::Client.new(
45
+ access_token: access_token,
46
+ namespace: domain
47
+ )
48
+ end
49
+ it_should_behave_like 'v2 API client'
50
+ it_should_behave_like 'Authentication API client'
51
+ end
52
+
53
+ context 'and domain' do
54
+ let(:subject) do
55
+ Minty::Client.new(
56
+ access_token: access_token,
57
+ domain: domain
58
+ )
59
+ end
60
+ it_should_behave_like 'v2 API client'
61
+ it_should_behave_like 'Authentication API client'
62
+ end
63
+
64
+ context 'and version' do
65
+ let(:subject) do
66
+ Minty::Client.new(
67
+ api_version: 2,
68
+ access_token: access_token,
69
+ domain: domain
70
+ )
71
+ end
72
+ it_should_behave_like 'v2 API client'
73
+ it_should_behave_like 'Authentication API client'
74
+ end
75
+
76
+ context 'with token' do
77
+ let(:subject) do
78
+ Minty::Client.new(
79
+ api_version: 2,
80
+ token: access_token,
81
+ domain: domain
82
+ )
83
+ end
84
+ it_should_behave_like 'v2 API client'
85
+ it_should_behave_like 'Authentication API client'
86
+ end
87
+
88
+ context 'with token and client_secret' do
89
+ let(:subject) do
90
+ Minty::Client.new(
91
+ token: access_token,
92
+ domain: domain,
93
+ client_secret: client_secret
94
+ )
95
+ end
96
+ it_should_behave_like 'v2 API client'
97
+ it_should_behave_like 'Authentication API client'
98
+ end
99
+ end
100
+
101
+ describe 'V2 client without token' do
102
+ context 'should try to get an API token' do
103
+ before do
104
+ stub_api_token
105
+ end
106
+
107
+ let(:subject) do
108
+ Minty::Client.new(
109
+ domain: domain,
110
+ client_id: client_id,
111
+ client_secret: client_secret
112
+ )
113
+ end
114
+ it_should_behave_like 'v2 API client'
115
+ it_should_behave_like 'Authentication API client'
116
+ end
117
+
118
+ context 'when try to get an API tokenwith api_identifier' do
119
+ let(:api_identifier) { 'https://samples.api_identifier/api/v2/' }
120
+
121
+ before do
122
+ stub_api_token_with_api_identifier
123
+ end
124
+
125
+ let(:subject) do
126
+ Minty::Client.new(
127
+ domain: domain,
128
+ client_id: client_id,
129
+ client_secret: client_secret,
130
+ api_identifier: api_identifier
131
+ )
132
+ end
133
+
134
+ it_should_behave_like 'v2 API client'
135
+ it_should_behave_like 'Authentication API client'
136
+ end
137
+
138
+ context 'when try to get an API token with organization' do
139
+ before do
140
+ stub_api_token_with_organization
141
+ end
142
+
143
+ let(:subject) do
144
+ Minty::Client.new(
145
+ domain: domain,
146
+ client_id: client_id,
147
+ client_secret: client_secret,
148
+ organization: organization
149
+ )
150
+ end
151
+
152
+ it_should_behave_like 'v2 API client'
153
+ it_should_behave_like 'Authentication API client'
154
+ end
155
+
156
+ context 'should fail if' do
157
+ it 'does not have a client_secret' do
158
+ expect do
159
+ Minty::Client.new(
160
+ domain: domain,
161
+ client_id: client_id
162
+ )
163
+ end.to raise_error('Must supply a valid API token')
164
+ end
165
+ end
166
+ end
167
+
168
+ def stub_api_token
169
+ stub_request(:post, "https://#{domain}/oauth/token")
170
+ .with(
171
+ body: hash_including(
172
+ {
173
+ grant_type: 'client_credentials',
174
+ client_id: client_id,
175
+ client_secret: client_secret,
176
+ audience: "https://#{domain}/api/v2/"
177
+ }
178
+ )
179
+ )
180
+ .to_return(
181
+ headers: { 'Content-Type' => 'application/json' },
182
+ body: '{"access_token":"__test_access_token__"}',
183
+ status: 200
184
+ )
185
+ end
186
+
187
+ def stub_api_token_with_api_identifier
188
+ stub_request(:post, "https://#{domain}/oauth/token")
189
+ .with(
190
+ body: hash_including(
191
+ {
192
+ grant_type: 'client_credentials',
193
+ client_id: client_id,
194
+ client_secret: client_secret,
195
+ audience: api_identifier
196
+ }
197
+ )
198
+ )
199
+ .to_return(
200
+ headers: { 'Content-Type' => 'application/json' },
201
+ body: '{"access_token":"__test_access_token__"}',
202
+ status: 200
203
+ )
204
+ end
205
+
206
+ def stub_api_token_with_organization
207
+ stub_request(:post, "https://#{domain}/oauth/token")
208
+ .with(
209
+ body: hash_including(
210
+ {
211
+ grant_type: 'client_credentials',
212
+ client_id: client_id,
213
+ client_secret: client_secret
214
+ }
215
+ )
216
+ )
217
+ .to_return(
218
+ headers: { 'Content-Type' => 'application/json' },
219
+ body: '{"access_token":"__test_access_token__"}',
220
+ status: 200
221
+ )
222
+ end
223
+ end