fog-core 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +2 -0
- data/.github/dependabot.yml +2 -4
- data/.github/workflows/ci.yml +32 -0
- data/.rubocop.yml +1 -1
- data/README.md +2 -1
- data/SECURITY.md +6 -0
- data/changelog.md +12 -0
- data/fog-core.gemspec +1 -1
- data/lib/fog/compute.rb +1 -1
- data/lib/fog/core/mock.rb +1 -1
- data/lib/fog/core/provider.rb +1 -1
- data/lib/fog/core/service.rb +1 -1
- data/lib/fog/core/version.rb +1 -1
- data/lib/fog/core.rb +0 -1
- data/lib/fog/formatador.rb +3 -3
- data/lib/fog/storage.rb +0 -1
- data/lib/tasks/test_task.rb +2 -3
- metadata +5 -31
- data/.github/workflows/ruby.yml +0 -18
- data/.github/workflows/stale.yml +0 -9
- data/spec/compute/models/server_spec.rb +0 -229
- data/spec/compute_spec.rb +0 -95
- data/spec/connection_spec.rb +0 -107
- data/spec/core/cache_spec.rb +0 -227
- data/spec/core/collection_spec.rb +0 -24
- data/spec/core/model_spec.rb +0 -69
- data/spec/core/stringify_keys_spec.rb +0 -38
- data/spec/core/whitelist_keys_spec.rb +0 -36
- data/spec/credentials_spec.rb +0 -88
- data/spec/current_machine_spec.rb +0 -36
- data/spec/fake_app/fake_service.rb +0 -18
- data/spec/fake_app/models/collection.rb +0 -5
- data/spec/fake_app/models/model.rb +0 -2
- data/spec/fake_app/requests/request.rb +0 -11
- data/spec/fog_attribute_spec.rb +0 -569
- data/spec/formatador_spec.rb +0 -154
- data/spec/identity_spec.rb +0 -95
- data/spec/mocking_spec.rb +0 -84
- data/spec/service_spec.rb +0 -201
- data/spec/spec_helper.rb +0 -14
- data/spec/storage_spec.rb +0 -112
- data/spec/test_helpers/formats_helper_spec.rb +0 -121
- data/spec/test_helpers/schema_validator_spec.rb +0 -101
- data/spec/timeout_spec.rb +0 -20
- data/spec/utils_spec.rb +0 -29
- data/spec/uuid_spec.rb +0 -11
- data/spec/wait_for_spec.rb +0 -30
data/spec/connection_spec.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Fog::Core::Connection do
|
4
|
-
it "raises ArgumentError when no arguments given" do
|
5
|
-
assert_raises(ArgumentError) do
|
6
|
-
Fog::Core::Connection.new
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
[:request, :reset].each do |method|
|
11
|
-
it "responds to #{method}" do
|
12
|
-
connection = Fog::Core::Connection.new("http://example.com")
|
13
|
-
assert connection.respond_to?(method)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "adds custom user-agents to Fog requests" do
|
18
|
-
Fog::VERSION = "Version".freeze
|
19
|
-
Fog::Core::Connection.add_user_agent("my-app/1.2")
|
20
|
-
|
21
|
-
connection = Fog::Core::Connection.new("http://example.com")
|
22
|
-
assert_equal "my-app/1.2 fog/Version fog-core/#{Fog::Core::VERSION}",
|
23
|
-
connection.instance_variable_get(:@excon).data[:headers]["User-Agent"]
|
24
|
-
|
25
|
-
Fog.send(:remove_const, :VERSION)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "doesn't error when persistence is enabled" do
|
29
|
-
Fog::Core::Connection.new("http://example.com", true)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "doesn't error when persistence is enabled and debug_response is disabled" do
|
33
|
-
options = {
|
34
|
-
debug_response: false
|
35
|
-
}
|
36
|
-
Fog::Core::Connection.new("http://example.com", true, options)
|
37
|
-
end
|
38
|
-
|
39
|
-
describe ":path_prefix" do
|
40
|
-
it "does not emit a warning when provided this argument in the initializer" do
|
41
|
-
$stderr = StringIO.new
|
42
|
-
|
43
|
-
Fog::Core::Connection.new("http://example.com", false, path_prefix: "foo")
|
44
|
-
|
45
|
-
assert_empty($stderr.string)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "raises when the 'path' arg is present and this arg is supplied" do
|
49
|
-
assert_raises(ArgumentError) do
|
50
|
-
Fog::Core::Connection.new("http://example.com", false, path_prefix: "foo", path: "bar")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#request" do
|
56
|
-
describe "default behavior" do
|
57
|
-
it "supplies the 'path' arg directly to Excon" do
|
58
|
-
spy = Object.new
|
59
|
-
spy.instance_eval do
|
60
|
-
def params
|
61
|
-
@params
|
62
|
-
end
|
63
|
-
|
64
|
-
def new(_, params)
|
65
|
-
@params = params
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
Object.stub_const("Excon", spy) do
|
70
|
-
Fog::Core::Connection.new("http://example.com", false, path: "bar")
|
71
|
-
assert_equal("bar", spy.params[:path])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "with path_prefix supplied to the initializer" do
|
77
|
-
let(:spy) do
|
78
|
-
Object.new.tap do |spy|
|
79
|
-
spy.instance_eval do
|
80
|
-
def new(*_args); self; end
|
81
|
-
def params; @params; end
|
82
|
-
|
83
|
-
def request(params)
|
84
|
-
@params = params
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it "uses the initializer-supplied :path_prefix arg with #request :arg to formulate a path to send to Excon.request" do
|
91
|
-
Object.stub_const("Excon", spy) do
|
92
|
-
c = Fog::Core::Connection.new("http://example.com", false, path_prefix: "foo")
|
93
|
-
c.request(path: "bar")
|
94
|
-
assert_equal("foo/bar", spy.params[:path])
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
it "does not introduce consecutive '/'s into the path if 'path' starts with a '/'" do
|
99
|
-
Object.stub_const("Excon", spy) do
|
100
|
-
c = Fog::Core::Connection.new("http://example.com", false, path_prefix: "foo")
|
101
|
-
c.request(path: "/bar")
|
102
|
-
assert_equal("foo/bar", spy.params[:path])
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
data/spec/core/cache_spec.rb
DELETED
@@ -1,227 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "securerandom"
|
3
|
-
|
4
|
-
module Fog
|
5
|
-
class SubFogTestModel < Fog::Model
|
6
|
-
identity :id
|
7
|
-
|
8
|
-
attribute :config
|
9
|
-
attribute :subconfig
|
10
|
-
|
11
|
-
def initialize(new_attributes = {})
|
12
|
-
super
|
13
|
-
|
14
|
-
# This way we make YAML to use aliases
|
15
|
-
self.config = {
|
16
|
-
"users" => [
|
17
|
-
{ "user1" => "user1@email" },
|
18
|
-
{ "user2" => "user2@email" }
|
19
|
-
]
|
20
|
-
}
|
21
|
-
self.subconfig = config["users"][0]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
module Fog
|
27
|
-
class SubFogTestCollection < Fog::Collection
|
28
|
-
model Fog::SubFogTestModel
|
29
|
-
|
30
|
-
attribute :spec_attribute
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module Fog
|
35
|
-
class SubFogTestService < Fog::Service
|
36
|
-
|
37
|
-
class Mock
|
38
|
-
attr_reader :options
|
39
|
-
|
40
|
-
def initialize(opts = {})
|
41
|
-
@options = opts
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe Fog::Cache do
|
48
|
-
before(:each) do
|
49
|
-
Fog.mock!
|
50
|
-
@service = Fog::SubFogTestService.new
|
51
|
-
Fog::Cache.namespace_prefix = "test-dir"
|
52
|
-
end
|
53
|
-
|
54
|
-
it "has a namespace_prefix configurable" do
|
55
|
-
Fog::Cache.namespace_prefix = "for-service-user-region-foo"
|
56
|
-
|
57
|
-
# Expand path does not downcase. case insensitive platform tests.
|
58
|
-
example_cache = File.expand_path(Fog::Cache.namespace(Fog::SubFogTestModel, @service)).downcase
|
59
|
-
expected_namespace = File.expand_path("~/.fog-cache/for-service-user-region-foo").downcase
|
60
|
-
|
61
|
-
assert_equal example_cache.include?(expected_namespace), true
|
62
|
-
end
|
63
|
-
|
64
|
-
it "has metadata associated to the namespace that you can save to" do
|
65
|
-
Fog::Cache.clean!
|
66
|
-
Fog::Cache.namespace_prefix = "for-service-user-region-foo"
|
67
|
-
# nothing exists, nothing comes back
|
68
|
-
assert_equal Fog::Cache.metadata, {}
|
69
|
-
# write/read
|
70
|
-
Fog::Cache.write_metadata({last_dumped: "Tuesday, November 8, 2016"})
|
71
|
-
assert_equal Fog::Cache.metadata[:last_dumped], "Tuesday, November 8, 2016"
|
72
|
-
|
73
|
-
# diff namespace, diff metadata
|
74
|
-
Fog::Cache.namespace_prefix = "different-namespace"
|
75
|
-
assert_nil Fog::Cache.metadata[:last_dumped]
|
76
|
-
# still accessible per namespace
|
77
|
-
Fog::Cache.namespace_prefix = "for-service-user-region-foo"
|
78
|
-
assert_equal Fog::Cache.metadata[:last_dumped], "Tuesday, November 8, 2016"
|
79
|
-
# can overwrite
|
80
|
-
Fog::Cache.write_metadata({last_dumped: "Diff date"})
|
81
|
-
assert_equal Fog::Cache.metadata[:last_dumped], "Diff date"
|
82
|
-
|
83
|
-
# can't write a non-hash/data entry.
|
84
|
-
assert_raises Fog::Cache::CacheDir do
|
85
|
-
Fog::Cache.write_metadata("boo")
|
86
|
-
end
|
87
|
-
|
88
|
-
# namespace must be set as well.
|
89
|
-
assert_raises Fog::Cache::CacheDir do
|
90
|
-
Fog::Cache.namespace_prefix = nil
|
91
|
-
Fog::Cache.write_metadata({a: "b"})
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
it "can load cache data from disk" do
|
96
|
-
path = File.expand_path("~/.fog-cache-test-#{Time.now.to_i}.yml")
|
97
|
-
data = "--- ok\n...\n"
|
98
|
-
File.open(path, "w") { |f|
|
99
|
-
f.write(data)
|
100
|
-
}
|
101
|
-
|
102
|
-
assert_equal "ok", Fog::Cache.load_cache(path)
|
103
|
-
end
|
104
|
-
|
105
|
-
it "load bad cache data - empty file, from disk" do
|
106
|
-
path = File.expand_path("~/.fog-cache-test-2-#{Time.now.to_i}.yml")
|
107
|
-
data = ""
|
108
|
-
File.open(path, "w") { |f|
|
109
|
-
f.write(data)
|
110
|
-
}
|
111
|
-
|
112
|
-
assert !Fog::Cache.load_cache(path)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "must have a namespace_prefix configurable" do
|
116
|
-
Fog::Cache.namespace_prefix = nil
|
117
|
-
assert_raises Fog::Cache::CacheDir do
|
118
|
-
Fog::Cache.load(Fog::SubFogTestModel, @service)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
it "can create a namespace" do
|
123
|
-
Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
|
124
|
-
assert_equal File.exist?(Fog::Cache.namespace(Fog::SubFogTestModel, @service)), false
|
125
|
-
|
126
|
-
Fog::Cache.create_namespace(Fog::SubFogTestModel, @service)
|
127
|
-
assert_equal File.exist?(Fog::Cache.namespace(Fog::SubFogTestModel, @service)), true
|
128
|
-
end
|
129
|
-
|
130
|
-
it "will raise if no cache data found" do
|
131
|
-
Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
|
132
|
-
|
133
|
-
assert_raises Fog::Cache::CacheNotFound do
|
134
|
-
Fog::Cache.load(Fog::SubFogTestModel, @service)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
it "Fog cache ignores bad cache data - empty file, from disk" do
|
139
|
-
Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
|
140
|
-
id = SecureRandom.hex
|
141
|
-
a = Fog::SubFogTestModel.new(id: id, service: @service)
|
142
|
-
a.cache.dump
|
143
|
-
|
144
|
-
# input bad data
|
145
|
-
path_dir = File.expand_path(Fog::Cache.namespace(Fog::SubFogTestModel, @service))
|
146
|
-
path = File.join(path_dir, "foo.yml")
|
147
|
-
data = ""
|
148
|
-
File.open(path, "w") { |f|
|
149
|
-
f.write(data)
|
150
|
-
}
|
151
|
-
|
152
|
-
assert_equal 1, Fog::Cache.load(Fog::SubFogTestModel, @service).size
|
153
|
-
end
|
154
|
-
|
155
|
-
it "can be dumped and reloaded back in" do
|
156
|
-
|
157
|
-
Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
|
158
|
-
|
159
|
-
id = SecureRandom.hex
|
160
|
-
a = Fog::SubFogTestModel.new(id: id, service: @service)
|
161
|
-
|
162
|
-
assert_equal File.exist?(Fog::Cache.namespace(Fog::SubFogTestModel, @service)), false
|
163
|
-
a.cache.dump
|
164
|
-
assert_equal File.exist?(Fog::Cache.namespace(Fog::SubFogTestModel, @service)), true
|
165
|
-
|
166
|
-
instances = Fog::Cache.load(Fog::SubFogTestModel, @service)
|
167
|
-
|
168
|
-
assert_equal instances.first.id, a.id
|
169
|
-
assert_equal instances.first.class, a.class
|
170
|
-
end
|
171
|
-
|
172
|
-
it "dumping two models that have a duplicate identity" do
|
173
|
-
Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
|
174
|
-
|
175
|
-
id = SecureRandom.hex
|
176
|
-
|
177
|
-
# security groups on aws for eg can have the same identity group name 'default'.
|
178
|
-
# there are no restrictions on `identity` fog attributes to be uniq.
|
179
|
-
a = Fog::SubFogTestModel.new(id: id, service: @service, bar: "bar")
|
180
|
-
b = Fog::SubFogTestModel.new(id: id, service: @service, foo: "foo")
|
181
|
-
|
182
|
-
a.cache.dump
|
183
|
-
b.cache.dump
|
184
|
-
|
185
|
-
instances = Fog::Cache.load(Fog::SubFogTestModel, @service)
|
186
|
-
|
187
|
-
assert_equal instances.size, 2
|
188
|
-
end
|
189
|
-
|
190
|
-
it "dumping two models that have a duplicate identity twice" do
|
191
|
-
Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
|
192
|
-
|
193
|
-
id = SecureRandom.hex
|
194
|
-
|
195
|
-
# security groups on aws for eg can have the same identity group name 'default'.
|
196
|
-
# there are no restrictions on `identity` fog attributes to be uniq.
|
197
|
-
a = Fog::SubFogTestModel.new(id: id, service: @service, bar: "bar")
|
198
|
-
b = Fog::SubFogTestModel.new(id: id, service: @service, foo: "foo")
|
199
|
-
|
200
|
-
a.cache.dump
|
201
|
-
b.cache.dump
|
202
|
-
|
203
|
-
# and then again, w/out expiring cache
|
204
|
-
a.cache.dump
|
205
|
-
b.cache.dump
|
206
|
-
|
207
|
-
instances = Fog::Cache.load(Fog::SubFogTestModel, @service)
|
208
|
-
|
209
|
-
# unique-ify based on the attributes...
|
210
|
-
assert_equal instances.size, 2
|
211
|
-
end
|
212
|
-
|
213
|
-
it "dumps model with collection attributes and reloads them" do
|
214
|
-
Fog::Cache.expire_cache!(Fog::SubFogTestModel, @service)
|
215
|
-
|
216
|
-
c = Fog::SubFogTestCollection.new(service: @service, spec_attribute: 42)
|
217
|
-
|
218
|
-
id = SecureRandom.hex
|
219
|
-
a = Fog::SubFogTestModel.new(id: id, service: @service, collection: c)
|
220
|
-
|
221
|
-
a.cache.dump
|
222
|
-
|
223
|
-
instances = Fog::Cache.load(Fog::SubFogTestModel, @service)
|
224
|
-
assert_equal instances.first.id, id
|
225
|
-
assert_equal instances.first.collection.spec_attribute, 42
|
226
|
-
end
|
227
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "securerandom"
|
3
|
-
|
4
|
-
class FogTestModelForCollection < Fog::Model
|
5
|
-
identity :id
|
6
|
-
end
|
7
|
-
|
8
|
-
class FogTestCollection < Fog::Collection
|
9
|
-
model FogTestModelForCollection
|
10
|
-
|
11
|
-
def all
|
12
|
-
self
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe Fog::Collection do
|
17
|
-
describe "array delegation" do
|
18
|
-
it "delegates methods with keywords to Array" do
|
19
|
-
c = FogTestCollection.new
|
20
|
-
c << FogTestModelForCollection.new(id: SecureRandom.hex)
|
21
|
-
assert_equal c.sample(1, random: Random)[0], c[0]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/spec/core/model_spec.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "securerandom"
|
3
|
-
|
4
|
-
class FogTestModel < Fog::Model
|
5
|
-
identity :id
|
6
|
-
attribute :value
|
7
|
-
|
8
|
-
def create
|
9
|
-
self.identity = SecureRandom.hex
|
10
|
-
self
|
11
|
-
end
|
12
|
-
|
13
|
-
def update
|
14
|
-
self.value = 42
|
15
|
-
self
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe Fog::Model do
|
20
|
-
describe "#==" do
|
21
|
-
it "is not equal if one is not a Fog::Model" do
|
22
|
-
a = FogTestModel.new
|
23
|
-
b = 2
|
24
|
-
refute_equal a, b
|
25
|
-
refute_equal b, a
|
26
|
-
end
|
27
|
-
|
28
|
-
it "is equal if it is the same object" do
|
29
|
-
a = b = FogTestModel.new
|
30
|
-
assert_equal a, b
|
31
|
-
end
|
32
|
-
|
33
|
-
it "is equal if it has the same non-nil identity and the same class" do
|
34
|
-
id = SecureRandom.hex
|
35
|
-
assert_equal FogTestModel.new(id: id), FogTestModel.new(id: id)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "is not equal if both have nil identity, but are different objects" do
|
39
|
-
refute_equal FogTestModel.new, FogTestModel.new
|
40
|
-
end
|
41
|
-
|
42
|
-
it "is not equal if it has a different identity" do
|
43
|
-
refute_equal FogTestModel.new(id: SecureRandom.hex),
|
44
|
-
FogTestModel.new(id: SecureRandom.hex)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#save" do
|
49
|
-
describe "on a non persisted object" do
|
50
|
-
it "creates a new resource" do
|
51
|
-
a = FogTestModel.new
|
52
|
-
a.stub(:persisted?, false) do
|
53
|
-
a.save
|
54
|
-
refute_nil(a.identity)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "on a persisted object" do
|
60
|
-
it "updates resource" do
|
61
|
-
a = FogTestModel.new
|
62
|
-
a.stub(:persisted?, true) do
|
63
|
-
a.save
|
64
|
-
assert_equal(a.value, 42)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Fog::StringifyKeys" do
|
4
|
-
describe ".stringify" do
|
5
|
-
describe "when key is a Symbol" do
|
6
|
-
it "replaces key with String" do
|
7
|
-
input = { key: "value" }
|
8
|
-
output = Fog::StringifyKeys.stringify(input)
|
9
|
-
assert(output.key?("key"))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "when key is a String" do
|
14
|
-
it "keeps key as String" do
|
15
|
-
input = { "key" => "value" }
|
16
|
-
output = Fog::StringifyKeys.stringify(input)
|
17
|
-
assert(output.key?("key"))
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "when Hash is empty" do
|
22
|
-
it "returns empty Hash" do
|
23
|
-
assert_equal({}, Fog::StringifyKeys.stringify({}))
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "when keys are deeply nested" do
|
28
|
-
it "updates only top level key" do
|
29
|
-
input = { key1: { key2: { key3: nil }}}
|
30
|
-
|
31
|
-
output = Fog::StringifyKeys.stringify(input)
|
32
|
-
|
33
|
-
expected = { "key1" => { key2: { key3: nil }}}
|
34
|
-
assert_equal(expected, output)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Fog::WhitelistKeys" do
|
4
|
-
describe ".whitelist" do
|
5
|
-
describe "when other keys are present" do
|
6
|
-
it "returns Hash with only allowed keys" do
|
7
|
-
input = { name: "name", type: "type", size: 80 }
|
8
|
-
valid_keys = %w(name size)
|
9
|
-
|
10
|
-
output = Fog::WhitelistKeys.whitelist(input, valid_keys)
|
11
|
-
|
12
|
-
expected = { "name" => "name", "size" => 80 }
|
13
|
-
assert_equal(expected, output)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "when key is a Symbol" do
|
18
|
-
it "returns a String" do
|
19
|
-
input = { name: "name" }
|
20
|
-
valid_keys = %w(name)
|
21
|
-
|
22
|
-
output = Fog::WhitelistKeys.whitelist(input, valid_keys)
|
23
|
-
|
24
|
-
expected = { "name" => "name" }
|
25
|
-
assert(expected, output)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "when Hash is empty" do
|
30
|
-
it "returns empty Hash" do
|
31
|
-
output = Fog::WhitelistKeys.whitelist({}, [])
|
32
|
-
assert_equal({}, output)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/spec/credentials_spec.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "credentials" do
|
4
|
-
before do
|
5
|
-
@old_home = ENV["HOME"]
|
6
|
-
@old_rc = ENV["FOG_RC"]
|
7
|
-
@old_credential = ENV["FOG_CREDENTIAL"]
|
8
|
-
@old_credentials = Fog.credentials
|
9
|
-
Fog.instance_variable_set("@credential_path", nil) # kill memoization
|
10
|
-
Fog.instance_variable_set("@credential", nil) # kill memoization
|
11
|
-
end
|
12
|
-
|
13
|
-
after do
|
14
|
-
ENV["HOME"] = @old_home
|
15
|
-
ENV["FOG_RC"] = @old_rc
|
16
|
-
ENV["FOG_CREDENTIAL"] = @old_credential
|
17
|
-
Fog.credentials = @old_credentials
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "credential" do
|
21
|
-
it "returns :default for default credentials" do
|
22
|
-
assert_equal :default, Fog.credential
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns the to_sym of the assigned value" do
|
26
|
-
Fog.credential = "foo"
|
27
|
-
assert_equal :foo, Fog.credential
|
28
|
-
end
|
29
|
-
|
30
|
-
it "can set credentials throught the FOG_CREDENTIAL env va" do
|
31
|
-
ENV["FOG_CREDENTIAL"] = "bar"
|
32
|
-
assert_equal :bar, Fog.credential
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "credentials_path" do
|
37
|
-
it "has FOG_RC takes precedence over HOME" do
|
38
|
-
ENV["HOME"] = "/home/path"
|
39
|
-
ENV["FOG_RC"] = "/rc/path"
|
40
|
-
|
41
|
-
assert_equal "/rc/path", Fog.credentials_path
|
42
|
-
end
|
43
|
-
|
44
|
-
it "properly expands paths" do
|
45
|
-
ENV["FOG_RC"] = "/expanded/subdirectory/../path"
|
46
|
-
assert_equal "/expanded/path", Fog.credentials_path
|
47
|
-
end
|
48
|
-
|
49
|
-
it "falls back to home path if FOG_RC not set" do
|
50
|
-
ENV.delete("FOG_RC")
|
51
|
-
assert_equal File.join(ENV["HOME"], ".fog"), Fog.credentials_path
|
52
|
-
end
|
53
|
-
|
54
|
-
it "ignores home path if it does not exist" do
|
55
|
-
ENV.delete("FOG_RC")
|
56
|
-
ENV["HOME"] = "/no/such/path"
|
57
|
-
assert_nil Fog.credentials_path
|
58
|
-
end
|
59
|
-
|
60
|
-
it "File.expand_path raises because of non-absolute path" do
|
61
|
-
ENV.delete("FOG_RC")
|
62
|
-
ENV["HOME"] = "."
|
63
|
-
|
64
|
-
if RUBY_PLATFORM == "java"
|
65
|
-
Fog::Logger.warning("Stubbing out non-absolute path credentials test due to JRuby bug: https://github.com/jruby/jruby/issues/1163")
|
66
|
-
else
|
67
|
-
assert_nil Fog.credentials_path
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
it "returns nil when neither FOG_RC or HOME are set" do
|
72
|
-
ENV.delete("HOME")
|
73
|
-
ENV.delete("FOG_RC")
|
74
|
-
assert_nil Fog.credentials_path
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "symbolize_credential?" do
|
79
|
-
it "returns false if the value is :headers" do
|
80
|
-
refute Fog.symbolize_credential?(:headers)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "returns true if the value is not :headers" do
|
84
|
-
assert Fog.symbolize_credential?(:foo)
|
85
|
-
assert Fog.symbolize_credential?(:liberate_me_ex_inheris)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Fog::CurrentMachine do
|
4
|
-
before do
|
5
|
-
@was_mocking = Fog.mock?
|
6
|
-
Fog.mock!
|
7
|
-
|
8
|
-
@old_excon_defaults_mock = Excon.defaults[:mock]
|
9
|
-
Excon.defaults[:mock] = true
|
10
|
-
end
|
11
|
-
|
12
|
-
after do
|
13
|
-
Fog.unmock! unless @was_mocking
|
14
|
-
|
15
|
-
Fog::CurrentMachine.ip_address = nil
|
16
|
-
Excon.stubs.clear
|
17
|
-
Excon.defaults[:mock] = @old_excon_defaults_mock
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "ip_address" do
|
21
|
-
it "should be thread safe" do
|
22
|
-
|
23
|
-
(1..10).map do
|
24
|
-
Thread.new do
|
25
|
-
Excon.stub({ method: :get, path: "/" }, { body: "" })
|
26
|
-
Fog::CurrentMachine.ip_address
|
27
|
-
end
|
28
|
-
end.each(&:join)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should remove trailing endline characters" do
|
32
|
-
Excon.stub({ method: :get, path: "/" }, { body: "192.168.0.1\n" })
|
33
|
-
assert_equal "192.168.0.1", Fog::CurrentMachine.ip_address
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class FakeService < Fog::Service
|
2
|
-
class Real
|
3
|
-
def initialize(_options)
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
class Mock
|
8
|
-
def initialize(_options)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
model_path File.join(File.dirname(__FILE__), "models")
|
13
|
-
model :model
|
14
|
-
collection :collection
|
15
|
-
|
16
|
-
request_path File.join(File.dirname(__FILE__), "requests")
|
17
|
-
request :request
|
18
|
-
end
|