test/fastly/client_test.rb in fastly-2.5.3 vs test/fastly/client_test.rb in fastly-3.0.0
- old
+ new
@@ -18,51 +18,38 @@
assert_equal api_key, client.api_key
assert_equal nil, client.user
assert_equal nil, client.password
end
+ it 'raises Unauthorized if api_key is not passed in the options' do
+ assert_raises(Fastly::Unauthorized) { Fastly::Client.new(user: user, password: password)}
+ end
+
it 'raises Unauthorized if user/pass provided but are invalid' do
stub_request(:any, /api.fastly.com/).to_return(status: 400)
e = assert_raises(Fastly::Unauthorized) {
- Fastly::Client.new(user: user, password: pass)
+ Fastly::Client.new(user: user, password: password)
}
- assert_equal "Invalid auth credentials. Check username/password.", e.message
+ assert_equal "Invalid auth credentials. Check api_key.", e.message
end
- it 'surfaces a deprecation message when a username or password is provided' do
- stub_request(:any, /api.fastly.com/).
- to_return(body: JSON.generate(i: "dont care"), status: 200)
-
- assert_output('', /DEPRECATION WARNING:/) { Fastly::Client.new(user: user, password: pass) }
- end
-
it 'initializes an http client' do
client = Fastly::Client.new(api_key: api_key)
assert_equal Net::HTTP, client.http.class
assert_equal 443, client.http.port
assert_equal 'api.fastly.com', client.http.address
assert client.http.use_ssl?
end
- it 'sets a cookie when auth with valid user/pass' do
- stub_request(:any, /api.fastly.com/).
- to_return(body: JSON.generate(i: "dont care"), status: 200, headers: { 'Set-Cookie' => 'tasty!' })
-
- client = Fastly::Client.new(user: user, password: pass)
- assert_equal "tasty!", client.cookie
- end
-
it 'raises an Error if username is used in place of user as an option' do
stub_request(:any, /api.fastly.com/).
- to_return(body: JSON.generate(i: "dont care"), status: 200, headers: { 'Set-Cookie' => 'tasty!' })
+ to_return(body: JSON.generate(i: "dont care"), status: 200)
- assert_raises(ArgumentError) { Fastly.new(username: user, password: pass) }
+ assert_raises(ArgumentError) { Fastly.new(username: user, password: password) }
- Fastly.new(user: user, password: pass)
- Fastly.new(api_key: api_key)
- Fastly.new(api_key: api_key, user: user, password: pass)
+ Fastly.new(api_key: api_key, user: user, password: password)
end
end
describe 'get' do
let(:client) { Fastly::Client.new(api_key: api_key) }