minty 1.0.0 → 1.1.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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -16
  3. data/Gemfile.lock +28 -208
  4. data/README.md +58 -57
  5. data/Rakefile +4 -27
  6. data/docs/DefaultApi.md +217 -0
  7. data/docs/RedirectUrl.md +18 -0
  8. data/git_push.sh +57 -0
  9. data/lib/minty/api/default_api.rb +210 -0
  10. data/lib/minty/api_client.rb +388 -0
  11. data/lib/minty/api_error.rb +53 -0
  12. data/lib/minty/configuration.rb +275 -0
  13. data/lib/minty/models/redirect_url.rb +216 -0
  14. data/lib/minty/version.rb +9 -3
  15. data/lib/minty.rb +33 -7
  16. data/minty.gemspec +19 -32
  17. data/pkg/minty-1.1.0.gem +0 -0
  18. data/publish_rubygem.sh +1 -1
  19. data/spec/api/default_api_spec.rb +65 -0
  20. data/spec/api_client_spec.rb +222 -0
  21. data/spec/configuration_spec.rb +38 -0
  22. data/spec/models/redirect_url_spec.rb +28 -0
  23. data/spec/spec_helper.rb +95 -63
  24. metadata +37 -292
  25. data/.bundle/config +0 -4
  26. data/.devcontainer/Dockerfile +0 -19
  27. data/.devcontainer/devcontainer.json +0 -37
  28. data/.env.example +0 -2
  29. data/.gemrelease +0 -2
  30. data/.github/PULL_REQUEST_TEMPLATE.md +0 -33
  31. data/.github/dependabot.yml +0 -10
  32. data/.github/stale.yml +0 -20
  33. data/.gitignore +0 -18
  34. data/.rspec +0 -3
  35. data/.rubocop.yml +0 -9
  36. data/CODE_OF_CONDUCT.md +0 -3
  37. data/DEPLOYMENT.md +0 -61
  38. data/DEVELOPMENT.md +0 -35
  39. data/EXAMPLES.md +0 -195
  40. data/Guardfile +0 -39
  41. data/LICENSE +0 -21
  42. data/Makefile +0 -5
  43. data/RUBYGEM.md +0 -9
  44. data/codecov.yml +0 -22
  45. data/lib/minty/algorithm.rb +0 -7
  46. data/lib/minty/api/authentication_endpoints.rb +0 -30
  47. data/lib/minty/api/v2.rb +0 -8
  48. data/lib/minty/client.rb +0 -7
  49. data/lib/minty/exception.rb +0 -50
  50. data/lib/minty/mixins/api_token_struct.rb +0 -4
  51. data/lib/minty/mixins/headers.rb +0 -19
  52. data/lib/minty/mixins/httpproxy.rb +0 -125
  53. data/lib/minty/mixins/initializer.rb +0 -38
  54. data/lib/minty/mixins/validation.rb +0 -113
  55. data/lib/minty/mixins.rb +0 -23
  56. data/lib/minty_client.rb +0 -4
  57. data/spec/integration/lib/minty/api/api_authentication_spec.rb +0 -122
  58. data/spec/integration/lib/minty/minty_client_spec.rb +0 -92
  59. data/spec/lib/minty/client_spec.rb +0 -223
  60. data/spec/lib/minty/mixins/httpproxy_spec.rb +0 -658
  61. data/spec/lib/minty/mixins/initializer_spec.rb +0 -121
  62. data/spec/lib/minty/mixins/token_management_spec.rb +0 -129
  63. data/spec/lib/minty/mixins/validation_spec.rb +0 -559
  64. data/spec/support/credentials.rb +0 -14
  65. data/spec/support/dummy_class.rb +0 -20
  66. data/spec/support/dummy_class_for_proxy.rb +0 -6
  67. data/spec/support/dummy_class_for_restclient.rb +0 -4
  68. data/spec/support/dummy_class_for_tokens.rb +0 -18
  69. data/spec/support/import_users.json +0 -13
  70. data/spec/support/stub_response.rb +0 -3
@@ -1,121 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'timecop'
5
-
6
- class MockClass
7
- attr_reader :token
8
-
9
- include Minty::Mixins::Initializer
10
- include Minty::Mixins::HTTPProxy
11
- include Minty::Mixins::Headers
12
- include Minty::Mixins::TokenManagement
13
- end
14
-
15
- describe Minty::Mixins::Initializer do
16
- let(:params) { { namespace: 'samples.minty.page' } }
17
- let(:instance) { DummyClassForProxy.send(:include, described_class).new(params) }
18
- let(:time_now) { Time.zone.now }
19
-
20
- context 'api v2' do
21
- it 'sets retry_count when passed' do
22
- params[:token] = '123'
23
- params[:retry_count] = 10
24
-
25
- expect(instance.instance_variable_get('@retry_count')).to eq(10)
26
- end
27
- end
28
-
29
- context 'token initialization' do
30
- before do
31
- params[:api_version] = 2
32
- Timecop.freeze(time_now)
33
- end
34
-
35
- after do
36
- Timecop.return
37
- end
38
-
39
- it 'sets token when access_token is passed' do
40
- params[:access_token] = '123'
41
-
42
- expect(instance.instance_variable_get('@token')).to eq('123')
43
- end
44
-
45
- it 'sets token when token is passed' do
46
- params[:token] = '123'
47
-
48
- expect(instance.instance_variable_get('@token')).to eq('123')
49
- end
50
-
51
- it 'fetches a token if none was given' do
52
- params[:client_id] = client_id = 'test_client_id'
53
- params[:client_secret] = client_secret = 'test_client_secret'
54
- params[:api_identifier] = api_identifier = 'test'
55
-
56
- payload = {
57
- grant_type: 'client_credentials',
58
- client_id: client_id,
59
- client_secret: client_secret,
60
- audience: api_identifier
61
- }
62
-
63
- expect(RestClient::Request).to receive(:execute).with(hash_including(
64
- method: :post,
65
- url: 'https://samples.minty.page/oauth/token',
66
- payload: payload.to_json
67
- ))
68
- .and_return(StubResponse.new({
69
- 'access_token' => 'test',
70
- 'expires_in' => 86_400
71
- },
72
- true,
73
- 200))
74
-
75
- expect(instance.instance_variable_get('@token')).to eq('test')
76
- expect(instance.instance_variable_get('@token_expires_at')).to eq(time_now.to_i + 86_400)
77
- end
78
-
79
- it "doesn't get a new token if one was supplied using 'token'" do
80
- params[:token] = 'access-token'
81
-
82
- expect(RestClient::Request).not_to receive(:execute).with(hash_including(
83
- method: :post,
84
- url: 'https://samples.minty.page/oauth/token'
85
- ))
86
-
87
- expect(instance.instance_variable_get('@token')).to eq('access-token')
88
- expect(instance.instance_variable_get('@token_expires_at')).to eq(Time.now.to_i + 3600)
89
- end
90
-
91
- it "doesn't get a new token if one was supplied using 'access_token'" do
92
- params[:access_token] = 'access-token'
93
-
94
- expect(RestClient::Request).not_to receive(:execute).with(hash_including(
95
- method: :post,
96
- url: 'https://samples.minty.page/oauth/token'
97
- ))
98
-
99
- expect(instance.instance_variable_get('@token')).to eq('access-token')
100
- expect(instance.instance_variable_get('@token_expires_at')).to eq(Time.now.to_i + 3600)
101
- end
102
-
103
- it 'can supply token_expires_at option' do
104
- params[:token] = 'access-token'
105
- params[:token_expires_at] = time_now.to_i + 300
106
-
107
- expect(RestClient::Request).not_to receive(:execute).with(hash_including(
108
- method: :post,
109
- url: 'https://samples.minty.page/oauth/token'
110
- ))
111
-
112
- expect(instance.instance_variable_get('@token')).to eq('access-token')
113
- expect(instance.instance_variable_get('@token_expires_at')).to eq(time_now.to_i + 300)
114
- end
115
-
116
- it 'throws if no token or credentials were given' do
117
- params[:client_id] = 'test-client-id'
118
- expect { instance }.to raise_error(Minty::InvalidCredentials)
119
- end
120
- end
121
- end
@@ -1,129 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'timecop'
5
-
6
- describe Minty::Mixins::TokenManagement do
7
- let(:client_id) { 'test-client-id' }
8
- let(:client_secret) { 'test-client-secret' }
9
- let(:api_identifier) { 'test-audience' }
10
- let(:domain) { 'samples.minty.page' }
11
-
12
- let(:payload) do
13
- {
14
- grant_type: 'client_credentials',
15
- client_id: client_id,
16
- client_secret: client_secret,
17
- audience: api_identifier
18
- }
19
- end
20
-
21
- let(:params) do
22
- {
23
- domain: domain,
24
- client_id: client_id,
25
- client_secret: client_secret,
26
- api_identifier: api_identifier
27
- }
28
- end
29
-
30
- let(:instance) { DummyClassForTokens.send(:include, described_class).new(params) }
31
- let(:time_now) { Time.zone.now }
32
-
33
- before :each do
34
- Timecop.freeze(time_now)
35
- end
36
-
37
- after :each do
38
- Timecop.return
39
- end
40
-
41
- context 'get_token' do
42
- it 'renews the token if there is no token set' do
43
- expect(RestClient::Request).to receive(:execute).with(hash_including(
44
- method: :post,
45
- url: 'https://samples.minty.page/oauth/token',
46
- payload: payload.to_json
47
- ))
48
- .and_return(StubResponse.new({
49
- 'access_token' => 'test',
50
- 'expires_in' => 86_400
51
- },
52
- true,
53
- 200))
54
-
55
- instance.send(:get_token)
56
-
57
- expect(instance.instance_variable_get('@token')).to eq('test')
58
- expect(instance.instance_variable_get('@token_expires_at')).to eq(time_now.to_i + 86_400)
59
- end
60
-
61
- it 'does not renew the token if the expiry time has not been reached' do
62
- params[:token] = 'test-token'
63
- params[:token_expires_at] = time_now.to_i + 86_400
64
-
65
- expect(RestClient::Request).not_to receive(:execute).with(hash_including(
66
- method: :post,
67
- url: 'https://samples.minty.page/oauth/token'
68
- ))
69
-
70
- instance.send(:get_token)
71
-
72
- expect(instance.instance_variable_get('@token')).to eq('test-token')
73
- expect(instance.instance_variable_get('@token_expires_at')).to eq(time_now.to_i + 86_400)
74
- end
75
-
76
- it 'renews the token if within 10 seconds of the expiry' do
77
- params[:token] = 'test-token'
78
- params[:token_expires_at] = time_now.to_i + 5
79
-
80
- expect(RestClient::Request).to receive(:execute).with(hash_including(
81
- method: :post,
82
- url: 'https://samples.minty.page/oauth/token',
83
- payload: payload.to_json
84
- ))
85
- .and_return(StubResponse.new({
86
- 'access_token' => 'renewed_token',
87
- 'expires_in' => 86_400
88
- },
89
- true,
90
- 200))
91
-
92
- instance.send(:get_token)
93
-
94
- expect(instance.instance_variable_get('@token')).to eq('renewed_token')
95
- expect(instance.instance_variable_get('@token_expires_at')).to eq(time_now.to_i + 86_400)
96
- end
97
-
98
- it 'renews the token if past the expiry' do
99
- params[:token] = 'test-token'
100
- params[:token_expires_at] = time_now.to_i - 10
101
-
102
- expect(RestClient::Request).to receive(:execute).with(hash_including(
103
- method: :post,
104
- url: 'https://samples.minty.page/oauth/token',
105
- payload: payload.to_json
106
- ))
107
- .and_return(StubResponse.new({
108
- 'access_token' => 'renewed_token',
109
- 'expires_in' => 86_400
110
- },
111
- true,
112
- 200))
113
-
114
- instance.send(:get_token)
115
-
116
- expect(instance.instance_variable_get('@token')).to eq('renewed_token')
117
- expect(instance.instance_variable_get('@token_expires_at')).to eq(time_now.to_i + 86_400)
118
- end
119
-
120
- it 'does not renew existing token if no token_expires_at' do
121
- params[:token] = 'test-token'
122
- instance.instance_variable_set '@token_expires_at', nil
123
-
124
- expect(RestClient::Request).not_to receive(:execute)
125
-
126
- instance.send(:get_token)
127
- end
128
- end
129
- end