fog-core 2.4.0 → 2.5.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +2 -0
  3. data/.github/dependabot.yml +2 -4
  4. data/.github/workflows/ci.yml +32 -0
  5. data/.rubocop.yml +1 -1
  6. data/README.md +2 -1
  7. data/SECURITY.md +6 -0
  8. data/changelog.md +12 -0
  9. data/fog-core.gemspec +1 -1
  10. data/lib/fog/compute.rb +1 -1
  11. data/lib/fog/core/mock.rb +1 -1
  12. data/lib/fog/core/provider.rb +1 -1
  13. data/lib/fog/core/service.rb +1 -1
  14. data/lib/fog/core/version.rb +1 -1
  15. data/lib/fog/core.rb +0 -1
  16. data/lib/fog/formatador.rb +3 -3
  17. data/lib/fog/storage.rb +0 -1
  18. data/lib/tasks/test_task.rb +2 -3
  19. metadata +5 -31
  20. data/.github/workflows/ruby.yml +0 -18
  21. data/.github/workflows/stale.yml +0 -9
  22. data/spec/compute/models/server_spec.rb +0 -229
  23. data/spec/compute_spec.rb +0 -95
  24. data/spec/connection_spec.rb +0 -107
  25. data/spec/core/cache_spec.rb +0 -227
  26. data/spec/core/collection_spec.rb +0 -24
  27. data/spec/core/model_spec.rb +0 -69
  28. data/spec/core/stringify_keys_spec.rb +0 -38
  29. data/spec/core/whitelist_keys_spec.rb +0 -36
  30. data/spec/credentials_spec.rb +0 -88
  31. data/spec/current_machine_spec.rb +0 -36
  32. data/spec/fake_app/fake_service.rb +0 -18
  33. data/spec/fake_app/models/collection.rb +0 -5
  34. data/spec/fake_app/models/model.rb +0 -2
  35. data/spec/fake_app/requests/request.rb +0 -11
  36. data/spec/fog_attribute_spec.rb +0 -569
  37. data/spec/formatador_spec.rb +0 -154
  38. data/spec/identity_spec.rb +0 -95
  39. data/spec/mocking_spec.rb +0 -84
  40. data/spec/service_spec.rb +0 -201
  41. data/spec/spec_helper.rb +0 -14
  42. data/spec/storage_spec.rb +0 -112
  43. data/spec/test_helpers/formats_helper_spec.rb +0 -121
  44. data/spec/test_helpers/schema_validator_spec.rb +0 -101
  45. data/spec/timeout_spec.rb +0 -20
  46. data/spec/utils_spec.rb +0 -29
  47. data/spec/uuid_spec.rb +0 -11
  48. data/spec/wait_for_spec.rb +0 -30
@@ -1,154 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Fog::Formatador do
4
- describe "when object is Fog::Collection instance" do
5
- before do
6
- @member_class = Class.new(Fog::Model) do
7
- attribute :name
8
-
9
- def self.name
10
- "MemberGadget"
11
- end
12
- end
13
-
14
- @collection_class = Class.new(Fog::Collection) do
15
- model @member_class
16
-
17
- attribute :attr_one
18
- attribute :attr_two
19
-
20
- def self.name
21
- "InspectionGadget"
22
- end
23
-
24
- def all
25
- self
26
- end
27
- end
28
-
29
- @collection = @collection_class.new(attr_one: "String", attr_two: 5)
30
- @collection << @member_class.new(name: "Member name")
31
- @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
32
- <InspectionGadget
33
- attr_one="String",
34
- attr_two=5
35
- [
36
- <MemberGadget
37
- name="Member name"
38
- >
39
- ]
40
- >
41
- EOS
42
- end
43
-
44
- it "returns formatted representation" do
45
- Fog::Formatador.format(@collection).must_equal @expected
46
- end
47
- end
48
-
49
- describe "when object is Fog::Collection without attributes" do
50
- before do
51
- @collection_class = Class.new(Fog::Collection) do
52
- def all
53
- self
54
- end
55
- end
56
-
57
- @collection = @collection_class.new
58
- @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
59
- <
60
- [
61
-
62
- ]
63
- >
64
- EOS
65
- end
66
-
67
- it "returns formatted representation" do
68
- Fog::Formatador.format(@collection).must_equal @expected
69
- end
70
- end
71
-
72
- describe "when object has is Fog::Collection but ignoring nested objects" do
73
- before do
74
- @collection_class = Class.new(Fog::Collection) do
75
- attribute :name
76
-
77
- def all
78
- self
79
- end
80
- end
81
- @collection = @collection_class.new(name: "Name")
82
- @collection << "this"
83
- end
84
-
85
- it "returns formatted representation" do
86
- @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
87
- <
88
- name="Name"
89
- >
90
- EOS
91
-
92
- opts = { include_nested: false }
93
- Fog::Formatador.format(@collection, opts).must_equal @expected
94
- end
95
- end
96
-
97
- describe "when object is not enumerable" do
98
- before do
99
- @class = Class.new
100
- @subject = @class.new
101
- @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
102
- <
103
- >
104
- EOS
105
- end
106
-
107
- it "returns formatted representation" do
108
- Fog::Formatador.format(@subject).must_equal @expected
109
- end
110
- end
111
-
112
- describe "when object responds to non-enumerable '#map'" do
113
- before do
114
- @member = Class.new(Fog::Model) do
115
- def self.name
116
- "IPAddress"
117
- end
118
-
119
- # This map action is unrelated to Enumerable (See GH-138)
120
- def map
121
- raise "Do not call me when inspecting!"
122
- end
123
- end
124
-
125
- @collection_class = Class.new(Fog::Collection) do
126
- model @member
127
-
128
- def self.name
129
- "IPAddressCollection"
130
- end
131
-
132
- def all
133
- self
134
- end
135
- end
136
-
137
- @collection = @collection_class.new
138
- @collection << @member.new
139
-
140
- @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
141
- <IPAddressCollection
142
- [
143
- <IPAddress
144
- >
145
- ]
146
- >
147
- EOS
148
- end
149
-
150
- it "returns formatted representation" do
151
- Fog::Formatador.format(@collection).must_equal @expected
152
- end
153
- end
154
- end
@@ -1,95 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Fog
4
- module Identity
5
- def self.require(*_args); end
6
- end
7
- end
8
-
9
- describe "Fog::Identity" do
10
- describe "#new" do
11
- module Fog
12
- module TheRightWay
13
- class Identity
14
- def initialize(_args); end
15
- end
16
- end
17
- end
18
-
19
- module Fog
20
- module TheRightWay
21
- extend Provider
22
- service(:identity, "Identity")
23
- end
24
- end
25
-
26
- it "instantiates an instance of Fog::Identity::<Provider> from the :provider keyword arg" do
27
- identity = Fog::Identity.new(provider: :therightway)
28
- assert_instance_of(Fog::TheRightWay::Identity, identity)
29
- end
30
-
31
- module Fog
32
- module Identity
33
- class TheWrongWay
34
- def initialize(_args); end
35
- end
36
- end
37
- end
38
-
39
- module Fog
40
- module TheWrongWay
41
- extend Provider
42
- service(:identity, "Identity")
43
- end
44
- end
45
-
46
- it "instantiates an instance of Fog::<Provider>::Identity from the :provider keyword arg" do
47
- identity = Fog::Identity.new(provider: :thewrongway)
48
- assert_instance_of(Fog::Identity::TheWrongWay, identity)
49
- end
50
-
51
- module Fog
52
- module BothWays
53
- class Identity
54
- attr_reader :args
55
- def initialize(args)
56
- @args = args
57
- end
58
- end
59
- end
60
- end
61
-
62
- module Fog
63
- module Identity
64
- class BothWays
65
- def initialize(_args); end
66
- end
67
- end
68
- end
69
-
70
- module Fog
71
- module BothWays
72
- extend Provider
73
- service(:identity, "Identity")
74
- end
75
- end
76
-
77
- describe "when both Fog::Identity::<Provider> and Fog::<Provider>::Identity exist" do
78
- it "prefers Fog::Identity::<Provider>" do
79
- identity = Fog::Identity.new(provider: :bothways)
80
- assert_instance_of(Fog::BothWays::Identity, identity)
81
- end
82
- end
83
-
84
- it "passes the supplied keyword args less :provider to Fog::Identity::<Provider>#new" do
85
- identity = Fog::Identity.new(provider: :bothways, extra: :stuff)
86
- assert_equal({ extra: :stuff }, identity.args)
87
- end
88
-
89
- it "raises ArgumentError when given a :provider where a Fog::Identity::Provider that does not exist" do
90
- assert_raises(ArgumentError) do
91
- Fog::Identity.new(provider: :wat)
92
- end
93
- end
94
- end
95
- end
data/spec/mocking_spec.rb DELETED
@@ -1,84 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Fog mocking" do
4
- before do
5
- @fog_was_mocked = Fog.mock?
6
- Fog.unmock! if @fog_was_mocked
7
- end
8
-
9
- after do
10
- Fog.mock! if @fog_was_mocked
11
- end
12
-
13
- describe "Fog.mock!" do
14
- it "Fog.mock! returns true" do
15
- assert_equal true, Fog.mock!
16
- end
17
-
18
- it "Fog.mock? without Fog.mock! returns false" do
19
- assert_equal false, Fog.mock?
20
- end
21
-
22
- it "Fog.mock? with Fog.mock!" do
23
- Fog.mock!
24
- assert_equal true, Fog.mock?
25
- end
26
-
27
- it "Fog.mocking? without Fog.mock!" do
28
- assert_equal false, Fog.mocking?
29
- end
30
-
31
- it "Fog.mocking? with Fog.mock!" do
32
- Fog.mock!
33
- assert_equal true, Fog.mocking?
34
- end
35
- end
36
-
37
- describe "Fog::Mock.delay" do
38
- it "Fog::Mock.delay defaults to 0" do
39
- assert_equal 1, Fog::Mock.delay
40
- end
41
-
42
- it "handles reassignment" do
43
- Fog::Mock.delay = 2
44
- assert_equal 2, Fog::Mock.delay
45
-
46
- Fog::Mock.delay = 1
47
- assert_equal 1, Fog::Mock.delay
48
- end
49
-
50
- it "raises when given an illegal delay" do
51
- assert_raises(ArgumentError) do
52
- Fog::Mock.delay = -1
53
- end
54
- end
55
- end
56
-
57
- describe "Fog::Mock.random_ip" do
58
- it "defaults to ipv4" do
59
- assert IPAddr.new(Fog::Mock.random_ip).ipv4?
60
- end
61
-
62
- it "supports explicit request for v4" do
63
- assert IPAddr.new(Fog::Mock.random_ip(version: :v4)).ipv4?
64
- end
65
-
66
- it "supports explicit request for v6" do
67
- assert IPAddr.new(Fog::Mock.random_ip(version: :v6)).ipv6?
68
- end
69
-
70
- it "raises when supplied an illegal IP version" do
71
- assert_raises(ArgumentError) do
72
- IPAddr.new(Fog::Mock.random_ip(version: :v5)).ipv4?
73
- end
74
- end
75
- end
76
-
77
- describe "Fog::Mock.not_implemented" do
78
- it "raises MockNotImplemented when called" do
79
- assert_raises(Fog::Errors::MockNotImplemented) do
80
- Fog::Mock.not_implemented
81
- end
82
- end
83
- end
84
- end
data/spec/service_spec.rb DELETED
@@ -1,201 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Fog::Service do
4
- class TestService < Fog::Service
5
- requires :generic_api_key
6
- recognizes :generic_user
7
-
8
- class Real
9
- attr_reader :options
10
-
11
- def initialize(opts = {})
12
- @options = opts
13
- end
14
- end
15
-
16
- class Mock
17
- attr_reader :options
18
-
19
- def initialize(opts = {})
20
- @options = opts
21
- end
22
- end
23
- end
24
-
25
- class ChildOfTestService < TestService
26
- class Real; def initialize(*_args); end; end
27
- class Mock; def initialize(*_args); end; end
28
- end
29
-
30
- it "properly passes headers" do
31
- user_agent_hash = {
32
- "User-Agent" => "Generic Fog Client"
33
- }
34
- params = {
35
- generic_user: "bob",
36
- generic_api_key: "1234",
37
- connection_options: {
38
- headers: user_agent_hash
39
- }
40
- }
41
- service = TestService.new(params)
42
-
43
- assert_equal user_agent_hash, service.options[:connection_options][:headers]
44
- end
45
-
46
- describe "when created with a Hash" do
47
- it "raises for required argument that are missing" do
48
- assert_raises(ArgumentError) { TestService.new({}) }
49
- end
50
-
51
- it "converts String keys to be Symbols" do
52
- service = TestService.new "generic_api_key" => "abc"
53
- assert_includes service.options.keys, :generic_api_key
54
- end
55
-
56
- it "removes keys with `nil` values" do
57
- service = TestService.new generic_api_key: "abc", generic_user: nil
58
- refute_includes service.options.keys, :generic_user
59
- end
60
-
61
- it "converts number String values with to_i" do
62
- service = TestService.new generic_api_key: "3421"
63
- assert_equal 3421, service.options[:generic_api_key]
64
- end
65
-
66
- it "converts 'true' String values to TrueClass" do
67
- service = TestService.new generic_api_key: "true"
68
- assert_equal true, service.options[:generic_api_key]
69
- end
70
-
71
- it "converts 'false' String values to FalseClass" do
72
- service = TestService.new generic_api_key: "false"
73
- assert_equal false, service.options[:generic_api_key]
74
- end
75
-
76
- it "warns for unrecognised options" do
77
- bad_options = { generic_api_key: "abc", bad_option: "bad value" }
78
- logger = Minitest::Mock.new
79
- logger.expect :warning, nil, ["Unrecognized arguments: bad_option"]
80
- Fog.stub_const :Logger, logger do
81
- TestService.new(bad_options)
82
- end
83
- logger.verify
84
- end
85
- end
86
-
87
- describe "when creating and mocking is disabled" do
88
- it "returns the real service" do
89
- Fog.stub :mocking?, false do
90
- service = TestService.new(generic_api_key: "abc")
91
- service.must_be_instance_of TestService::Real
92
- end
93
- end
94
-
95
- it "TestService::Real has TestService::Collections mixed into the mocked service" do
96
- Fog.stub :mocking?, false do
97
- service = TestService.new(generic_api_key: "abc")
98
- assert_includes(service.class.ancestors, TestService::Collections)
99
- assert_includes(service.class.ancestors, Fog::Service::Collections)
100
- refute_includes(service.class.ancestors, ChildOfTestService::Collections)
101
- end
102
- end
103
-
104
- it "ChildOfTestService::Real has ChildOfTestService::Collections and TestService::Collections mixed in" do
105
- Fog.stub :mocking?, true do
106
- service = ChildOfTestService.new
107
- assert_includes(service.class.ancestors, Fog::Service::Collections)
108
- assert_includes(service.class.ancestors, TestService::Collections)
109
- assert_includes(service.class.ancestors, ChildOfTestService::Collections)
110
- end
111
- end
112
- end
113
-
114
- describe "when creating and mocking is enabled" do
115
- it "returns mocked service" do
116
- Fog.stub :mocking?, true do
117
- service = TestService.new(generic_api_key: "abc")
118
- service.must_be_instance_of TestService::Mock
119
- end
120
- end
121
-
122
- it "TestService::Mock has TestService::Collections mixed into the mocked service" do
123
- Fog.stub :mocking?, true do
124
- service = TestService.new(generic_api_key: "abc")
125
- assert_includes(service.class.ancestors, Fog::Service::Collections)
126
- assert_includes(service.class.ancestors, TestService::Collections)
127
- refute_includes(service.class.ancestors, ChildOfTestService::Collections)
128
- end
129
- end
130
-
131
- it "ChildOfTestService::Mock has ChildOfTestService::Collections and TestService::Collections mixed in" do
132
- Fog.stub :mocking?, true do
133
- service = ChildOfTestService.new
134
- assert_includes(service.class.ancestors, Fog::Service::Collections)
135
- assert_includes(service.class.ancestors, TestService::Collections)
136
- assert_includes(service.class.ancestors, ChildOfTestService::Collections)
137
- end
138
- end
139
- end
140
-
141
- describe "when no credentials are provided" do
142
- it "uses the global values" do
143
- @global_credentials = {
144
- generic_user: "fog",
145
- generic_api_key: "fog"
146
- }
147
-
148
- Fog.stub :credentials, @global_credentials do
149
- @service = TestService.new
150
- assert_equal @service.options, @global_credentials
151
- end
152
- end
153
- end
154
-
155
- describe "when credentials are provided as settings" do
156
- it "merges the global values into settings" do
157
- @settings = {
158
- generic_user: "fog"
159
- }
160
- @global_credentials = {
161
- generic_user: "bob",
162
- generic_api_key: "fog"
163
- }
164
-
165
- Fog.stub :credentials, @global_credentials do
166
- @service = TestService.new(@settings)
167
- assert_equal @service.options[:generic_user], "fog"
168
- assert_equal @service.options[:generic_api_key], "fog"
169
- end
170
- end
171
- end
172
-
173
- describe "when config object can configure the service itself" do
174
- it "ignores the global and its values" do
175
- @config = Minitest::Mock.new
176
- def @config.config_service?; true; end
177
- def @config.nil?; false; end
178
- def @config.==(other); object_id == other.object_id; end
179
-
180
- unexpected_usage = lambda { raise "Accessing global!" }
181
- Fog.stub :credentials, unexpected_usage do
182
- @service = TestService.new(@config)
183
- assert_equal @config, @service.options
184
- end
185
- end
186
- end
187
-
188
- describe "#setup_requirements" do
189
- before :each do
190
- @service = FakeService.new
191
- end
192
-
193
- it "should require collections" do
194
- assert @service.respond_to?(:collection)
195
- end
196
-
197
- it "should mock" do
198
- assert_includes @service.mocked_requests, :request
199
- end
200
- end
201
- end
data/spec/spec_helper.rb DELETED
@@ -1,14 +0,0 @@
1
- # Set home outside of real user
2
- require "tmpdir"
3
- ENV["HOME"] = Dir.mktmpdir("foghome")
4
-
5
- require "minitest/autorun"
6
- require "minitest/spec"
7
- require "minitest/stub_const"
8
-
9
- $LOAD_PATH.unshift "lib"
10
- require "fog/core"
11
-
12
- Dir["spec/fake_app/**/*.rb"].each do |file|
13
- require File.join(File.dirname(__FILE__), "..", file)
14
- end
data/spec/storage_spec.rb DELETED
@@ -1,112 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Fog
4
- module Storage
5
- def self.require(*_args); end
6
- end
7
- end
8
-
9
- describe "Fog::Storage" do
10
- describe "#new" do
11
- module Fog
12
- module TheRightWay
13
- class Storage
14
- def initialize(_args); end
15
- end
16
- end
17
- end
18
-
19
- module Fog
20
- module TheRightWay
21
- extend Provider
22
- service(:storage, "Storage")
23
- end
24
- end
25
-
26
- it "instantiates an instance of Fog::<Provider>::Storage from the :provider keyword arg" do
27
- compute = Fog::Storage.new(provider: :therightway)
28
- assert_instance_of(Fog::TheRightWay::Storage, compute)
29
- end
30
-
31
- module Fog
32
- module Storage
33
- class TheWrongWay
34
- def initialize(_args); end
35
- end
36
- end
37
-
38
- module TheWrongWay
39
- extend Provider
40
- service(:storage, "Storage")
41
- end
42
- end
43
-
44
- it "instantiates an instance of Fog::Storage::<Provider> from the :provider keyword arg" do
45
- compute = Fog::Storage.new(provider: :thewrongway)
46
- assert_instance_of(Fog::Storage::TheWrongWay, compute)
47
- end
48
-
49
- module Fog
50
- module BothWays
51
- class Storage
52
- attr_reader :args
53
-
54
- def initialize(args)
55
- @args = args
56
- end
57
- end
58
- end
59
- end
60
-
61
- module Fog
62
- module Storage
63
- class BothWays
64
- def initialize(_args); end
65
- end
66
- end
67
- end
68
-
69
- module Fog
70
- module BothWays
71
- extend Provider
72
- service(:storage, "Storage")
73
- end
74
- end
75
-
76
- describe "when both Fog::Storage::<Provider> and Fog::<Provider>::Storage exist" do
77
- it "prefers Fog::Storage::<Provider>" do
78
- compute = Fog::Storage.new(provider: :bothways)
79
- assert_instance_of(Fog::BothWays::Storage, compute)
80
- end
81
- end
82
-
83
- it "passes the supplied keyword args less :provider to Fog::Storage::<Provider>#new" do
84
- compute = Fog::Storage.new(provider: :bothways, extra: :stuff)
85
- assert_equal({ extra: :stuff }, compute.args)
86
- end
87
-
88
- it "raises ArgumentError when given a :provider where a Fog::Storage::Provider that does not exist" do
89
- assert_raises(ArgumentError) do
90
- Fog::Storage.new(provider: :wat)
91
- end
92
- end
93
- end
94
-
95
- describe ".get_body_size" do
96
- it "doesn't alter the encoding of the string passed to it" do
97
- body = "foo".encode("UTF-8")
98
- Fog::Storage.get_body_size(body)
99
-
100
- assert_equal("UTF-8", body.encoding.to_s)
101
- end
102
-
103
- it "respects frozen strings" do
104
- if RUBY_VERSION >= "2.3.0"
105
- body = "foo".freeze
106
- Fog::Storage.get_body_size(body)
107
- else
108
- skip
109
- end
110
- end
111
- end
112
- end